function exchange(id)	{
	$("#"+id).attr('old_src', $("#"+id).attr('src'));
	$("#"+id).attr('src', $("#mainimg").attr('src').replace('medium/','thumb/'));
	
	$("#mainimg").attr('src', $("#"+id).attr('old_src').replace('thumb/','medium/'));
	$("#maina").attr('href', $("#"+id).attr('old_src').replace('thumb/',''));
}

function isValidEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

function fleXcrollTo(id,x,y,relative) {
	var scrollDiv = document.getElementById(id);
	if (scrollDiv == null) return;
	if(scrollDiv.contentScroll) scrollDiv.contentScroll(x,y,relative);
}

function preload_images() {
	for (i = 1; i <= 10; i++) {
		if ($("#r" + i) != undefined) {
			preload[i] = new Image();
			preload[i].src = $("#r" + i).src.replace(".gif", "_o.gif");
		}
	}
}

function mover(id) {
	if ($("#"+id).attr('old_src') == null) {
		$("#"+id).attr('old_src', $("#"+id).attr('src'));
	}
	
	if( $("#"+id).attr('src').indexOf('_o.gif') == -1 ) $("#"+id).attr('src', $("#"+id).attr('old_src').replace(".gif", "_o.gif"));
}
function mout(id)	{
	$("#"+id).attr('src', $("#"+id).attr('old_src'));
}

function fader(fotos, photoview0, photoview1, photolabel) {	
	this.fotos = fotos;
	this.photoview0 = photoview0;
	this.photoview1 = photoview1;
	this.photolabel = photolabel;
	
	// Set fadeSpeed (number of milliseconds to wait between 5% changes in opacity)
	var fadeSpeed = (arguments.length > 4 && !isNaN(arguments[4]) ? arguments[4] : 50);
	
	var fadeT;
	var fadeOpacity = 0;
	var preloadLength = fotos.length
	
	var preloadpics = new Array();
	var j = preloadLength - 1;
	for (var i = 0; i < preloadLength; i++) {
		if (i > j) break;
		preloadpics[i] = new Image();
		preloadpics[i].src = fotos[i][0];
		preloadpics[j] = new Image();
		preloadpics[j].src = fotos[j][0];
		j--;
	
	}
	
	var cur_foto = 0;
	var tot_fotos = fotos.length - 1;
	var to;
	
	this.scroll_photo = scroll_photo;
	this.scroll_photo2 = scroll_photo2;
	this.fadeIn = fadeIn;
	
	function scroll_photo(i) {
		if (fadeOpacity > 0) return;
		if (to) clearTimeout(to);
		to = setTimeout(function() { scroll_photo2(i); }, 50);
	}
	
	function scroll_photo2(i) {
		cur_foto = cur_foto + i;
		if (cur_foto < 0) cur_foto = tot_fotos;
		if (cur_foto > tot_fotos) cur_foto = 0;
	
		document.getElementById(photoview1).innerHTML = '<img src="' + fotos[cur_foto][0] + '" width="' + fotos[cur_foto][1] + '" height="' + fotos[cur_foto][2] + '" border="0" class="limg">';
		// document.getElementById(photolabel).innerHTML = fotos[cur_foto][3];
	
		fadeT = setTimeout(function() { fadeIn(); }, fadeSpeed);
	}
	
	function fadeIn() {
		fadeOpacity = fadeOpacity + 5;
		var fade_top_object = document.getElementById(photoview1);
		var fade_bottom_object = document.getElementById(photoview0);
	
		if (fadeOpacity <= 100) {
			var tmpOpacity = (fadeOpacity == 100 ? 99.999 : fadeOpacity);
			if (fade_top_object.filters) fade_top_object.filters.alpha.opacity = tmpOpacity;
			if (fade_top_object.style.MozOpacity) fade_top_object.style.MozOpacity = tmpOpacity / 100;
			if (fade_top_object.style.opacity) fade_top_object.style.opacity = tmpOpacity / 100;
			if (fade_top_object.style.KHTMLOpacity) fade_top_object.style.KHTMLOpacity = tmpOpacity / 100;
			if (fadeOpacity == 100)	fade_bottom_object.innerHTML = fade_top_object.innerHTML;
			fadeT = setTimeout(function() { fadeIn(); }, fadeSpeed);
		} else {
			if (fade_top_object.filters) fade_top_object.filters.alpha.opacity = 0;
			if (fade_top_object.style.MozOpacity) fade_top_object.style.MozOpacity =0;
			if (fade_top_object.style.opacity) fade_top_object.style.opacity = 0;
			if (fade_top_object.style.KHTMLOpacity) fade_top_object.style.KHTMLOpacity = 0;
			fadeOpacity = 0;
		}
	}
}

