$(function(){
	// Checks the URL and sets the appropriate nav element to selected
	// If the url is blank ie the homepage then highlight the dashboard
	// menu option.
	var path = location.pathname.substring(1);
	if ( path ) {
		var str = path.split('/');
		$.each(str, function(index, value) {
			switch (value) {
				case 'home':
					$('#nav-dashboard').addClass('nav-selected');
					break;
				case 'member':
					$('#nav-members').addClass('nav-selected');
					break;
				case 'employer':
					$('#nav-employers').addClass('nav-selected');
					break;
			}
		});
	} else {
		$('#nav-dashboard').addClass('nav-selected');
	}
	
	// When an input field is focused changed the border to darker.
	var $input = $('input');
	$input.focus(function(){
		$(this).addClass('input_focus');
	});
	$input.blur(function(){
		$(this).removeClass('input_focus');
	});
		
	// Set rollover styles of buttons
	$('a[class=button]').hover(
		function () {
			$(this).addClass('button_hover');
		},
		function () {
			$(this).removeClass('button_hover');
		}
	);
	// Set up tabs
	$("#tabs").tabs();
 });

//Standard function to set user notifications in the message_block
// 0 = Error, 1 = Success, second var is text string to output.
function set_message_block (x, msg) {
	var $message_block = $('#message_block');
	
	switch (x) {
		case 1:
			$message_block.removeClass('message_block_deny').addClass('message_block_confirm').slideDown().html(msg).effect("pulsate", { times:1 }, 400);
			break;
		case 0:
			$message_block.removeClass('message_block_confirm').addClass('message_block_deny').slideDown().html(msg).effect("pulsate", { times:1 }, 400);
			break;
		case 2:
			$message_block.removeClass('message_block_confirm').removeClass('message_block_deny').slideDown().html(msg).effect("pulsate", { times:1 }, 400);
	}
}

function elipse (text, text_length) {
	if (text.length < text_length) {
		return text;
	} else {
		return text.substr(0, text_length) + '...';
	}
}

// Jquery Placeholder Plugin
jQuery.fn.textPlaceholder = function () {

	return this.each(function(){

		var that = this;

		if (that.placeholder && 'placeholder' in document.createElement(that.tagName)) return;

		var placeholder = that.getAttribute('placeholder');
		var input = jQuery(that);

		if (that.value === '' || that.value == placeholder) {
			input.addClass('text-placeholder');
			that.value = placeholder;
		}

		input.focus(function(){
			if (input.hasClass('text-placeholder')) {
				this.value = '';
				input.removeClass('text-placeholder')
			}
		});

		input.blur(function(){
			if (this.value === '') {
				input.addClass('text-placeholder');
				this.value = placeholder;
			} else {
				input.removeClass('text-placeholder');
			}
		});

		that.form && jQuery(that.form).submit(function(){
			if (input.hasClass('text-placeholder')) {
				that.value = '';
			}
		});

	});

};


