// Helper functions
function prepPlaceholder(el) {
	if(el.attr('value') == '' || el.attr('value') == el.attr('placeholdertext')) {
		el.addClass('placeholder');
		if(el.attr('value') == '') {
			el.attr('value', el.attr('placeholdertext'));
		}
	} else {
		el.removeClass('placeholder');
	}
}
function togglePlaceholder(el) {
	// Check if the input already has a value...
	if((el.attr('value') != '') && (el.attr('value') != el.attr('placeholdertext'))) { return false; }
	if(el.attr('value') == el.attr('placeholdertext')) {
		el.attr('value', '');
	} else if(el.attr('value' == '')) {
		el.attr('value', el.attr('placeholdertext'))
	}
	el.toggleClass('placeholder');
}
function clearPlaceholdersOnSubmit() {
	jQuery('form').submit(function(){
		jQuery('input[placeholdertext]').each(function(){
			var _this = jQuery(this);
			if(_this.attr('value') == _this.attr('placeholdertext')) {
				_this.attr('value','');
			}
		});
	});
}
// Style 1: inputs with titles
function inputPlaceholders() {
	var els = jQuery('input[type=text][title].placeholder');
	els.each(function(){
		var _this = jQuery(this);
		// Set the placeholdertext attribute to the title
		_this.attr('placeholdertext',_this.attr('title'));
		prepPlaceholder(_this);
		_this.focus(function(){
			togglePlaceholder(_this);
		});
		_this.blur(function(){
			togglePlaceholder(_this);
		});
	});
	clearPlaceholdersOnSubmit();
}

jQuery(document).ready(function($) {
	// Initiate input placeholders
	inputPlaceholders();
	
	// :last-child fixes
	$('#footer-navigation li:last-child').addClass('last');
	
	// suckerfish dropdown fixes for IE
	$('#navigation li, #all-categories li').mouseover(function() {
		$(this).addClass('hover');
	});
	$('#navigation li, #all-categories li').mouseout(function() {
		$(this).removeClass('hover');
	});
});