/* depends on settings in index */
function sfaq(faq_id)	{
	jQuery.get("/common/ajax.php", {id:faq_id, type: "faq",lang: baunatLanguage}, function(data){
		$("#intxt").html(data);
		CSBfleXcroll('txt');
		fleXcrollTo("txt","0px","0px",false);
	});
}
function stxt(where, id)	{
	jQuery.get("/common/ajax.php", {id:id, type: "txt",lang: baunatLanguage}, function(data){
		$("#"+where).html(data);
	});
}
function s2f()	{
	var email1 = $("#s2femail").val();
	var email2 = $("#s2fkemail").val();
	$('#error_s2fdata').html('');
	$('#error_s2ffriend').html('');
	$('#s2femail').removeClass('input_bestelform_error');
	$('#s2femail').addClass('input_bestelform');
	$('#s2fkemail').removeClass('input_bestelform_error');
	$('#s2fkemail').addClass('input_bestelform');
	if(!isValidEmail(email1) || !isValidEmail(email2)){
		if(!isValidEmail(email1)){
			$('#error_s2fdata').html(baunatMailerror);
			$('#s2femail').removeClass('input_bestelform');
			$('#s2femail').addClass('input_bestelform_error');
		}
		if(!isValidEmail(email2)){
			$('#error_s2ffriend').html(baunatMailerror);
			$('#s2fkemail').removeClass('input_bestelform');
			$('#s2fkemail').addClass('input_bestelform_error');
		}
	}else{
	jQuery.get("/common/ajax.php", {
			naam:$("#s2fnaam").val(),voornaam:$("#s2fvoornaam").val(),email:$("#s2femail").val(),
			knaam:$("#s2fknaam").val(),kvoornaam:$("#s2fkvoornaam").val(),kemail:$("#s2fkemail").val(),
			url:$("#s2furl").val(), type: "s2f",lang: baunatLanguage
		}, function(data){
		$("#overlayHtml").html(data);
	});
		}
}
function nb()	{
	jQuery.get("/common/ajax.php", {
			naam:$("#nbnaam").val(),voornaam:$("#nbvoornaam").val(),email:$("#nbemail").val(),
			type: "nb",lang: baunatLanguage
		}, function(data){
		$("#subscribeok").toggle();
		$("#subscribenok").toggle();		
	});
}

function checknb()	{
	if(document.getElementById('nbemail').value =='' || document.getElementById('nbemail').value.indexOf('@') == -1 || document.getElementById('nbnaam').value =='' || document.getElementById('nbvoornaam').value =='' ) return(false);
	else return(true);
}

