var down;
var oneTime = true;

// JavaScript Document
$(document).ready(function(){
	
	var windowHeight = $(window).height();
	
	// Enable dragging
	$('#menu').draggable( { 
		containment: 'window',
		axis: 'y',
		handle: '#menu',
		drag: function(event, ui) { 
			resizeMaps();
		} 
	} );
	
	// Function to resize the maps during dragging
	function resizeMaps() {
		var winHeight = $(window).height();
		var zoomHeight = winHeight - $('#menu').position().top;
		if(zoomHeight>285) map_zoom.addControl(mapzoomControl, mapzoomOnder);
		if(zoomHeight<285) map_zoom.removeControl(mapzoomControl);
		$("#map_canvas_zoom").height(zoomHeight);
		$("#map_canvas").height($('#menu').position().top);
		map.checkResize();
		map_zoom.checkResize();
	}
	
	$('#menu').tooltip({
		track: true,
		fixPNG: true,
		left: 5
	});

	
	$('#menu_txt a').hover(function() {
		$(this).stop().animate({ "opacity": .7 });
	}, function() {
		$(this).stop().animate({ "opacity": 1 });
	});
		
	//menu hover 
	$(".menu").hover(
	 function() {
	  this.src = this.src.replace("_off","_on");
	  //$(this).attr("src")
	 },
	 function() {
	  this.src = this.src.replace("_on","_off");
	 }
	);
		
	// submenu hover
	$(".submenu").hover(
		function() {
			if (!$(this).hasClass("selected")) {
				var x = this.src;
				if (x.match("_on") != null) {
					this.src = this.src.replace("_on", "_off");
				}
				else {
					this.src = this.src.replace("_off", "_on");
				}
			}
		},
		function() {
			if ( !$( this ).hasClass("selected") ) {
				var x = this.src;
				if (x.match("_on") != null) {
					this.src = this.src.replace("_on", "_off");
				}
				else {
					this.src = this.src.replace("_off","_on");
				}
			}
		}
	);
	
	// selected submenu
	$(".submenu").click( function() {
		moveDown();
		
		$(".submenu").each( function() {
			var x = this.src;
			if( x.match("_on") != null ) {
				$(this).removeClass( "selected");
				this.src = this.src.replace("_on","_off");
			}
		} );
		
		var x = this.src;
		if( x.match("_on") == null ) {
			$( this ).addClass( "selected");
			this.src = this.src.replace("_off","_on");
		}
		
		var cat = this.name;
		getNewPois( cat );
	} );
	
	//png fix voor IE6	
	//set the background image	
	$.ifixpng(themeUrl+'/images/pixel.gif');
	
	//only our used images and not the one's provided by google maps
	$('#buzaImg, #disclaimerImg, #hierisImg, #pageStateImg, #arrowsImg').ifixpng();
	
	// Add bookmark link
	$('#bookmarkPage').jFav();
	
	// Add
	$("#share_txt a").mouseover(function(){
		$("#share_txt_mouseover").html($(this).html());
	}).mouseout(function(){
		$("#share_txt_mouseover").html('');
	});
	
	//all images
	//$('img[@src$=.png]').ifixpng(); 
});
 
 
//functions 
function moveDown() {
	var winHeight = $(window).height();
	var boven = winHeight * 0.6;
	var onder = winHeight * 0.4;
	
	$("#map_canvas").animate({ "height" : boven }, 0);
	$("#menu").animate({ "top" : boven }, 0);
	$("#map_canvas_zoom").animate({ "height" : onder }, 0);
		
	if(oneTime)	{ //maar een keer centreren, eigenlijk alleen nodig voor "nu"
		window.setTimeout(function() {
			map.checkResize();			   
			map.setCenter(new GLatLng(20.0, -1.0), 2);
		}, 500);
		oneTime = false;
	}
	down = true;
}

function moveUp() {
	var winHeight = $(window).height();
	var boven = winHeight * 0.2;
	var onder = winHeight * 0.8;
	
	$("#map_canvas").animate({ "height" : boven }, 0);
	$("#menu").animate({ "top" : boven }, 0);
	$("#map_canvas_zoom").animate({ "height" : onder }, 0);

	down = false;
}

function animateMenu() { 
	if(down){
	   moveUp();
	} else {
	   moveDown();
	}
}

function resizeThis( spot ) {
	var winHeight = $(window).height();
	var map_canvasHeight;
	var map_canvas_zoomHeight;
	
	if( down === true ) {
		spot = 'down';
	} else {
		spot = 'up';
	}
	
	switch( spot ) {
		case 'down':
			map_canvasHeight = winHeight * 0.6;
			map_canvas_zoomHeight = winHeight * 0.4;
			break;
		default:
			map_canvasHeight = winHeight * 0.2;
			map_canvas_zoomHeight = winHeight * 0.8;
	}
	
	$("#map_canvas").css( "height", map_canvasHeight );
	$("#map_canvas_zoom").css( "height", map_canvas_zoomHeight );
	$("#menu").css( "top", map_canvasHeight );

}
