//jQuery.noConflict();

jQuery(function() {
	
	// NAV DROPDOWNS
	jQuery('#header ul li').hover(function() {
		jQuery(this).addClass('over');
	}, function() {
		jQuery(this).removeClass('over');
	});

	// CLEAR SEARCH BOXES
	jQuery('.default').each(function() {
		var default_value = this.value;
		jQuery(this).focus(function() {
			if(this.value == default_value) {
			this.value = '';
			}
		});
		jQuery(this).blur(function() {
			if(this.value == '') {
			this.value = default_value;
			}
		});
	});

	// ADD CLASSES TO ELEMENTS
	jQuery('#main-nav ul li:last').each(function(){
		jQuery(this).addClass('last');
	});
	jQuery('#sub-nav li:first').each(function(){
		jQuery(this).addClass('first');
	});
	jQuery('#rec-products ul li:last').each(function(){
		jQuery(this).addClass('last');
	});
	jQuery('#category-content #center #rec-products ul li:nth-child(3n+1)').each(function(){
		jQuery(this).addClass('one')
	});
	jQuery('#category-content #center #rec-products ul li:nth-child(3n)').each(function(){
		jQuery(this).addClass('three')
	});
	jQuery('#reviews-content #main table:last').each(function(){
		jQuery(this).attr('id', 'average-rating');
		jQuery(this).before('<h2 id="average-rating-head">Average Rating</h2>');
	});
	
	if (jQuery.browser.msie && jQuery.browser.version.substr(0,1) < 7) {		
	} else {
		var windowHeight = jQuery(window).height(),
			footerHeight = jQuery('#footer').height(),
			footerOffset = jQuery('#footer').offset(),
			footerTop = footerOffset.top,
			footerTopDiff = windowHeight - (footerHeight + footerTop);

			if (footerTopDiff > 0)
			{
				jQuery("#footer-bottom").css('height', (footerTopDiff+footerHeight)-70);
			}
	}
	
	
	var AJ = AJ || {};

	AJ.placeholders = function() {

		function showPlaceholder(input) 
	  {    
	      //see if there is HTML5 support - if so bail out... no need for the rest
	      if ('placeholder' in document.createElement('input')) return;

	      var placeholderText = input.attr("placeholder");
	      if ( input.val() === "" || input.val() === placeholderText ) 
	      {
	          input.val(placeholderText);
	      }
	  };	

		$("input[type=text][placeholder]").each( 
	      function() 
	      {
	          showPlaceholder($(this));
	      } 
	  )
	  .blur( 
	      function() 
	      {
	          showPlaceholder($(this));
	      }
	  )
	  .focus( 
	      function() 
	      {
	          var input = $(this);
	          if (input.val() === input.attr("placeholder")) 
	          {
	              input.val("");
	          }
	      } 
	  );

	};

	$( function() { AJ.placeholders(); });
	
	
});
