if($.browser.msie&&($.browser.version=="6.0")&&!window.XMLHttpRequest){$("head:first").append('<link href="/_assets/css/ie6.css" rel="stylesheet" type="text/css" media="all" />')}
$(function(){

// Navigering -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

	var oNav;
	var arrRolldown;

	// Dropdown
	$("#nav li").hoverIntent(function() { $(this).find("ul").css("display","block"); }, function() { $(this).find("ul").css("display","none"); });

	// Dropdownlänkning
	$("#nav ul li").click(function() { document.location = $(this).find("a:first")[0]; });

	// Subnav submeny
	$("#subNav ul").parent().find("a:first").click(function(e){ $(this).parent().find("ul").toggle(); e.preventDefault(); });
	
	// Rensa sökruta
	$("#ctl00_ContentPlaceHolderMain_search1_tbSearch").click(function(e) { this.value = ""; });

	// Rensa sökruta
	$("li.retailer").click(function(e) { document.location = $(this).find("a:first")[0]; });

	// Bildspel, kollektion
	$('#collectionSlide').cycle({
        fx:     'fade',
        timeout: 5000,
        pager:  '#collectionSlideThumb',
		pagerAnchorBuilder: function(idx, slide) { return '#collectionSlideThumb li:eq(' + idx + ') a'; }
    });
	 
	function isValidEmail(email) 
	{ 
		var re = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
		return re.test(email);
 	}

	function showValidationError(selector) 
	{ 
		$(selector).css("background-color", "#FD8985");
	}

	function hideValidationError(selector) 
	{ 
		$(selector).css("background-color", "");
	}

	
	$(".checkout1 #ctl00_ContentPlaceHolderMain_btnNext").click(function(e){
		var preventDefault = false;
		$(".required:visible").each(function(i) {
			hideValidationError(this);
			if ($.trim($(this).val()) == "") {
				showValidationError(this);
				preventDefault = true;
			}
		});
		
		var emailSelector = "#ctl00_ContentPlaceHolderMain_billToEmail";
		var emailVal = $(emailSelector).val();
		hideValidationError(emailSelector);  
		if (emailVal != "") {
			if (!isValidEmail(emailVal)) { 
				showValidationError(emailSelector);  
				preventDefault = true;
			}
		}
		
		
		
		if (preventDefault) {
			e.preventDefault();
		}
	});
	 
	 $(".checkout1 input[type='checkbox']").change(function() {
		 $shipToFields = $("#shipToFields");
		 if ($(this).attr("checked")) {
			$shipToFields.slideDown("slow");
			$shipToFields.find("input:first").focus();
		} else {
			$shipToFields.slideUp("slow");
		}
	});
	
	var sum = $("#ctl00_ContentPlaceHolderMain_sum").val();
	var freight = $("#ctl00_ContentPlaceHolderMain_freight").val();
	var currency = " " + $("#ctl00_ContentPlaceHolderMain_currency").val();
	
	var	origtotal,
			shipping,
			newtotal;
	if (sum != undefined) {
		origtotal = new Number(sum.replace(",", "."));
		shipping = new Number(freight.replace(",", "."));
		newtotal = new Number(shipping + origtotal)
		$(".checkout2 table#sum .right:last").html(newtotal.toFixed(2) + currency);
	}
	$("#ctl00_ContentPlaceHolderMain_rblShipping input").change(function() {
		shipping = new Number($(this).parent().attr("title").replace(",", "."));
		newtotal = new Number(shipping + origtotal)
		$(".checkout2 table#sum .right:first").html(shipping.toFixed(2) + currency);
		$(".checkout2 table#sum .right:last").html(newtotal.toFixed(2) + currency);
	});


	// Provbeställning
	$("#ctl00_ContentPlaceHolderMain_ddlColor").change(function() {
		if ($(this).val() == 0) {
			$("#ctl00_ContentPlaceHolderMain_btnAdd").hide();
		} else {
			$("#ctl00_ContentPlaceHolderMain_btnAdd").show();
		}
	});
});



function flash(strFile, strId, strClass, intWidth, intHeight) {
    document.write("<object class=\"" + strClass + "\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" name=\"" + strId + "\" width=\"" + intWidth + "\" height=\"" + intHeight + "\" id=\"" + strId + "\">");
    document.write("<param name=\"movie\" value=\"" + strFile + "\" />");
    document.write("<param name=\"quality\" value=\"high\" />");
    document.write("<param name=\"wmode\" value=\"transparent\">");
    document.write("<param name=\"SCALE\" value=\"exactfit\">");
    document.write("<param name=\"menu\" value=\"false\">");
    document.write("<embed class=\"" + strClass + "\" src=\"" + strFile + "\" width=\"" + intWidth + "\" height=\"" + intHeight + "\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" scale=\"exactfit\" menu=\"false\" name=\"" + strId + "\"></embed></object>");
}
