// JavaScript Document
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function OpenPopup(sPicURL)
{    window.open("http://www.ggweb.nl/popup.php?"+sPicURL, "Vergroting", "resizable=0,HEIGHT=220,WIDTH=220");
} 
function changeImage(Obj)
{
	if( document.getElementById('big') ) 
	{
		document.getElementById('big').src = Obj.src;
	}
}
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function goToPage(page)
{
	window.location.href = page;
}

jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}
function validateCI()
{
	if (document.checkout.shipping_first_name.value == '' || document.checkout.shipping_last_name.value == '' || document.checkout.shipping_address.value == '' || document.checkout.shipping_zip.value == '' || document.checkout.shipping_city.value == '' || document.checkout.email_address.value == ''){
	
		jQuery('#form-error').show();
  		return false;
	}else{
		$('#checkout').submit();
		return true;
	}

}
$(document).ready(function($){

	$('#content-left-sfeer').cycle({ 
    fx:    'fade', 
    timeout:  4000,
    speed: 2000 
	});

	/*var activeid = '';
	i = 1;
	$('.thumbnail img').each( function (e) { 
		if(i==1) activeid = jQuery(this).attr('src');
	
		itemval = jQuery(this).attr('src');
		file = retrieveScreenshot(itemval, 'medium');
		jQuery("<img>").attr("src", file);
		i++;
	});

	$('.thumbnail img').hover( function (e) { 
		curid = jQuery(this).attr("src");
		if(activeid==curid) return false;
		activeid = curid;

		itemval = jQuery(this).attr('src');
		mediumimage = retrieveScreenshot(itemval, 'medium');
		popupimage = retrieveScreenshot(itemval, 'popup');
		
		if(file){
			jQuery(".screenshot a.photobox").attr('href', popupimage);
			jQuery("#big-image").fadeOut(400,function() {
			jQuery(this).attr('src', mediumimage).fadeIn(600);});
		}
	});*/
	
	jQuery("a.photobox").fancybox({
		'zoomSpeedIn':	0, 
		'zoomSpeedOut':	0,
		'overlayShow': true,
		'overlayOpacity': 0.7
	});    
	jQuery("a.youtube").fancybox({
		'zoomSpeedIn':	100, 
		'zoomSpeedOut':	100,
		'frameWidth': 425,
		'frameHeight': 344,
		'overlayShow': true,
		'overlayOpacity': 0.6
	});    
	
	// form date option
	$('#uitvoerdatum').change(function() {
    	var test = document.getElementById('uitvoerdatum').selectedIndex;
    	if (test == 3){
   			$('#datum').show();
   		} else{
   			$('#datum').hide();
   		}
    
	  });


	// slideshow
	$('#sfeer').cycle({ 
	    fx:    'scrollUp', 
	    timeout:  3500,
	    speed: 900,
	   	pager:  '#slider-nav',
	   	before: update_sfeer_description,
	    pauseOnPagerHover: 1
	});
	function update_sfeer_description(curr,next,opts) {
   		//var index = opts.currSlide;
   		//alert(opts.currSlide +'-'+ opts.nextSlide);
   		if(opts.currSlide != opts.nextSlide){
			$('#shoptext').cycle(opts.nextSlide);
		}
	}
	$('#shoptext').cycle({ 
	    fx:    'scrollLeft', 
	    timeout:  0,
	    speed: 900 
	});
	
	//show banks
	$('#virtuelekassa').click(function(){
	$('#loadingbanks').show('fast');
	$('select#banks').hide('fast');

		$.ajax({
    		url: "/ideal/virtuelekassa.php"
    		, type: "POST"
    		, contentType:"text/html"
            , processData: false
            , beforeSend: xmlStart
			, success: xmlSuccess
			, error: xmlError
      		});
      		
      		
	});
		$('#vooruit').click(function(){
		$('#ideal').hide('fast');
		$('select#banks').hide('fast');
	});
		$('#rembours').click(function(){
		$('#ideal').hide('fast');
		$('select#banks').hide('fast');
	});
	
	

	
	//Start accordion menu
	
	
  $('.navshop ul').hide();
  jQuery('.navshop li a').hover(
    function() {
      var checkElement = $(this).next();
      var prevElement = $(this).prev();
      if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
        return true;
        }
        
      if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
        $('.navshop ul:visible').slideUp('normal');
        checkElement.slideDown('normal');
        return true;
        }
      }
    );
    //Ruud start uitklappen active ul
	if(jQuery('.navshop li a').hasClass('active')){
	var checkElement = $('.navshop li a.active').next();
	if((checkElement.is('ul'))) {
        checkElement.slideDown('normal');
        return true;
        }
	}
	//Eind accordion menu
	
	jQuery(':radio').change(function(){
		var selection = document.checkout.paymethod;
		for (i=0; i<selection.length; i++){
			if (selection[i].checked == true){
  				//alert(selection[i].value);
  				 if(selection[i].value == "IDEAL" || selection[i].value == "VISA" || selection[i].value == "MASTERCARD" || selection[i].value == "MISTERCASH"){
  				 	jQuery('#cartthrobpaymethod').html("<input type=\"hidden\" name=\"gateway\" value=\"HSYqA0cCwDwGWaApu1lAO72b0a37K8dFHFGNTzqupN8=\" id=\"multisafepay\"/>");
  				 }
  				 if(selection[i].value == "VOORUIT"){
  				 	jQuery('#cartthrobpaymethod').html("<input type=\"hidden\" name=\"gateway\" value=\"p604WNIQ+SxWe5knD/gQoz1hE3JfluyKokzOO5N6ids=\" id=\"vooruit\"/>");
  				 }
  				 if(selection[i].value == "PAYPAL"){
  				 	jQuery('#cartthrobpaymethod').html("<input type=\"hidden\" name=\"gateway\" value=\"uv+oFKc+antZH3Olwy64iH8cPiLNmtIMTAG5L2NyY5Y=\">");
  				 }
  			}
		}
	});
		
});

