/**
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
*
* @param f onMouseOver function || An object with configuration options
* @param g onMouseOut function || Nothing (use configuration options object)
* @author Brian Cherne <brian@cherne.net>
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);


$(document).ready(function() {
	//hide the sidebar items when on home page
	$("#Home > #qj_specials, #Home > #recenlty_viewed").hide();
	
	//account login panel
	function addMega(){
		$(this).addClass("hovering");
	}
	
	function removeMega(){
		$(this).removeClass("hovering");
	}
	
	var megaConfig = {
		interval: 150,
		sensitivity: 4,
		over: addMega,
		timeout: 50,
		out: removeMega
	};
	$("li.mega").hoverIntent(megaConfig);
	
	//featured products slideshow settings
	if($("#featured").length) {
		$("#featured").easySlider({
			//auto: true, 
			vertical: true,
			continuous: true,
			numeric: false
		});
	}
	
	//80% opacity items rollover settings	
	if (jQuery.support.opacity) {
	   $("#input_search_prod_btn, #smt_search_key_btn, .spf > div > a > img, a.btn_add_small, #smt_login_btn, #smt_add_cart_btn, #input_submit_review").addClass("op80");
	}
	$(".op80").hover(  
		function() {  
			if (jQuery.support.opacity) {
			 $(this).animate({opacity: 1}, "fast");
			}
		},
		function() {  
			if (jQuery.support.opacity) {
			 $(this).animate({opacity: 0.8}, "fast");
			}
		}  
	);		        
	
	//50% opacity items rollover settings
	//$(".op50").fadeTo(0, 0.5);
	$(".op50").hover(  
		function() {  
			if (jQuery.support.opacity) {
			 $(this).animate({opacity: 1}, "fast");
			}
		},
		function() {  
			if (jQuery.support.opacity) {
			 $(this).animate({opacity: 0.5}, "fast");
			}
		}  
	);	
	//$(".enlarge").fadeTo(0,0);
	$(".prod_v_img > a").hover(  
		function() {  
			$(this).children(".enlarge").css("display", "block");
		},
		function() {  
			$(this).children(".enlarge").css("display", "none");
		}  
	);	
	//toggle tab on link click
	var $tabs = $("#product_results").tabs(); // first tab selected

	$("#view_all_reviews").click(function() { // bind click event to link
	    $tabs.tabs('select', 1); // switch to reviews tab
	    return false;
	});
	
	//product image tabs
	$(".tabs").tabs("div.ui-tabs-panel").tabs({ fx: { opacity: "toggle", effect: "fade", fadeOutSpeed: 5} }); 
	
	//recently viewed items toggle
	$("li.toggle > .product").fadeTo(0, 0.5);
	$("li.toggle").hover(
		function() {
            $(this).children(".product").animate({opacity: 1}, "fast");
            $(this).addClass("hover").children("div.prod_detail").children("div.prod_desc").animate({ 
              opacity: 1,
              left: "0"
              }, 150, 'linear' );
		},
		function() {
    		 $(this).children(".product").animate({opacity: 0.5}, "slow");
			$(this).children("div.prod_detail").children("div.prod_desc").animate({ 
			  opacity: 0,
			  left: "202px"
			}, 250, 'linear', function() {
			     $(this).parent().parent().removeClass("hover")
			    } );
		}
		
	);
	//input box default text replace
	textReplacement($('#input_search_key_txt'));
	function textReplacement(input){
		var originalvalue = input.val();
		input.focus( function(){
	 		if( $.trim(input.val()) == originalvalue ){ input.val(''); }
		});
		input.blur( function(){
	 		if( $.trim(input.val()) == '' ){ input.val(originalvalue); }
		});
	}				
	//sidebar scroller
	$("#navbar").stickyfloat({ duration: 800 });
	
    //
   });

