function wc()
{
	if(window.console)
	{
		for(var i = 0; i < arguments.length; i++)
		{
			window.console.log(arguments[i]);
		}
	}
}

// ----------------------------------------------------------------------------

function populateFormWithCendris(form)
{
	//var pc = '1095KK', nr = '27';
	
	var pc = $("input[name=postcode]", form).val();
	
	//wc(pc, nr);
	
	if(pc == "")
	{
		// doe alleen wat als pc en nr beide een waarde hebben
	}
	else
	{
		$.getJSON(
		
			'http://www.wilgenhaege.nl/js/cendris/getaddress.php',
			
			{ pc: pc },
			
			function(data)
			{
				wc(data.length);
				
				if(data.length)
				{
					data = data[0];
					
					$("input[name=straat]").val(data.straatnaam);
					$("input[name=plaats]").val(data.woonplaats);
				}
			}
		);
	}
}

// ----------------------------------------------------------------------------

$(document).ready(function()
{
	/* 
		
	*/		
	$('input[name=postcode], input[name=huisnummer]').change(function(){
	
		populateFormWithCendris($(this).parents('form'));
		
	});
	
	/* 
		
	*/
	$('body').delegate('a[href$=.pdf], a[href$=.doc]', 'click', function(event) {
	
		wc(this.href);
		
		if(_gaq)
		{
			_gaq.push(['_trackPageview', this.href]);
		}
		
	});	
	
	$('body').delegate('a._blank', 'click', function(event) {
			
		// wc(this, event);
		
		if(this.href) window.open(this.href);
		
		return false;
	});
	
	/* 
		append navigator elements
	*/
	$('.slideshow .items').css({ width: 2700 }); ///.append('<div class="navi"></div>');
	
	$('.slideshow').before('<a class="slideshow-nav nextSlide"></a><a class="slideshow-nav prevSlide"></a>');
	
	
	/* 
		initialize scrollable and return the programming API 
	*/
	var slideshow = $('.slideshow').css({ height: 300 }).scrollable({ 
	
		items: '.items',
		clickable: false ,
		size: 1,
		easing: 'custom',
		next: '.nextSlide',
		prev: '.prevSlide'
		//api: true
	
	}).navigator();//.mousewheel();
	
	//--------------------------------------------------------------
	

	
	
	// ----------------------------------------------------------------------------
	
	// fancybox
	var fancySettings = {
		'hideOnContentClick':	false,
		'cyclic'			:	true,
		'margin'			:	20,
		'centerOnScroll'	:	true,
		'overlayOpacity'	:	0.6,
		'overlayColor'		:	'#000',
		'speedIn'			:	600, 
		'speedOut'			:	200, 
		'overlayShow'		:	true,
		'showCloseButton'	:	true,
		'titlePosition' 	:	'inside',
		//'titleFormat'		:	fancyTitle,
		'foo': 'bar'
	}
	
	$('a.thickbox:has(img)', $('#pagecontent div.image')).fancybox(fancySettings);
	
	// slideshow home niet thickboxen... IE only
	$('.slideshow a.thickbox').removeAttr('href');
	
	//--------------------------------------------------------------
	
	
	var i = 0;		
	 
	/* 
		deposito toevoegen
	*/
	$("p.add_deposito").click(
		
		function()
		{
			
			i++;
			
			var html = $('div.duplicate:first').clone();
			
			var attr = $("input[name^='deposito']",$(html));
			
				
			
			$('input,select',$(html).insertBefore(".add_deposito").removeClass('duplicate'))
			.each(function()
			{
			
				$(this).attr('name',$(this).attr('name').replace('deposito[0','deposito['+ i));
			});
			
			wc(attr);
			
			
			
			
		}
	);
	
	// ----------------------------------------------------------------------------
	
	//$('#pagecontent h3:first').addClass('first-child');
	$('#pagecontent h2:eq(0)').addClass('first-child');
	
	//--------------------------------------------------------------
		
	$('.panel').each(function(i){
		
		$('p.image', this).hide();
		
		var bgs = $('p.image img', this).attr('src');
		
		// wc(bgs);
		
		// todo.. als bgs is undefined!
		
		var wrap = $('<div class="js-wrap"/>');
		
		if(bgs) wrap.css({ backgroundImage: 'url('+bgs+')' });
		
		$('.content', this).wrap(wrap).css({ opacity: 0.9 } );
		
		// 
		if($(this).hasClass('js-enabled'))
		{
			//
			$('.content', this).css({
							
				position: 'absolute',
				
				height: 150,
				
				width: 265, // < voor IE7
				
				top: 113
				
			});
			
			// IE round weer fixen
			
			$(this).hover(function(){
			
				wc('over');
				
				$('.content', this).stop().animate({
						
					top: 0
										
				}, '800');
				
			}, function(){
			
				wc('out');
				
				$('.content', this).stop().animate({
						
					top: 110
										
				}, '1200');
			});
		}
		
	});
	
	
	if(jQuery.browser.msie && parseInt(jQuery.browser.version) > 6)
	{
		//$('.panel, .image')
		$('.panel')
			.append('<span class="rc-ltop"></span><span class="rc-rtop"></span>')
			.prepend('<span class="rc-lbottom"></span><span class="rc-rbottom"></span>')
		;
	}
	
	// ----------------------------------------------------------------------------
	
	if($('#map').length)
	{
		var myLatlng = new google.maps.LatLng(-34.397, 150.644);
		
		//var address = 'Wilgenhaege Vermogensbeheer B.V., Polarisavenue 97, 2132 JH Hoofddorp';
		var address = 'Polarisavenue 97, 2132 JH Hoofddorp';
		
		var myOptions = {
			
			zoom: 14,
			
			disableDefaultUI: false,
			
			//center: myLatlng,
			
			mapTypeId: google.maps.MapTypeId.ROADMAP
		}
		
		var infowindow_contents = $('#map').html();
		
		//wc(infowindow_contents);
		
		var map = new google.maps.Map($('#map')[0], myOptions);
	
		var geocoder = new google.maps.Geocoder();
		
		geocoder.geocode(
			
			{'address': address},
			
			function(results, status)
			{
				if (status == google.maps.GeocoderStatus.OK)
				{
					// wc(results);
					
					map.setCenter(results[0].geometry.location);
					
					map.setZoom(14);
					
					var marker = new google.maps.Marker({
						map: map, 
						position: results[0].geometry.location
					});
					
					var infowindow = new google.maps.InfoWindow({
					
						content: infowindow_contents,
						
						maxWidth: 400
						
					});
									
					infowindow.open(map, marker);
				
				}
				else
				{
					wc("Geocode was not successful for the following reason: " + status);
				}
			}
		);
		
		// api v2 only???
		//var trafficOptions = {incidents:true};
		//trafficInfo = new GTrafficOverlay(trafficOptions);
		//map.addOverlay(trafficInfo);
	}
	
});

// ----------------------------------------------------------------------------

$.easing.custom = function (x, t, b, c, d) { 
    var s = 1.70158;  
    if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b; 
    return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b; 
}

