Cufon.set().replace('#content h1');

	var map;
    var gdir;
    var geocoder = null;
    var addressMarker;
	
function setVerzend(verzend){
			if(verzend){
				location.href = 'winkelmandje?verzend=ja';
			}else{
				location.href = 'winkelmandje?verzend=nee';
			}	
		} 

$(document).ready(function(){
	
	$('#akkoord').click(function(){
		if($(this).is(':checked')){
			$('#gotostap2').removeClass('volgendestap_off');
			$('#gotostap2').addClass('volgendestap');
			$('#gotostap2').text('Verder met bestellen - ga naar stap 2');
			$('#gotostap2').attr({href: $('#gotostap2').attr('hrefon')});
			$('#divsaver').load('modules/ajax.load.shop.savestep1.php?akkoord=ja');		
		}else{
			$('#gotostap2').removeClass('volgendestap');
			$('#gotostap2').addClass('volgendestap_off');
			$('#gotostap2').text('Accepteer eerst de voorwaarden!');
			$('#gotostap2').attr({href: $('#gotostap2').attr('hrefoff')});
			$('#divsaver').load('modules/ajax.load.shop.savestep1.php?akkoord=nee');	
		}		
	});
	
	$('#homeslide').cycle();
	
	$('#faq').change(function(){
		$('#accordion').load('modules/faqlist.inc.php?id='+$(this).val(), false, function(){
			$('#accordion').accordion({ 
				collapsible: true,
				active: false,
				autoHeight: false,
				clearStyle: true
			});			
		});
	});
	
	$('#prodslideshow').cycle({
		pager:  '#prodpager', 
   		pagerAnchorBuilder: function(idx, slide) { 
        	return '#prodpager a:eq(' + idx + ')'; 
    	} 		
	});
	
	$("a.fancybox").fancybox();
	
/*
	$("a.fancyframe").fancybox({
		callbackOnClose: function(){
			window.location.reload();
		},
		frameHeight: 112,
		frameWidth: 452,
		hideOnContentClick: false
	});
*/

	$('a.fancyframe').click(function(){
		//alert('Artikel word toegevoegd');
		url = $(this).attr('href');
		$.ajax({
			type: 'get',
			url: url,
			success: function(data){
				$('#addtocart').html(data);
			}
		});
		$('#aantalartikelen').load('includes/winkelwagenaantal.php?aantal=aantal');
		$('#totaalbedrag').load('includes/winkelwagenaantal.php?aantal=prijs');
		return false;
		
	});

	$("a.cartfoto").fancybox();
	
	$("form.shopper").submit(function(){
		
		tb_show('Toevoegen', $(this).attr('action')
								+'&aantal='+ $('#aantal').val()
								+'&versieid='+ $('#versieid').val() 
								+'&productid='+ $('#productid').val() 
								+'&placeValuesBeforeTB_=savedValues&height=184&width=463&modal=true', ''); 
								
		$('#mand1').load('includes/winkelwagenaantal.php?aantal=aantal');
		$('#mand2').load('includes/winkelwagenaantal.php?aantal=prijs');
	
	return false;
		
	});
	
	if($('#heightcheck').height() < ($(window).height()-4)){
		$('#container').height(($(window).height()-4));
	}
	if ($('#map_canvas').length > 0) {
		initialize();
		$('#route').submit(function(){
			//var adress = this.straat.value + ' ' + this.huisnummer.value + ', ' + this.plaats.value + ', nederland';
			var adress = $(this).find('input[name="straat"]').val() + ' ' + $(this).find('input[name="huisnummer"]').val() + ', ' + $(this).find('input[name="plaats"]').val() + ', nederland';
			setDirections(adress, 'Postwagenstraat 8,6219 NP, Maastricht', 'nl'); 
			return false;
		});
	}
});

$(window).resize(function(){
	if($('#heightcheck').height() < ($(window).height()-4)){
		$('#container').height(($(window).height()-4));
	}
});

 
    function initialize() {
      if (GBrowserIsCompatible()) {      
        map = new GMap2(document.getElementById("map_canvas"));
		map.addControl(new GSmallMapControl());
        gdir = new GDirections(map, document.getElementById("directions"));
        GEvent.addListener(gdir, "addoverlay", onGDirectionsLoad);
        GEvent.addListener(gdir, "error", handleErrors);
		map.setCenter(new GLatLng(50.867506, 5.672789), 14);
		var point = new GLatLng(50.867506, 5.672789);
		map.addOverlay(new GMarker(point));
      }
    }
	
    function setDirections(fromAddress, toAddress, locale) {
      gdir.load("from: " + fromAddress + " to: " + toAddress,
                { "locale": locale });
    }
	
	function onGDirectionsLoad() {
		if($('#heightcheck').height() < ($(window).height()-4)){
			$('#container').height(($(window).height()-4));
		}
	}
 
    function handleErrors(){
   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
     alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
     alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
     alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);
   else if (gdir.getStatus().code == G_GEO_BAD_KEY)
     alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);
   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
     alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
   else alert("An unknown error occurred.");
    }


