

function showPopup(file,width,height,maxW,url)
{	file=file.src;	
	file=file.split("w__");
	file=file[1];
	
	newwidth=width;
	newheight=height;
	
	ratio=maxW/newwidth;
		
	if (newwidth>maxW)
	{	newwidth=maxW;
		newheight=height*ratio;
	}

	var x=window.open('', 'bigPrev', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width='+(newwidth)+',height='+(newheight));
	
	x.document.write("<html><head><title>Bild</title>");
	x.document.write('<style type="text/css">');
	x.document.write("html,body{margin:0;padding:0;overflow:hidden;}img{cursor:pointer;}");
	x.document.write("</style></head><body>");

	x.document.write('<img src="'+url+'index.php?rex_resize='+newwidth+'w__'+file+'" alt="" onclick="window.close();">');
	x.document.write("</body></html>");
	x.document.close();
	x.focus();
}	



function switchPic(width,height,file,displaywidth,popupwidth,url)
{	img=document.getElementById('prodimage').getElementsByTagName('IMG')[0];
	
	img.src='index.php?rex_resize='+displaywidth+'w__'+file;
	img.onclick=function() {	showPopup(img,width,height,popupwidth,url+"/");	};
}







$(document).ready(function()
{	$("*").unbind();
	

	$("a[@href$=.pdf]").addClass('pdf');
	$("a[@href$=.doc]").addClass('doc');
	$("a[@href$=.xls]").addClass('xls');
	$("a[@href$=.docx]").addClass('docx');
	$("a[@href^=mailto]").addClass('mailto');


	// Navi Links
	$(".extern").click(function ()
	{	this.setAttribute('target','_blank');
	});
	
	
	$("#basketform").submit(function ()
	{	var variants= new Array();
	
		 $("div.variations div").each(function (i)
		 {	variants[i]=this;
		 });
	
		
		if (!variants)
		{	/* No variants, add to basket */
			return true;
		}
		else
		{	/* Variants are there, check if they are checked.. */
			var checked=new Array();
			var labels=new Array();
			
			for (i=0;i<variants.length;i++)
			{	labels[i]=variants[i].getElementsByTagName('H3')[0];
				
				radios=variants[i].getElementsByTagName('INPUT');
				
				checked[i]=0;
				for (j=0;j<radios.length;j++)
				{	if (radios[j].checked==true)
					{	checked[i]=1;
					}
				}
			}
			/* Check if any of the sections don't have a selection */
			variantsNotSelected=1;
			for (i=0;i<checked.length;i++)
			{	if (checked[i]==0)
				{	variantsNotSelected=0;
					missing=labels[i].innerHTML;
				}
			}
			if (variantsNotSelected==0)
			{	alert('Bitte w'+unescape('%E4')+'hlen Sie "'+missing+'" aus.');
			}
			else
			{	return true;
			}
		}		
		return false;
	});
	
	
	
	$("div.variations input").click(function ()
	{	varbox=this.parentNode.parentNode.parentNode.parentNode; 
		productID=this.parentNode.parentNode.parentNode.parentNode.id;
		
		advAJAX.post({
			url: window.location.href,
			parameters : {
			"ajax" : "variants",
			"level" : this.parentNode.parentNode.parentNode.className, 
			"option" : this.parentNode.parentNode.parentNode.id,
			"value" : this.value,
			"product" : productID
			},
			onInitialization : function()
			{	/* Hiding layer */
				$('.proddetails').css('backgroundImage','url(files/_img/loader.gif)');
				$('.proddetails').css('backgroundRepeat','no-repeat');
				$('.proddetails').css('backgroundPosition','top right');				
			},
	
			onSuccess : function(obj) 
			{ 	// Display the new variants as quickly as possible
				varbox.innerHTML=obj.responseText;
				$.getScript("files/_js/init.js");
				
				// Recalculate price					
				advAJAX.post({
				url: window.location.href,
				parameters : {
				"ajax" : "recalc",
				"product" : productID
				},
				onSuccess : function(obj)
					{ 	if (document.getElementById('calcPrice'))
						{	document.getElementById('calcPrice').innerHTML=obj.responseText+" ";
						}
					}
				});
				
				
				
			},
			onFinalization : function()
			{	$('.proddetails').css('backgroundImage','');
			}
		});
	});

	
		
});


$(document).ready(function()
{	/* Search */
	var url = "";
	
	$('#rexsale_search_query').click(function()
	{	$('#rexsale_search_query').attr('value','');
	});
	
	$('#rexsale_search_query').autocomplete("index.php", {
		width: 170,
		max: 4,
		highlight: false,
		scroll: true,
		scrollHeight: 300,
		formatItem: function(data, i, n, value) {
			
			return "<p>"+value.split("~~~")[0]+"</p>";
		},
		formatResult: function(data, value) {
			x = value.split("~~~")[1];
			$("#rexsale_search_query").attr('rel',x);
			return value.split("~~~")[0];
		}
	}).result(function(event, data,formatted)
		{	if (formatted.split("~~~")[1]!=undefined)
			{	window.location.href = formatted.split("~~~")[1];
			}
		});
	
	$('#rexsale_search').submit(function()
	{	return false;
	});
	
	
	
});






$(document).ready(function()
{	
	$('.faqToggle .answer').css('display','none');	
	$('.faqToggle h3.question').click(function()
	{	$('.faqToggle').removeClass('faqopen');
			
		if ($(this).parent().children('.answer').css('display')=="none")
		{	$('.faqToggle .answer').css('display','none');	
			$(this).parent().addClass('faqopen');	
			$(this).parent().children('.answer').toggle('fast');
		}
		else
		{	$(this).parent().children('.answer').toggle('fast');
		}
	});



});




/* Spring galerie */

$(document).ready(function()
{	
	// hide the spring items
	$('.spring-galerie-preview div.springitem').css({display:"none"});

	// make the vorschau boxes
	$('.spring-galerie-preview').prepend('<div class="picture"></div><div class="text"><h3 class="title"></h3><p class="price"></p><p class="order"></p><div class="comment"></div></div>');
	
	// $('.spring-galerie-thumbs a').css({float:"left"});
	
	$('.spring-galerie-thumbs ul a').click(function(){
		$(this).blur();
	});



	$('.spring-galerie-thumbs ul a').mouseover(function(){
		className = $(this).attr('rel');
		$(this).addClass('selected');
		
		$('.spring-galerie-preview').attr('rel',className);
		
		img = $('.spring-galerie-preview .'+className+' img').attr('src');
		title = $('.spring-galerie-preview .'+className+' dt.name').html();
		price = $('.spring-galerie-preview .'+className+' dd.price').html();
		link = $('.spring-galerie-preview .'+className+' dd.link').html();
		comment = $('.spring-galerie-preview .'+className+' dd.comment').html();
		
		
		if (!title) {
			$('.spring-galerie-preview .text .title').css('display','none');
		} else {
			$('.spring-galerie-preview .text .title').css('display','block');
		}
		
		if (!price) {
			$('.spring-galerie-preview .text .price').css('display','none');
		} else {
			$('.spring-galerie-preview .text .price').css('display','block');
		}
		
		if (!link) {
			$('.spring-galerie-preview .text .order').css('display','none');
		} else {
			$('.spring-galerie-preview .text .order').css('display','block');
		}
		
		if (!comment) {
			$('.spring-galerie-preview .text .comment').css('display','none');
		} else {
			$('.spring-galerie-preview .text .comment').css('display','block');
		}
		
		$('.spring-galerie-preview .picture').html('<img src="'+img+'" />');
		
		
		
		
		$('.spring-galerie-preview .text .title').html(title);
		$('.spring-galerie-preview .text .price').html(price);
		$('.spring-galerie-preview .text .order').html(link);
		$('.spring-galerie-preview .text .comment').html(comment);
		
	});
	
	$('.spring-galerie-preview .picture').click(function(){
		
		
		par = $('.spring-galerie-preview').attr('rel');

		idx = 0;
		count = 0;
				
		$('.spring-galerie-thumbs ul img').each(function(i){
			if ($(this).parent().attr('rel')==par) {
				idx = count;
			}
			count++;
		});	
		
		if ((idx+1)==(count)) {
			next = 0;
		}
		else {
			next = idx+1;
		}

		$('.spring-galerie-thumbs ul img:eq('+next+')').parent().trigger('mouseover');
		rexgal_carousel.scroll(next);		
		
		
	});
	
	
	// click the first link
	$('.spring-galerie-thumbs ul a:eq(0)').trigger('mouseover');
	
});


$(document).ready(function()
{	
	$('a[rel="rxs-postage"]').click(function(){
		url = $(this).attr('href');
		var x = window.open(url+'&popup=1','popup','height=300,width=600,scrollbars=1');
		x.focus();
		return false;
	});
});

