

/*
   PLUGINS------------------------------------------------------------------------
*/

//Hover Intent Plugin "http://cherne.net/brian/resources/jquery.hoverIntent.html"
(function(d){d.fn.hoverIntent=function(k,l){var c={sensitivity:7,interval:100,timeout:0},c=d.extend(c,l?{over:k,out:l}:k),f,g,h,i,j=function(c){f=c.pageX;g=c.pageY},m=function(e,b){b.hoverIntent_t=clearTimeout(b.hoverIntent_t);if(Math.abs(h-f)+Math.abs(i-g)<c.sensitivity)return d(b).unbind("mousemove",j),b.hoverIntent_s=1,c.over.apply(b,[e]);else h=f,i=g,b.hoverIntent_t=setTimeout(function(){m(e,b)},c.interval)},n=function(e){var b=jQuery.extend({},e),a=this;if(a.hoverIntent_t)a.hoverIntent_t=clearTimeout(a.hoverIntent_t);
if(e.type=="mouseenter"){if(h=b.pageX,i=b.pageY,d(a).bind("mousemove",j),a.hoverIntent_s!=1)a.hoverIntent_t=setTimeout(function(){m(b,a)},c.interval)}else if(d(a).unbind("mousemove",j),a.hoverIntent_s==1)a.hoverIntent_t=setTimeout(function(){a.hoverIntent_t=clearTimeout(a.hoverIntent_t);a.hoverIntent_s=0;c.out.apply(a,[b])},c.timeout)};return this.bind("mouseenter",n).bind("mouseleave",n)}})(jQuery);

/*
  FUNCTIONS---------------------------------------------------------------------
 */

/*
//hide loading gif when img loaded
$('.product-box .image-container img').hide();

$('.product-box .image-container img').load(function(){
	$(this).parents('.image-container').css('background-image', 'none');
	$(this).fadeIn(500);
});
*/

$(document).ready(function(){


//--Dropdown menu
	$("#mainnav li").hoverIntent({
		sensitivity:1,
		interval:100,
		over:function(){
			$(this).find("> ul, > div").fadeIn(400).show()
		},
		timeout:350,
		out:function(){
			$(this).find("> ul, > div").fadeOut(500,function(){$(this).hide()})
		}
	});	

/*
//--Add to Cart js
	//timeout function
	function fadeOutTime() {
		$(".cart-drop").fadeOut(250);
	};

	//Trigger Function
	$('.add-cart').click(function() {
		//Dropdown Drop/Fade
		if (! $(".cart-drop").is(":visible")) {
			$(".cart-drop").stop().slideDown(400, function() {
				var timoutId = setTimeout(fadeOutTime, 4000 );
			});
		};

		var price = $('.total-price').html();//Get Total
		
		setTimeout( function() {
			//Show 'minimum limit' notification
			if( price < 500 ){
				$(".minimum").text('Only $20 left to reach the $500 minimum order');
			}

			//Hide 'minimum limit' notification
			if( price >= 500  ){
				$('.minimum').text('You\'ve Reached the Minimum Order size');
			}
		}, 850 );
		return false;
	});
  
	//Close Dropdown with 'x' or ' Continue Shopping'
	$('.cart-drop .close, .cart-drop .continue').click( function() { 
		$(".cart-drop").stop(true, true).fadeOut(250);
		return false;
	});

*/	
});


//--Clear Form Fields
jQuery.fn.cleardefault=function(){return this.focus(function(){if(this.value==this.defaultValue)this.value=""}).blur(function(){if(!this.value.length)this.value=this.defaultValue})};   $("input:not(input[type='submit']), textarea").cleardefault();

//--Smooth Scroll to internal links
$(function(){$("a[href*=#], a.smoothscroll").click(function(){if(location.pathname.replace(/^\//,"")==this.pathname.replace(/^\//,"")&&location.hostname==this.hostname){var a=$(this.hash),a=a.length&&a||$("[name="+this.hash.slice(1)+"]");if(a.length)return a=a.offset().top,$("html,body").animate({scrollTop:a},1E3),!1}})});

//--Catalog Search submit
function searchSubmit() {
	var term = document.getElementById('searchTerm').value;
	if (!term) {
		alert('Please enter something to search for.'); return false;
		}
	else
		document.forms['catalogSearch'].submit();
	}