$(document).ready(function() {
	$('.winkelmand_verwijder').click(function(){
		var articleid = $(this).attr('id');
		$.post("/common/winkelmand-verwijder-ajax.php", 
	        	{ 
	        		id: articleid,
	        		lang: baunatLanguage
	        	},
	  			function(data){
	  				$('#winkelmand').html(data);
	  				$("#tr_"+articleid).hide();
	  		});
	});
	$('.order').click(function(){
		$('#maat_error').hide();
		var articleid = $(this).attr('articleid');
		var size = -1;
		if($('#maat').length > 0){
			size = $('#maat').val();
		}
		if(size == '0'){
			$('#maat_error').show();
		}else {
			$.post("/common/winkelmand-ajax.php", 
	        	{ 
	        		id: articleid,
	        		size: size,
	        		lang: baunatLanguage
	        	},
	  			function(data){
	  				$('#winkelmand').append(data);
					setOrder(); 
					DoShowPopup('400px','210px');
	  		});
			// alert('Product toegevoegd aan uw bestelling. Klik op "Aankoop uitvoeren" om over te gaan tot de aankoop.');
		}
	});
	$('#back2form').click(function() {
		//console.log('clicked');
		//history.back();
		location.href='?salesform=1';
	});
	$('#aankoop_uitvoeren_2').click(function() {
		$('#bestelformulier_2').submit();
	});
	$('#aankoop_uitvoeren').click(function() {
		$('#bestelformulier').submit();
	});
	$('#soortgelijke_producten').click(function() {
		$('#soortgelijkeproducten_formulier').submit();
	});
	$('#next').click(function() {
		$('#soortgelijkeproducten_next').submit();
	});
	$('#previous').click(function() {
		$('#soortgelijkeproducten_previous').submit();
	});
	$('#betaalwijze_ogone').click(function() {
		$('#ogone_clausule').show();
	});
	$('#betaalwijze_wire').click(function() {
		$('#ogone_clausule').hide();
	});
	$('.commitments-title').click(function() {
		//$('.commitments').hide();
		var id = $(this).attr('commitment_id');
		$('.commitments').each(function(){
			if($(this).attr('id') == id) {
				$(this).toggle();
			} else {
				$(this).hide()
			}
		});
	});
});
function setS2f()	{
	$('#divPopup').html('');
	$.get("/content/overlay.php" , 
	       	{ 
				strla: baunatLanguage,
				ct:'s2f',
				detail:$('#theOrderId').attr('articleid'),
				time:baunatTimer
	        	},
	  			function(data){
	  				$('#divPopup').html(data);
	  		});
}
function setExpl()	{
	$('#divPopup').html('');
	$.get("/content/overlay.php", 
	       	{ 
				strla: baunatLanguage,
				ct:'expl',
				time:baunatTimer
	        	},
	  			function(data){
	  				$('#divPopup').html(data);
	  		});
}
function setMap()	{
	$('#divPopup').html('');
	$.get("/content/overlay.php", 
	       	{ 
				strla: baunatLanguage,
				ct:'roadmap',
				time:baunatTimer
	        	},
	  			function(data){
	  				$('#divPopup').html(data);
	  		});
}
function setOrder()	{
	$('#divPopup').html('');
	$.get("/content/overlay.php", 
	       	{ 
				strla: baunatLanguage,
				ct:'productadded',
				time:baunatTimer
	        	},
	  			function(data){
	  				$('#divPopup').html(data);
	  		});
}

function setRealsize()	{
	$('#divPopup').html('');
	$.get("/content/overlay.php", 
	       	{ 
				strla: baunatLanguage,
				ct:'realsize',
				time:baunatTimer
	        	},
	  			function(data){
	  				$('#divPopup').html(data);
	  		});
}

function setRealEarsize()	{
	$('#divPopup').html('');
	$.get("/content/overlay.php", 
	       	{ 
				strla: baunatLanguage,
				ct:'realearsize',
				time:baunatTimer
	        	},
	  			function(data){
	  				$('#divPopup').html(data);
	  		});
}

function waitscroll() {
	dscroll.style.top=(tscroll-1) + "px";
	timerID = window.setTimeout("startscroll()", 25);
}

function stopscroll() {
	window.clearTimeout(timerID);
}

function startscroll() {
	dscroll=document.getElementById("scrollcont");
	hscroll=dscroll.offsetHeight;
	tscroll=dscroll.offsetTop;
	if (tscroll>0-((content_length - 1) * 42)) {
		if (tscroll % 42 == 0) {
			timerID = window.setTimeout("waitscroll()", 3000);
		} else {
			dscroll.style.top=(tscroll-1) + "px";
			timerID = window.setTimeout("startscroll()", 25);
		}
	} else {
		dscroll.style.top="0px";
		timerID = window.setTimeout("startscroll()", 0)	;
	}
}