/* 	Author: jab@nozebra.dk 
	Date:	05 jul 2011 */

var shown = false;
var first = true;

function getURLParameter(name) {
    return decodeURI(
        (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
    );
}

function showMenu(){
	if(shown==false){
		$("ul.priceDropdown li").each(
			function(){
				$(this).show();
				
			}
		)
		first=true;
		shown=true;
	}
	else{
		$("ul.priceDropdown li").each(
			function(){
					if(first==true){
						first=false; //Avoid the first li gets hidden
					}
					else{
						$(this).hide();
					}
				
			}
		)
		shown=false;
	}

}

//function hideMenu(){
//	$("ul.priceDropdown li").each(
//		function(){
//			if(first==true){
//				first=false; //Avoid the first li gets hidden
//			}
//			else{
//			$(this).hide();
//			$(this).hide().delay(5000);
//			alert('ud');
//			}
//		}
//	)
//}

function submitCategory(value){
	$('#categoryPicker').val(value);
	$("#dateSelector").submit();
//	$('#dateSelector').submit();
//	document.getElementById("dateSelector").submit();
}


function hover1_3img(id){
	$("#arrow" + id).removeClass('elementArrowOff').addClass('elementArrowOn');
	$("#img" + id).attr("src", "/Files/System/Damstahl2011/gfx/bg_1_3_global_selected.png");
}
function noHover1_3img(id){
	$("#arrow" + id).addClass('elementArrowOff').removeClass('elementArrowOn');
	$("#img" + id).attr("src", "/Files/System/Damstahl2011/gfx/bg_1_3_global.png");
}

function hover1_6img(id){
	$(id).addClass('selected');
}
function noHover1_6img(id){
	$(id).removeClass('selected');
}

function hoverProductsInTopemnu(id){
	$("#" + id).addClass('L1_ActiveHover').removeClass('L1_Active');
	$("#topMenuContainer").css('display','block');
}

function noHoverProductsInTopemnu(id){
	$("#" + id).addClass('L1_Active').removeClass('L1_ActiveHover');
	$("#topMenuContainer").css('display','none');
}

//Hver 3 .global_1_3-klasse skal have tilføjet .global_1_3_first-child
//$(".global_1_3:nth-child(2)").addClass("global_1_3_first-child");
//$(".global_1_4_v2:nth-child(2n+1)").addClass("global_1_3_first-child");


$(document).ready(function() {

	//Hver 1 .global_1_3-klasse skal have tilføjet .global_1_3_first-child
//	$(".global_1_3:nth-child(2)").addClass("global_1_3_first-child");
//	$(".global_1_3:nth-child(1)").addClass("global_1_3_first-child");
	
	$("ul.breadcrumb li:last-child").addClass("breadcrumbLast"); //removes arrow-images from last bread crumb li

	function megaHoverOver(){
		$(this).find(".sub").stop().fadeTo('fast', 1).show();
			
		//Calculate width of all ul's
		(function($) { 
			jQuery.fn.calcSubWidth = function() {
				rowWidth = 660;
				//Calculate row
				$(this).find("ul").each(function() {					
//					rowWidth += $(this).width(); 
				});	
			};
		})(jQuery); 
		
		if ( $(this).find(".row").length > 0 ) { //If row exists...
			var biggestRow = 660;	
			//Calculate each row
			$(this).find(".row").each(function() {							   
				$(this).calcSubWidth();
				//Find biggest row
				if(rowWidth > biggestRow) {
//					biggestRow = rowWidth;
					
				}
			});
			//Set width
			$(this).find(".sub").css({'width' :biggestRow});
			$(this).find(".row:last").css({'margin':'0'});
			
		} else { //If row does not exist...
			
			$(this).calcSubWidth();
			//Set Width
			$(this).find(".sub").css({'width' : rowWidth});
			
		}
	}
	
	function megaHoverOut(){ 
	  $(this).find(".sub").stop().fadeTo('fast', 0, function() {
		  $(this).hide(); 
	  });
	}


	var config = {    
		 sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)
		 interval: 100, // number = milliseconds for onMouseOver polling interval
		 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
		 timeout: 50000, // number = milliseconds delay before onMouseOut
		 out: megaHoverOut // function = onMouseOut callback (REQUIRED)
	};

	$("ul#topnav li .sub").css({'opacity':'0'});
	$("ul#topnav li").hoverIntent(config);
	

	if($('#citySelect').length != 0){
		$("#citySelect").click(function () {
		  $(".contactSearchOptions").slideToggle("slow");
		});
	}
//	$("#departmentSelect").click(function () {
//	  $(".contactSearchOptionsDepartment").slideToggle("slow");
//	});


});

//Search field input width change
$(document).ready(function() {
//					$('input[type="text"]').addClass("idleField");
	$('input#s').focus(function() {
//						alert('splat');
		$('input#s').animate({width:"200px"},400);
		if (this.value == this.defaultValue){
			this.value = '';
		}
		if(this.value != this.defaultValue){
			this.select();
		}
	});
	$('input#s').blur(function() {
//						$(this).removeClass("focusField").addClass("idleField");
		$('input#s').animate({width:"151px"},400);
		if (this.value == this.defaultValue){
			this.value = '';
		}
		if ($.trim(this.value == '')){
			this.value = (this.defaultValue ? this.defaultValue : '');
		}
	});
	$('.rightColBox input[type="text"]').focus(function() {
//		$('input#s').animate({width:"200px"},400);
		if (this.value == this.value){
//			alert(this.defaultValue);
			this.value = '';
		}
		if(this.value != this.value){
			this.select();
		}
	});
	
//	$("ul.priceDropdown li").css("display", "block");
});

