$(document).ready(function(){
	/*
	jQuery(function(){jQuery(document).pngFix();});

	$("a.zoom").fancybox();
	*/
	$("a[rel=fotogroep]").fancybox({
		'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-outside"><span style="float:right"># ' +  (currentIndex + 1) + ' / ' + currentArray.length + '</span>' + (title && title.length ? title : '&nbsp;' ) + '</span>';
		}
	});
	
	$('#cform').validate();

	
	$('#home .blok').hover(function(){
		//$('.blok').not(this).stop().animate({opacity:'0.5'},{queue:false,duration:300, easing: 'easeOutCirc'});;
		$(".cover", this).stop().animate({top:'0px'},{queue:false,duration:300, easing: 'easeOutCirc'});
	}, function(){
		//$('.blok').stop().animate({opacity:'1'},{queue:false,duration:500, easing: 'easeOutCirc'});;
		$(".cover", this).stop().animate({top:'170px'},{queue:false,duration:500, easing: 'easeOutCirc'});
	})
	
	$( "#accordion" ).accordion({
		collapsible: true,
		autoHeight: false,
		fillSpace:false,
		active: false,
		navigation: true
	});
	
	$("#accordion h2 a").click(function(event){
		window.location.hash=this.hash;
		$('html, body').animate({scrollTop: $(window.location.hash).offset().top}, 500);
	});
	
	var map='';
	$("#accordion").bind('accordionchange', function(event, ui) {
		if (ui.newContent.attr('id')=='routebeschrijving' && !map){
			map=initialize();
		}
		
	});
	
	if(window.location.hash){

		$(window.location.hash).css('display','block');
	}
	
	if(window.location.hash=='#routebeschrijving') initialize();

	if(window.location.hash=='#verzonden') alert('Uw bericht is succesvol verzonden!');
});

function initialize() {
	var myLatlng = new google.maps.LatLng( 51.46246, 5.68440);
	var myOptions = {
	mapTypeControl: false,
	zoom: 13,
	center: myLatlng,
	mapTypeId: google.maps.MapTypeId.ROADMAP
	}
	var map = new google.maps.Map(document.getElementById("map"), myOptions);
	
	var locations = [
		['Gebebouw B.V.', 51.46246, 5.68440, 4, 'Plan uw route naar ons kantoor:<br><br><form action="http://maps.google.nl/maps" target="blank"><input onfocus="if(this.value==\'straat, plaats\') this.value=\'\'" value="straat, plaats" type="text" name="saddr" ><input type="hidden" name="daddr" value="Achterdijk 18, Helmond" > <input type="submit" value="plan route"></form>']
	];
	
	setMarkers(map, locations);
}

function setMarkers(map, locations) {
	for (var i = 0; i < locations.length; i++) {
		var locatie = locations[i];
		var myLatLng = new google.maps.LatLng(locatie[1], locatie[2]);
		var infowindow = new google.maps.InfoWindow({
		});

		var marker = new google.maps.Marker({
			position: myLatLng,
			map: map,
			title: locatie[0],
			zIndex: locatie[3],
			content: locatie[4]
		});
		
		infowindow.setContent(marker.content);
		infowindow.open(map,marker);
		
		google.maps.event.addListener(marker, 'click', function() {
			infowindow.setContent(marker.content);
			infowindow.open(map,marker);
		});
	}
}

