/**
* 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() {

	$("#prodsearch .submit").live('mouseover', function() {
		$(this).attr("src", 'http://webfiles.tine.no/tine.no_v2/images/product_search_hover.gif');
	});
	$("#prodsearch .submit").live('mouseout', function() {
		if (!$("#prodsearch .submit").is(":focus")) {
			$(this).attr("src", 'http://webfiles.tine.no/tine.no_v2/images/product_search.gif');
		}
	});



	function megaHoverOver(){
		$(this).addClass('active');
	   $(this).find(".sub").attr('style','display: block;')
		// $(this).find(".sub").slideDown('fast');
	}

	//On Hover Out
	function megaHoverOut(){
	
	  $(this).removeClass('active');
	  $(this).find(".sub").attr('style','display: none;')
	 // $(this).find(".sub").slideUp('fast');
	  $(this).find("a:eq(0)").removeClass('active');
	}


	var config = {
		 sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)
		 interval: 50, // number = milliseconds for onMouseOver polling interval
		 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
		 timeout: 50, // number = milliseconds delay before onMouseOut
		 out: megaHoverOut // function = onMouseOut callback (REQUIRED)
	};

$("ul#mainnav li.topitem").hoverIntent(config); //Trigger Hover intent with custom configurations
	

	$("#prodExpandSearch").live('click', function(e) {
		e.preventDefault();
		$("#prodsearch .expand").slideToggle();
		
		if ($('#merke').is(':disabled')) {
			$('#merke').removeAttr('disabled');
        }
		
		
		if ($('#id').is(':disabled')) {
			$('#id').removeAttr('disabled');
        }
		
		
	});
	
	/* For mouseover color productfamily link */
		$("#familyLink").live("mouseover", function() {
			bgColor = $(this).attr("style");
			$(this).attr("style", "background-color: #F00000");
		});
		$("#familyLink").live("mouseout", function() {
			$(this).attr("style", bgColor);
		});

	
});



/* produktkarusell*/

/* Speed for scrolling */
var scrollSpeed = 8;
var slideSpeed = 500;
var overlayId = "#logokarusellOverlay";
var activeName = "Active.png";
var showNumberOfLinks = 10;

/* Do not change, used for the links */
var multiplier = 1;
var bgColor;

/* Mouse over on left arrow, moves it to the left */
$("#productkarusell .right").live("mouseover", function() {
	this.iid = setInterval(function() {
		var position = $("#productkarusell .productpics").scrollLeft();
		$("#productkarusell .productpics").scrollLeft(position + scrollSpeed);
		$(this).mouseover();
	}, 25);
}).live("mouseout", function() {
	this.iid && clearInterval(this.iid);
});

/* Mouse over on right arrow, moves it to the right */
$("#productkarusell .left").live("mouseover", function() {
	this.iid = setInterval(function() {
		var position = $("#productkarusell .productpics").scrollLeft();
		$("#productkarusell .productpics").scrollLeft(position - scrollSpeed);
		$(this).mouseover();
	}, 25);
}).live("mouseout", function() {
	this.iid && clearInterval(this.iid);
});

function expand(){
	var nid = $(this).attr('id');
	alert(nid);	
}

