if($.browser.msie&&($.browser.version == "6.0")&&!window.XMLHttpRequest)
	$("head:first").append('<link href="/media/css/ie6.css" rel="stylesheet" type="text/css" media="all" />');

var options, a;
$(document).ready(function() {
	
	//Slide list functionalitility. For hide/show points in list					   
	$(".slide-list > li").each(function() {
		$(this).children('h4').click(function() {
			$(this).parent().children('div').slideToggle('fast');
		}); 
	});
	
	//If the menu has childs, show them
    if ($("#submenu-wrapper").children().size() > 0) {
        $("#submenu-wrapper").show();
        $("#speech-bubble-selector").show();
    }

	//Dont know what this does
    var f = $(".toggler");
    f.addClass("clickable");
    f.click(function() {
        $(this).next().toggle();
        $(this).toggleClass("active");
    });

	
    //$("#fancybox-close").click(UnLockWindow);

    //FancyBoxes
	try {
		
			$("a.openLightbox").fancybox({ title: ' ',afterShow: function() { $(".fancybox-inner :input").filter("[type=text],[type=password]").first().focus() } });
			$("a.openLightboxLarge").fancybox();
			$("a.openStoreMap").fancybox();
			$("a.openZoomLightBox").fancybox({  width: 630, height: 640, autoSize: false});
			
			$("#footer").append("OK");
		
		} catch(err) {

			$("a.openLightbox").attr("href","/ClearCache.asp").attr("onclick","");
			$("a.openLightboxLarge").attr("href","/ClearCache.asp").attr("onclick","");
			$("a.openStoreMap").attr("href","/ClearCache.asp").attr("onclick","");
			$("a.openZoomLightBox").attr("href","/ClearCache.asp").attr("onclick","");
			
			$("#footer").append("Err: " + err.description);
			
		}	
	
    //End FancyBoxes

	// Giftcard (2011.03.28 Jocke)
	$("#giftcardCheckBalance").click(function(e) 
	{ 
		pageTracker._trackEvent("External link", "Giftcard", "Check balance");
		
		// Giftcard popup (2011.03.28 Jocke)
		e.preventDefault();
		var url = $(this).attr("href");
		var balanceWindow = window.open(url, "balanceWindow", "location=0,status=0,scrollbars=0, width=500,height=600");
	}); 


	// Prrevent default action on search fields
	$("#textSearchForm").mouseup(function(e) {
		e.preventDefault();
	});
	
	
	//Autocomplete from FactFinder
	$('#textSearchForm').autocomplete({
								serviceUrl: '/search/autocomplete',
								minChars: 2,
								onSelect: function(value) { location.href = '/search-result/?q=' + value; },
								maxHeight: 400,
								width: 500
	});
	
	
	//Show tooltip box
//	try { $(".showToolTip").tooltip(); } catch(e) { }; STRIPPED DUE SMARTPHONES DOES NOT SUPPORT MOUSEOVER GESTURES VERY VELL (2012-01-31)

	
});	

function checkIfWeCanSearch(defaultText) {
	
	if($("#textSearchForm").val() == defaultText) {
		
		$("#textSearchForm").val("");
		$("#textSearchForm").attr("style","color: 000");
		$("#textSearchForm").focus();
		
		return false;
	}	
}

function ShowPriceWithIncludeVat(value) {
	var date = new Date();
	date.setTime(date.getTime()+(14*24*60*60*1000));
	var expires = "; expires="+date.toGMTString();
	document.cookie = "ShowPriceWithIncludeVatKey"+"="+value+expires+"; path=/";
	location.href = location.href;
}

function AddToCart(productId,quantityHolder)
{
	
	var qnty = $("#"+quantityHolder);
	var productQuantity = parseInt(qnty.val().replace(/[^0-9]+/,""));

    if(isNaN(productQuantity)) {
		productQuantity = 1;
		qnty.val(1);
	}
	  
	$.post("/cart/add", { product: productId, quantity :productQuantity, templateId:576}, function(data) {  
	if(data!=null && data.length >=0){
		$("#cart-wrapper").replaceWith(data)}
		qnty.effect("transfer", { to: $("#cart-wrapper") }, 1000);
	}, "text"); 
}

function LockWindow() {
    if ($("#checkout-lock").length > 0)
        return;
    var d = $(document).find('div:first');
    $('<div id="checkout-lock" style="height:' + ___getPageSize()[1] + 'px;">&nbsp;</div><div id="checkout-lock2" style="height:' + ___getPageSize()[1] + 'px;"><div><img id="checkout-lockImg" alt="" src="/media/images/ajax-loader.gif"/></div></div>').insertBefore('div:first');
}

function UnLockWindow() {
    
    if( $('div#checkout-lock').length>0 )
        $('div#checkout-lock').remove();
    if( $('div#checkout-lock2').length > 0)
        $('div#checkout-lock2').remove();
}




