$ = jQuery.noConflict();
$(document).ready(function() {
$("#Information").each(function(){
	$(this).find("span").hide();
});
	

$(".hasSub").each(function(){
	$(this).hover(function(){
		
		//bof:: added by ensys :: by prasad :: 7/28/2010
		$(this).find("ul").css({display: 'block'});		

	}, function(){
		//$(this).find("ul").slideUp("fast");
		$(this).find("ul").css({display: 'none'});		

	});
	//eof:: added by ensys :: by prasad :: 7/28/2010
});

/*
$("#Information").each(function(){
	$(this).hover(function(){
	
	if($(this).find("span").size() > 0){
		$(this).addClass("hoverOnlyRight padright");
		$(this).find("a.mainnav_hasSub").addClass("hoverOnlyLeft");
		$(this).find("span").css({display: "block"});	
		
	}
	
}, function(){
	$(this).removeClass("hoverOnlyRight padright");
	$(this).find("a.mainnav_hasSub").removeClass("hoverOnlyLeft");
	$(this).find("span").css({display: "none"});
})
});
*/

$("#Information").hover(function(){
	
	$(this).addClass("hoverOnlyRight");
	$(".mainnav_hasSub").addClass("hoverOnlyLeft");
	$(this).find("span").css({display: "block"});
}, function(){
	$(this).removeClass("hoverOnlyRight");
	$(".mainnav_hasSub").removeClass("hoverOnlyLeft")
	$(this).find("span").css({display: "none"});
});

//$(".mainLevel").append("<li class='last' style='display: none; clear: left;'></li>");
//$('.hasSub:last').addClass('last');

	// $("#navigationBar").append("<div id='wraper'></div>");
	/* 
	 $(".subLevel").each(function(){
		 $(this).hide();
	 });*/

//
//$('#wraper ul li:last').addClass('last');

	 $(".hasSub").each(function(){
		 $(this).hover(function(){
			 setCookie($(this).attr('id'));
			 $(this).nextAll().removeClass('now');
			 $(this).prevAll().removeClass('now');
			 $(this).addClass('now');
			 var content = $(this).children("span").html();
			 $("#wraper").html(' ') ;
			 if(content == '' || content == null){
				 content = '';
			 }
			
			 $("#wraper").slideUp("slow");
			 $("#wraper").html(content) ;
			 if(content != ''){
				 $("#wraper").slideDown("slow");
				 //$("#wraper").animate({opacity: "show"}, "slow");
				
			 }

		 });
	 });
/*if(getCookie( 'selectedMenuIs' )){
var menuIs = "#"+getCookie( 'selectedMenuIs' );
}else{
var menuIs = "#cat1";
}*/
/*var content = $(menuIs).children("span").html();
$(menuIs).addClass('now');
$("#wraper").html(content) ;*/
if(getCookie( 'selectedMenuIs' )){
var menuIs = "#"+getCookie( 'selectedMenuIs' );
$(menuIs).addClass('now');
}else{
	
//var menuIs = "#cat1";
}
var content = $(menuIs).children("span").html();


/*******************/
var items = $("#scrolingPanel").html();
var speed = 1500;
var zoom = 1.2;

$("#scrolingPanel").empty();

$("#scrolingPanel").prepend("<div id='inActiveLeft'>See flere Produkter</div><div id='leftArrow'>See flere Produkter</div><div id='scrolingContent'><div id='scrollable'></div></div><div id='inActiveRight'>See flere Produkter</div><div id='rightArrow'>See flere Produkter</div>");

$("#scrollable").html(items);

//var offset = parseInt($("#scrolingContent").width());
var offset = parseInt($("#scrolingContent").width())-400;

var contentWidth = $("#scrollable").width();

$("#scrolingContent").css({height: $("#leftArrow").height()});
$("#leftArrow").fadeOut('slow');

$(".zImg").each(function(){
	$(this).css({
		'width' : ($(this).find("img").width()+20) + 'px',
		'position' : "relative",
		'height' : $(this).find("img").height() + 'px'
	});
	$(this).find("div").css({		
		'width' : ($(this).find("img").width()+20) + 'px',		
		'height' : $(this).find("img").height() + 'px'
	});
	$(this).find("img").css({		
		'position' : "absolute"	,	
		'top' : "0px"	,	
		'left' : "0px"	
	});
});

$("#scrollable img").each(function(){
	var iWidth = $(this).width();
	var iHeight = $(this).height();
	$(this).hover(function(){
		
		$(this).animate({
			width: (iWidth * zoom) + 'px', 
			height: (iHeight * zoom) + 'px'
		}, 100);
	}, function() {
		$(this).animate({
			width: iWidth + 'px', 
			height: iHeight + 'px'
		}, 200);
	}).stop();
});

$("#leftArrow").click(function(){
	var leftSc = offset + parseInt($("#scrollable").css("left"));
	$("#scrollable").animate({left: leftSc+"px"},speed, function(){
		if(parseInt($("#scrollable").css("left"))  >= 0 ){
			$("#leftArrow").fadeOut('slow');
			$("#rightArrow").fadeIn('slow');
		}else{
			$("#rightArrow").fadeIn('slow');
		}
	});
});

/*$("#rightArrow").click(function(){
	var rightSc =  parseInt($("#scrollable").css("left"))- offset ;	
	$("#scrollable").animate({left: rightSc+"px"},speed, function(){
		if(parseInt($("#scrollable").css("left"))  <= (-contentWidth) ){
			$("#rightArrow").fadeOut('slow');
			$("#leftArrow").fadeIn('slow');
		}else{
			$("#leftArrow").fadeIn('slow');
		}
	});
});*/

$("#rightArrow").click(function(){
	var rightSc =  parseInt($("#scrollable").css("left"))- offset ;	
	//var endLimit = contentWidth-offset;
	$("#scrollable").animate({left: rightSc+"px"},speed, function(){
		if(parseInt($("#scrollable").css("left"))  <= (-contentWidth) ){
			$("#rightArrow").fadeOut('slow');
			$("#leftArrow").fadeIn('slow');
		}else{
			$("#leftArrow").fadeIn('slow');
		}
	});
});
/*******************/

function setCookie(name) {		
		document.cookie =  "selectedMenuIs =" +escape( name );	
	}

	function getCookie(name) {
		if (document.cookie.length>0)
		  {
		  c_start=document.cookie.indexOf(name + "=");
		  if (c_start!=-1)
		    {
		    c_start=c_start + name.length+1;
		    c_end=document.cookie.indexOf(";",c_start);
		    if (c_end==-1) c_end=document.cookie.length;
		    return unescape(document.cookie.substring(c_start,c_end));
		    }
		  }
		return "";
	}
 });
