$(document).ready(function(){
var thisTarget = "";
		 var LoadToppen = $("#MainContent").offset().top+200;
		 var LoadLeften = $("#MainContent").offset().left+350;
		 $("div#LoadingIntro").css({ position: "absolute", top: LoadToppen,left: LoadLeften});
		$('#LoadingIntro').fadeIn('slow');
		$('.introImages').hide();
		$.preload('.introImages img',{
			onFinish:finishIntro,
			placeholder:'media/2444/intro%20bilde%206.jpg',//this is the really important option
			threshold:5 //'1' is the default, how many at a time, to load.			
		});
		function finishIntro(){//hide the summary

			$('#LoadingIntro').hide();
			$('.introImages').show();
			$('.introImages').cycle({
				fx: 'fade',
				random: 1
			});
		
		}
		$("div#SubMeny").show();

		$("div#MenyLinkSelected").mouseover(function()
		{
		  $("div#SubMeny").fadeIn("slow");
		});


		$("a#MenyLinkSelected").mouseover(function()
		{
		  $("div#SubMeny").fadeIn("slow");
		});


		$(".MenyLink").bind("mouseenter",function()
		{
		  window.setTimeout(function(){$("div#SubMeny").fadeOut("slow");},10000);
		});

		$("div#SubMeny").bind("mouseleave",function()
		{
		  window.setTimeout(function(){$("div#SubMeny").fadeOut("slow");},10000);
		});

		window.setTimeout(function(){$("div#SubMeny").fadeOut("slow");},10000);


		$(".SammeVindu").click(function()
		{
		  
		  thisTarget = ".SammeSerieInfo" + $(this).attr('name');
		  thisName = "New" + $(this).attr('name');
		  thisNameLink = "." + thisName;
		$(thisTarget).each(function(index)
		{

			var $this = $(this);
			var thisId = this.id;
			$this
				.clone()
				.find('a')
			          .attr({
			            'title': $this.text() 
			          })
				.end()
				.appendTo('div#InfoBox')
				.attr("class",thisName);
		});		
		


		  $(".SammeSerieBox").hide();
		  $('#Loading').hide();
		  $("div#modalBack").show();
		  $("div#InfoBox").fadeIn("slow");
		  $("div#InfoBox").animate({width:700,height:450},"slow");
		  var Toppen = $(".highslide-wrapper").offset().top;
		  var Leften = $(".highslide-wrapper").offset().left;
		  $("div#CloseInsp").css({ position: "absolute", top: Toppen,left: Leften});
		  $("div#CloseInsp").width(700);
		  window.setTimeout(function(){$("div#CloseInsp").fadeIn("slow");},1000);		
		  window.setTimeout(function(){$(thisNameLink).fadeIn("slow");},200);
		  window.setTimeout(function(){$(".SammeSerieBox").fadeIn("slow");},1000);
		  Toppen = $(".highslide-wrapper").offset().top+15;
		  Leften = $(".highslide-wrapper").offset().left;
		  $("div#InfoBox").css({ position: "absolute", top: Toppen,left: Leften});
		});


		$(".ProdInfo").click(function()
		{
		  
		  thisTarget = "." + $(this).attr('name');
		  thisName = "New" + $(this).attr('name');
		  thisNameLink = "." + thisName;
		$(thisTarget).each(function(index)
		{

			var $this = $(this);
			var thisId = this.id;
			$this
				.clone()
				.find('a')
			          .attr({
			            'title': $this.text() 
			          })
				.end()
				.appendTo('div#InfoBox')
				.attr("class",thisName);
		});		
		


		  $(".SammeSerieBox").hide();
		  $('#Loading').hide();
		  $("div#modalBack").show();
		  $("div#InfoBox").fadeIn("slow");
		  $("div#InfoBox").animate({width:700,height:450},"slow");
		  var Toppen = $(".highslide-wrapper").offset().top;
		  var Leften = $(".highslide-wrapper").offset().left;
		  $("div#CloseInsp").css({ position: "absolute", top: Toppen,left: Leften});
		  $("div#CloseInsp").width(700);
		  window.setTimeout(function(){$("div#CloseInsp").fadeIn("slow");},1000);		
		  window.setTimeout(function(){$(thisNameLink).fadeIn("slow");},200);
		  window.setTimeout(function(){$(".SammeSerieBox").fadeIn("slow");},1000);
		  Toppen = $(".highslide-wrapper").offset().top+15;
		  Leften = $(".highslide-wrapper").offset().left;
		  $("div#InfoBox").css({ position: "absolute", top: Toppen,left: Leften});
		});



		$(".Insp").click(function()
		{
		  
		  thisTarget = "." + $(this).attr('name');
		  thisName = "New" + $(this).attr('name');
  		  thisNameLink = "." + thisName;
		$(thisTarget).each(function(index)
		{

			var $this = $(this);
			var thisId = this.id;
			$this
				.clone()
				.find('a')
			          .attr({
			            'title': $this.text(), 
			            'href': '#' + thisId
			          })
				.end()
				.prependTo('div#InfoBox')
				.attr("class",thisName);
		});		
		

		  $("div#modalBack").show();
		  var LoadToppen = $(".highslide-wrapper").offset().top+200;
		  var LoadLeften = $(".highslide-wrapper").offset().left+250;
		  $("div#Loading").css({ position: "absolute", top: LoadToppen,left: LoadLeften});
		  $('#Loading').fadeIn('slow');
		  $(".active").hide();
		  $.preload('.active img',{
				onFinish:finish,
				placeholder:'/media/361/testprodukt2.jpg',//this is the really important option
				threshold:1 //'1' is the default, how many at a time, to load.			
		  });

			function finish(){//hide the summary

 			  $('#Loading').fadeOut('slow');
			  $("div#InfoBox").fadeIn("slow");
			  $("div#InfoBox").animate({width:432,height:332},"slow");
			  var Toppen = $(".highslide-wrapper").offset().top;
			  var Leften = $(".highslide-wrapper").offset().left;
			  $("div#CloseInsp").css({ position: "absolute", top: Toppen,left: Leften});
			  $("div#CloseInsp").width(432);
			  window.setTimeout(function(){$("div#CloseInsp").fadeIn("slow");},1000);		
			  window.setTimeout(function(){$(thisNameLink).fadeIn("slow");},200);
			  Toppen = $(".highslide-wrapper").offset().top+15;
			  Leften = $(".highslide-wrapper").offset().left;
			  $("div#InfoBox").css({ position: "absolute", top: Toppen,left: Leften});
			  window.setTimeout(function(){$(".active").show();},2000);
			  window.setTimeout(function(){$(".active").cycle({
			      fx:     'fade', 
			      timeout: 3000 
			  });},2000);
	
			};

		});
		
		$("a#ACloseInsp").click(function()
		{
		  
		  $("div#InfoBox").animate({width:0,height:0},"slow");
		  $(thisTarget).fadeOut("slow");
		  $("div#CloseInsp").fadeOut("slow");
		  $("div#CloseInsp").width(0);
		  $("div#InfoBox").fadeOut("slow");
		  window.setTimeout(function(){$("div#modalBack").hide();},700);
		  $("div#InfoBox").empty();	
		});

		$(".SammeSerieBox").click(function()
		{
			var $this = $(this);
			var thisId = this.id;
			alert($this.find('a').attr('href'));

		});

	});