var geocoder;
var map;
var timeOut;

function initialize() {
	geocoder = new google.maps.Geocoder();

	var myAddress = document.getElementById('zip').value + " Nederland";
//	alert(myAddress);

	var latlng = codeAddress( myAddress , true);
	if(!latlng)
		latlng = new google.maps.LatLng(51.608316,5.46072);

	var points = document.getElementsByName('stores');
	var numstores = parseInt(document.getElementById('numstores').value);
	for(i = 0; i < numstores; i++)
		var adr = codeAddress( document.getElementById('stores_' + i ).value , false);

	var myOptions = {
		zoom: 11,
		center: latlng,
//		disableDefaultUI: true,
		navigationControlOptions: { 
        	position: google.maps.ControlPosition.TOP_RIGHT 
		},
		mapTypeControl: false,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	}
	map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}

function codeAddress(myAddress,doCenter) {
//	var address = document.getElementById("address").value;
	if (geocoder) {
		
		geocoder.geocode( { 'address': myAddress}, function(results, status) {
			if (status == google.maps.GeocoderStatus.OK) {
				if(doCenter){
					map.setCenter( results[0].geometry.location );
					var marker = new google.maps.Marker({
						map: map, 
						position: results[0].geometry.location,
						title: 'Your location',
						icon: '/images/layout/pinpoint_you.png'
					})
				}else{
					tooltip = '';
					if(myAddress.indexOf('|') > 0){
						myAddr = myAddress.split('|');
						myAddress = myAddr[1];
						tooltip = myAddr[0];
//						alert(tooltip);
					}
					
					var marker = new google.maps.Marker({
						map: map, 
						position: results[0].geometry.location,
//						title: tooltip,
						icon: '/images/layout/pinpoint_small.png'
					})
				}
				return results[0].geometry.location;
			} else {
				return false;
			}
		});
	}
}


$(document).ready(function() {
	$(function(){	// "active" als class toevoegen aan de actieve link in de navigatie
	   var path = location.pathname.substring(1);
	   if ( path ){
		 $('#navHolder a[@href$="/' + path + '"]').addClass('active');
	   }
	 });

	$.get("/data/token.ajax",function(txt){
		$(".securedForm").append('<input type="hidden" name="ts" value="'+txt+'" />');
	});
	if( $('#map_canvas').html() != null )	// kaart-div is geladen
		initialize();

	$("#menuWrapper").hover(
		function () {
/*			$("#subMenu").stop().animate({ 
			top: "0px"
		}, 450 );*/
			return true;
		}, 
		function () {
			if(undefined != timeOut)
				clearTimeout(timeOut);
			timeOut = setTimeout('$("#subMenu").stop().animate({ top: "-130px" }, 1000 );',10000);
/*			$("#subMenu").html("<div>&nbsp;</div>");*/
		}
	);

	$('#mainMenu > a').bind('mouseenter', function() {
		tt_id = $(this).attr('subHtml');
		tt = $('#sub'+tt_id).html();
//		alert(tt);
		if(tt.length > 10){
			
			$("#subMenu > div").fadeOut(100,function(){
				$("#subMenu").stop().html( "<div style='display: none;'>"+tt+"</div>" ).css("top","0px");
				setTimeout('$("#subMenu > div").show()',100);
			});
		}
	});

	setTimeout("$(window).trigger('resize')",1000);


	$('#slideshow').innerfade({
		animationtype: 'fade',
		speed: 2500,
		timeout: 6000,
		type: 'random',
		containerheight: '315px'
	});


	var winW = 630;
	
	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
			winW = window.innerWidth;
		}
		if (navigator.appName.indexOf("Microsoft")!=-1) {
			winW = document.body.offsetWidth;
		}
	}
	$('#collectionHolder').css("width",winW);
	
/*	$(".colBrowseImg").hover(
		function () {
			$(this).attr("height","300");
		}, 
		function () {
			$(this).attr("height","250");
		}
	);*/

	$(".mainBtn").hover(function(){
		$(this).css("background-position","0px -22px");
	},function(){
		$(this).css("background-position","0px 0px");
	});
/*
	$("#subMenu img").hover(function(){
		$(this).css("background-position","0px 80px");
	},function(){
		$(this).css("background-position","0px 0px");
	});
*/

});



