var dimmer;
var content;
var block;

$(document).ready(function(){

/********************************
Ring Size Guide
********************************/

	dimmer = $(".bgDimmer");
	content = $(".adZone .content");
	block = $(".adZone .block");
	btn_close = $(".adZone .close");
	links = $(".adZone a");

	btn_close.click(function(){
		closePopup();						 
	})
	links.click(function(){
		closePopup();						 
	})


	/*************************************
	Current page
	*************************************/
	var current = $("#swParent").text();
	$(".menuSub .swMenuItem a.active").each(function(){
		if($(this).attr("href").indexOf(current) > -1) {
			$(this).addClass("current");
		}
	});

	/*************************************
	Leftmenu expand current page
	*************************************/

	//swMenuHideAllSub(document.getElementById("swMenuTree"));
	var curMenuItem = $("div.swMenuItem[ParentId="+current+"]");
	if (curMenuItem.length > 0) {
		var curMenuItemId = curMenuItem.get(0).id;
		swMenuShowBranch(curMenuItemId);
	}


	if (($("#swNavigationLineValues").html().indexOf("320951")>0) || ($("#swNavigationLineValues").html()=="320951"))
	{
		$("div#swMiniBasket").show();
		$("div.creditcards").show();

	}
	else
	{
		if ($("div#swMiniBasket .basket a").html().indexOf("( 0 )")==-1)
		{
			$("div#swMiniBasket").show();
			$("div.creditcards").show();

		}
	}
	
	
	
	/////////////////////////////////////
	/// add text on product spec.
	/////////////////////////////////////
	$(".commerce-show-prices .commerce-show-oldpricetext").wrap("<div />").before("<span class='itemaddtext'>Before</span>")
	if ($(".commerce-show-prices span.commerce-show-additem:eq(0)").text().indexOf('»')!=0)
	{
		$(".commerce-show-prices .item-add-no").wrap("<div />").before("<span class='itemaddtext'>"+$(".commerce-show-prices span.commerce-show-additem:eq(0)").text()+"</span>");
	}
	else
	{
		$(".commerce-show-prices .item-add-no").wrap("<div />").before("<span class='itemaddtext'>Pieces</span>")
	}
	$(".commerce-show-prices .commerce-show-newprice").wrap("<div />").before("<span class='itemaddtext'>Price</span>");
	$(".commerce-show-feature select").before("<span class='itemaddtext'>Size</span>");
		
	
	/////////////////////////////////////
	/// remove dotted line in checkout
	/////////////////////////////////////
	$(".swCommerceShowBasket tr td[background='/sw/gfx/line2.gif']").hide()


	/////////////////////////////////////
	/// hide additional cells below e-com item
	/////////////////////////////////////
	$(".commerce-show-prices").parents("tr").eq(0).prev().hide();
	$(".commerce-show-prices").parents("tr").eq(0).next().hide();

	/////////////////////////////////////
	/// Move price table to content
	/////////////////////////////////////
	$("#swItemSpec").append($(".commerce-show-prices"));

	/////////////////////////////////////
	/// Move attributes below price table
	/////////////////////////////////////
	$("#swItemSpec").append($(".commerce-show-feature"));


	/////////////////////////////////////
	/// Get first clearfloat and float it
	/////////////////////////////////////
	$(".swClearBoth").eq(0).addClass("first");

	/////////////////////////////////////
	/// Add link to header of related item
	/////////////////////////////////////
	var relatedItems = $(".swCommerceRelatedProductLink");
	relatedItems.each(function(){
		var theHref = $(this).find("a").attr("href");
		var theHeader = $(this).find(".commerce-show-imagetext");
		theHeader.wrapInner("<a class='headerLink' href='"+theHref+"' />");
	});

	/////////////////////////////////////
	/// Add link to header of frontpage item
	/////////////////////////////////////
	var relatedItems = $(".swCommerceRows");
	relatedItems.each(function(){
		var theHref = $(this).find("a").attr("href");
		var theHeader = $(this).find(".commerce-show-imagetext");
		theHeader.wrapInner("<a class='headerLink' href='"+theHref+"' />");
	});


	/////////////////////////////////////
	/// Reset menu on frontpage
	/////////////////////////////////////
	
	var parent = $("#swParent").text();
	var menu = $("#swMenuTree").get(0);
	if(parent == ""){
		swMenuHideAllSub(menu);
	}

/* ADD CSS CLASS TO INPUT AND SUBMIT BUTTONS */
	$("input[@type=submit]").addClass("inputsubmit");
	$("input[@name=search]").addClass("inputsearch");


	/////////////////////////////////////
	/// Åben/luk funktion
	/////////////////////////////////////


	$(".OpenCloseText").swToggle(
		{
			displaytype: "image",
			closeImg: "/cgi-files/i_collapse.gif",
			openImg: "/cgi-files/i_expand.gif",
			effect: ""
		});

});

(function($) {
  $.fn.swToggle = function(settings)
  {
		var defaults = {   
			closeText: "[X]",   
			openText: "[-]",   
			closeImg: "close.gif",   
			openImg: "open.gif",   
			displaytype: "text",  
			effect: "slow"  
		};   
		var options = $.extend(defaults, settings);  
  	
  	return this.each(function(index)
  	{
		obj = $(this);   
		obj.attr('id','swToggle'+index);
		obj.wrap('<div id="swToggleBottom'+index+'" class="swToggleContainer"/>');
		if (options.displaytype=="text")
		{
			obj.before('<div class="swToggleClose"><a href="javascript:void(0)" index='+index+'>'+options.openText+'</a><a href="javascript:void(0)" style="display:none;" index='+index+'>'+options.closeText+'</a></div>')
		}
		else
		{
			obj.before('<div class="swToggleClose"><a href="javascript:void(0)" index='+index+'><img src="'+options.openImg+'" border="0"></a><a href="javascript:void(0)" style="display:none;" index='+index+'><img src="'+options.closeImg+'" border="0"></a></div>')
		}	
		
		obj.hide();
		$('#swToggleBottom'+index+' .swToggleClose a').click(function() {
			$('#swToggle'+$(this).attr("index")).toggle(options.effect);	
			$('#swToggleBottom'+$(this).attr("index")+' .swToggleClose a').toggle();
		});
	});
  };
})(jQuery);


function closePopup() {
	content.hide("slow");
	dimmer.fadeTo("slow", 0.00, function(){dimmer.hide()});
}

function openPopup(url) {
	content.show("slow");
	dimmer.show();
	dimmer.fadeTo("slow", 0.90);
	if (!url) {
		url="";
	}
	else {
		block.load(url);
	}
}
