$(function(){
	$("h1.js_flashfont,.dinlight_1").each(function(){
		var d_text = $(this).text();
		if(d_text != "")
		{
			var flashvars = {overskrift:d_text};
			var params = {wmode:"transparent"};
			var attributes = {};
			var trueelement;
			if($(this).get(0).nodeName.toLowerCase() == "h1")
			{
				trueelement = this;
			}
			else
			{
				trueelement = $("<h1></h1>");
				$(this).html(trueelement);
			}
			if($(trueelement).attr("id") !== "")
			{
				element_id = $(this).attr("id");
			}
			else
			{
				element_id = "h1_" + Math.floor(Math.random()*10000);
				$(trueelement).attr("id",element_id);
			}
			swfobject.embedSWF("/flash/dinlightembedded.swf", element_id, "250", "30", "9.0.0",false, flashvars, params, attributes);
		}
	});
	$("h1.js_flashfont_widecol,.dinlight_wide").each(function(){
		var d_text = $(this).text();
		if(d_text != "")
		{
			var flashvars = {overskrift:d_text};
			var params = {wmode:"transparent"};
			var attributes = {};
			var trueelement;
			if($(this).get(0).nodeName.toLowerCase() == "h1")
			{
				trueelement = this;
			}
			else
			{
				trueelement = $("<h1></h1>");
				$(this).html(trueelement);
			}
			if($(trueelement).attr("id") !== "")
			{
				element_id = $(this).attr("id");
			}
			else
			{
				element_id = "h1_" + Math.floor(Math.random()*10000);
				$(trueelement).attr("id",element_id);
			}
			swfobject.embedSWF("/flash/dinlightembedded_wide.swf", element_id, "485", "30", "9.0.0",false, flashvars, params, attributes);
		}
	});
	$('h1.js_flashfont_o').each(function(){
		var d_text = $(this).text();
		if(d_text != "")
		{
			var flashvars = {overskrift:d_text};
			var params = {wmode:"transparent"};
			var attributes = {};
			var trueelement;
			if($(this).get(0).nodeName.toLowerCase() == "h1")
			{
				trueelement = this;
			}
			else
			{
				trueelement = $("<h1></h1>");
				$(this).html(trueelement);
			}
			if($(trueelement).attr("id") !== "")
			{
				element_id = $(this).attr("id");
			}
			else
			{
				element_id = "h1_" + Math.floor(Math.random()*10000);
				$(trueelement).attr("id",element_id);
			}
			swfobject.embedSWF("/flash/dinlightembedded_o_special.swf", element_id, "250", "30", "9.0.0",false, flashvars, params, attributes);
		}
	});
	$("h1.js_flashfont_2rows,.dinlight_2").each(function(){
		var d_text = $(this).text();
		if(d_text != "")
		{
			var flashvars = {overskrift:d_text};
			var params = {wmode:"transparent"};
			var attributes = {};
			var trueelement;
			if($(this).get(0).nodeName.toLowerCase() == "h1")
			{
				trueelement = this;
			}
			else
			{
				trueelement = $("<h1></h1>");
				$(this).html(trueelement);
			}
			if($(trueelement).attr("id") !== "")
			{
				element_id = $(this).attr("id");
			}
			else
			{
				element_id = "h1_" + Math.floor(Math.random()*10000);
				$(trueelement).attr("id",element_id);
			}
			swfobject.embedSWF("/flash/dinlightembedded_2lines.swf", element_id, "250", "50", "9.0.0",false, flashvars, params, attributes);
		}
	});
	$("h1.js_flashfont_3rows,.dinlight_3").each(function(){
		var d_text = $(this).text();
		if(d_text != "")
		{
			var flashvars = {overskrift:d_text};
			var params = {wmode:"transparent"};
			var attributes = {};
			var trueelement;
			if($(this).get(0).nodeName.toLowerCase() == "h1")
			{
				trueelement = this;
			}
			else
			{
				trueelement = $("<h1></h1>");
				$(this).html(trueelement);
			}
			if($(trueelement).attr("id") !== "")
			{
				element_id = $(this).attr("id");
			}
			else
			{
				element_id = "h1_" + Math.floor(Math.random()*10000);
				$(trueelement).attr("id",element_id);
			}
			swfobject.embedSWF("/flash/dinlightembedded_3lines.swf", element_id, "250", "72", "9.0.0",false, flashvars, params, attributes);
		}
	});
	$("h1.js_flashfont_green,.dinlight_green").each(function(){
		var d_text = $(this).text();
		if(d_text != "")
		{
			var flashvars = {overskrift:d_text};
			var params = {wmode:"transparent"};
			var attributes = {};
			var trueelement;
			if($(this).get(0).nodeName.toLowerCase() == "h1")
			{
				trueelement = this;
			}
			else
			{
				trueelement = $("<h1></h1>");
				$(this).html(trueelement);
			}
			if($(trueelement).attr("id") !== "")
			{
				element_id = $(this).attr("id");
			}
			else
			{
				element_id = "h1_" + Math.floor(Math.random()*10000);
				$(trueelement).attr("id",element_id);
			}
			swfobject.embedSWF("/flash/dinlightembedded_green.swf", element_id, "160", "18", "9.0.0",false, flashvars, params, attributes);
		}
	});
	
	/*** category search ***/
	$("div.category h1").click(function(){
		//Target the div containing the subcategories
		$(this).next().next().slideToggle("fast");
		});
	
	/*** replace fonts from the wysiwyg ***/
	$("font[size=6]").each(function(){
		var flashvars = {overskrift:$(this).text()};
		var params = {wmode:"transparent"};
		var attributes = {};
		if($(this).attr("id") !== "")
		{
			element_id = $(this).attr("id");
		}
		else
		{
			element_id = "h1_" + Math.floor(Math.random()*10000);
			$(this).attr("id",element_id);
		}
		swfobject.embedSWF("/flash/dinlightembedded.swf", element_id, "250", "30", "9.0.0",false, flashvars, params, attributes);
	});
	$("img.js_product_thumb").click(function(){
		var imgsrc = $(this).attr("rel");
		$("img.js_bigpic").fadeOut("fast",function(){
			$("img.js_bigpic").attr("src","/image.php?image=/resources/products/picts/" + imgsrc + "&w=522&h=522");
			$("img.js_bigpic").load(function(){
				$(this).fadeIn("fast");
				});
			});
		});
	//Centers product images in their containing div (doesnt work in IE, was removed from a design standpoint)
	$("div.product_picture").each(function(){
		$(this).find("img").each(function(){
			$(this).load(function(){
			var totalHeight = parseInt($(this).parents("div.product_picture").eq(0).height(),10);
			var imgHeight = parseInt($(this).height(),10);
			var imgOffset = (totalHeight-imgHeight);
			$(this).css({position:"relative",top:imgOffset});
			//$(this).after("<span>" + imgOffset + "</span>");
			});
			
		});
		/*** IE doesnt fire load event if the image is cached ***/
		$(this).find("img[complete=complete]").each(function(){
			var totalHeight = parseInt($(this).parents("div.product_picture").eq(0).height(),10);
			var imgHeight = parseInt($(this).height(),10);
			var imgOffset = (totalHeight-imgHeight);
			$(this).css({position:"relative",top:imgOffset});
			//$(this).after("<span>" + imgOffset + "</span>");			
		});
	});
});



function fakeProcess(processDiv)
{
	$("body").append(processDiv);
	$(processDiv).children("object").before("<div class='spacer22'></div>");
	$(processDiv).children("object").attr("data","");
	$(processDiv).children("object").attr("data","/flash/dinlightembedded.swf");
	var divpos = $("iframe").eq(0).position();
	var iframewidth = parseInt($("iframe").eq(0).width(),10);
	var divwidth = parseInt($(processDiv).width(),10);
	$("iframe").eq(0).css("width",iframewidth-divwidth);
	$(processDiv).css({position:"absolute",top:divpos.top,left:parseInt(divpos.left,10)+iframewidth-divwidth});
}

function returnToNormal()
{
	var iframewidth = parseInt($("iframe").eq(0).width(),10);
	var divwidth = parseInt($("#order_process_div").width(),10);
	$("iframe").eq(0).css("width",iframewidth+divwidth);
	$("#order_process_div");
	$("#order_process_div").remove();
}