$(document).ready(function(){  

if (typeof (prod_selector_status) == "undefined")
{	
	// Product Selector initialisieren
	//$("#prodCat0").fadeIn("fast");
	prevProdCat = "#"+$(".productsContainer:first").attr("id");
	productListAppend = "<ul>"+$(prevProdCat+" .productListPopup").html()+"</ul>";
	$("#prodSelector .contentPadding").html(productListAppend); 

	$(prevProdCat).fadeIn("fast");
	
	$(".popupClose").click(function(){
		$(this).parent().fadeOut("fast");
	});
	
	
	$("#catChange").click(function(){
		// Auwahl aufheben
		$(".productsContainer input").removeAttr("checked"); 
		if ($("#catSelector").is(':hidden'))
		{
			$("#prodSelector").css({ display: 'none' });
			$("#catSelector").fadeIn("fast");
		}
		else
		{
			$("#catSelector").fadeOut("fast");
		}
	});
	
	$(".linkShowProducts").click(function(){
		$("#catChange").click();
		$("#catName").html($(this).html());
		if (prevProdCat != 0)
		{
			$(prevProdCat).css({ display: 'none' });
		}
		prevProdCat = "#prodCat"+$(this).attr('rel');
		productListAppend = "<ul>"+$("#prodCat"+$(this).attr('rel')+" .productListPopup").html()+"</ul>";
		$("#prodSelector .contentPadding").html(productListAppend); 
		$("#prodCat"+$(this).attr('rel')).fadeIn("fast");
		

	});


	
	
	$(".linkShowPopup").click(function(){
		if ($("#prodSelector").is(':hidden'))
		{
			// Inhalt setzen
			$("#catSelector").css({ display: 'none' });
			$("#prodSelector").fadeIn("fast");
			$("#prodSelector .contentPadding .insert_product").click(function(){
				prod_desc = $(this).html();
				$(prevProdCat+" .product_more_description").html(prod_desc+"<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
				$(prevProdCat+" input.product_more").attr('value', $(this).attr('rel'));
				$(prevProdCat+" input.product_more").attr('checked', true);
				$("#prodSelector").fadeOut("fast");
			});		
		}
		else
		{
			$("#prodSelector").fadeOut("fast");
		}
	});

}
// Script already executed
prod_selector_status = true;	
}); 