function xmlStart( xhrInstance ){
	//$( "#ideal" ).html( "Een ogenblik geduld, de banken lijst wordt opgehaald." );

}

function xmlError( xhrInstance, message, optional ){
	$("#ideal").html("<ul><li>There was an error loading the document.</li></ul>"+" - "+xhrInstance+" - "+message+" - "+optional);
}

function xmlSuccess( data, status ){
$('#loadingbanks').hide('fast');
	$('#ideal').show('fast');
	$('#ideal').append(data);
	
	//parseXML( data );
}
function parseXML( xml ){
	var bank = "bank";
	var bankname = "bankname";
	var bankid = "bankid";
	var content = "<select name='banks' id='banks' style='width:200px;'>";
	$( xml ).find( bank ).each(function(){
		title = $( this ).find( bankname ).text();
		id = $( this ).find( bankid ).text();
		content += "<option value="+id+">"+title+"</option>";
	});

	content += "</select>";
	$('#loadingbanks').hide('fast');
	$('#ideal').show('fast');
	$('#ideal').append(content);
	
}


function FillFields(box) {
	if(box.checked == false) { 
		document.checkout.first_name.value  = '';
		document.checkout.last_name.value  = '';
		document.checkout.address.value  = '';
		document.checkout.zip.value = '';
		document.checkout.city.value  = '';
		return; 
		
	}
	document.checkout.first_name.value  = document.checkout.shipping_first_name.value;
	document.checkout.last_name.value  = document.checkout.shipping_last_name.value;
	document.checkout.address.value  = document.checkout.shipping_address.value;
	document.checkout.zip.value = document.checkout.shipping_zip.value;
	document.checkout.city.value  = document.checkout.shipping_city.value;
	var check = document.getElementsByName("factuurgegevens");
	for(i=0;i<check.length;i++){
		if(check[i].checked){
			$('#informatie').show('fast');
		}else{
			$('#informatie').hide('fast');
		}
	}
}

function sleep(milliseconds) {
  var start = new Date().getTime();
  for (var i = 0; i < 1e7; i++) {
    if ((new Date().getTime() - start) > milliseconds){
      break;
    }
  }
}



function switchLanguage(lang) {
    u = location.href.split('/');
    u[5] = lang;
    location.href = u.join('/');
}



function changeLocation(menuObj)
{
   var i = menuObj.selectedIndex;

   if(i >= 0)
   {
      window.location = menuObj.options[i].value;
   }
}
