﻿$(document).ready(function(){
    $('.nav').formHighlighter({
            classFocus: 'focus',
            classBlur: 'blur',
            classKeyDown: 'keydown',
            classNotEqualToDefault: 'notEqualToDefault',
	    clearField:true
        });


$("div.productgroup div.product:nth-child(4n+1)").addClass("last");

if($("#bodyClass").text() !=''){
$("#fakeBody").removeClass().addClass($("#bodyClass").text());
}
else
{
$("#fakeBody").removeClass().addClass("sub");
}



/*Product viewer handler*/
$("#viewer img.small").first().addClass("showing");
$("#viewer img.small").last().addClass("last");
$("img.large").attr("src",$("#viewer img.small").first().attr("src"));

$("#zoomPicture a").attr("href",$("#viewer img.small").first().attr("title"));

$("#zoomButton").click(function(){

$("#zoomPicture a").click();

});

$("#viewer img.small").click(function(){
	$("img.small").removeClass("showing");
	$(".thumbItem").removeClass("active");
	$("img.large").attr("src",$(this).attr("src"));

	
	$("#zoomPicture a").attr("href",$(this).attr("title"));

	$(this).addClass("showing");
	$(this).parent().addClass("active");

});


/*Dynamic slider when there are more then 3 thumbs*/
var _thumbCounter = $("#thumbSlider #slideContent").children().size();
var _thumbLastStep = (_thumbCounter - 3) * (-88)+"px";

if(_thumbCounter > 3){
	// show arrows
	
	$("#thumbArrowUp").show();
	
	$("#thumbArrowUp").click(function(){ thumbSlideUp(); });
	$("#thumbArrowDown").click(function(){ thumbSlideDown(); });

}

function thumbSlideUp(){	

	$("#slideContent").animate({"margin-top": "-=88px"}, "slow",function() {
    	if($("#slideContent").css("margin-top") !='0px'){
		$("#thumbArrowDown").show();
	}
	
	console.log("Up" +  $("#slideContent").css("margin-top") + " -- " + _thumbLastStep);
	
	if($("#slideContent").css("margin-top") == _thumbLastStep)
	{
		$("#thumbArrowUp").hide();
	}
	
  });
	
}


function thumbSlideDown(){	

	$("#slideContent").animate({"margin-top": "+=88px"}, "slow",function() {
	
		console.log("DOWN" + $("#slideContent").css("margin-top") + " -- " + _thumbLastStep);
	
	if($("#slideContent").css("margin-top") =='0px'){
	
		$("#thumbArrowDown").hide();
	}
	
		if($("#slideContent").css("margin-top") != _thumbLastStep)
	{
		$("#thumbArrowUp").show();
	}
	
	 });
}



/* Left navi page hack */
$("#main #content .nav:not('ul.b_main')").append($(".nav.main ul li.active ul"));

$("#main #content .nav").has("ul.b_main").append($(".nav.main ul li#t14 ul"));

/*Front slide*/
   $(window).load(function () {
        $("#focus .items").cycle({
            fx: 'scrollHorz',
            timeout: 5000,
            speed: 1000,
            cleartype: true,
            pause: true,
            pager: '#focus .navi'
        });
     });


/*kunden siger*/


var randomNumber = Math.floor(Math.random()* $(".quote div").size());

$(".quote div:eq("+ randomNumber +")").delay(200).slideDown();




/*Landvælger hack*/

$(".input select option[selected='selected']").removeAttr("selected");
$(".input select option[value='382']").attr("selected","selected");

});
