
// JavaScript Document
var zoomlevel 		= 0;
var oldfactor		= 0;
var zoomtimeout 	= false;
var mapClosed 		= false;
var target_height 	= 3033;
var target_width 	= 3000;
var map_width;
var map_height;	
var map_left;	
var map_top;	
var plaatsen_temp = '';
function zoommap(pixels,noHide){
	if(!noHide){
		checkMapImage('low')
		target_width = parseInt($('map').style.width);
	}
	if(pixels > 0){
		newwidth 	= target_width + 0.04*(target_width);
	}else{
		newwidth 	= target_width - 0.04*(target_width);
	}
	if(newwidth < 400){
		newwidth = 400;
		setZoom(newwidth,'direct');		
	}else if(newwidth > 4000) {
		newwidth = 4000;
		setZoom(newwidth,'direct');
	}else{
		setZoom(newwidth,'direct')
		zoomtimeout = setTimeout('zoommap('+pixels+',true)',20);			
	}
}


function clearzoom(){
	//$('plaatsen').style.visibility = 'visible';
	setDragMap();
	clearTimeout(zoomtimeout);
	checkMapImage();
}

function reArrangePlaatsen(){
	var factorCoordinatenX = (parseInt($('map').style.width)) / (3000);
	var factorCoordinatenY = (parseInt($('map').style.height)) / (3033);	
	for(var i=0; i<plaatsenids.length;i++){
		$('plaats_' + plaatsenids[i]).style.left 	= Math.round(xcoord[i]*factorCoordinatenX)-8 + 'px';
		$('plaats_' + plaatsenids[i]).style.top 	= Math.round(ycoord[i]*factorCoordinatenY)-8 + 'px';			
	}			
}

function mapMoveTo(x,y,zoom){

	if(zoom){
		if(isNaN(zoom)) zoom = 1200;
		x = Math.round((x-19.3835719335) / 0.00310091048593) - 8;
		y = Math.round((y-42.0358984725) / -0.00246750509165) - 8;
		var targetwidth 		= zoom;
		var targetheight 		= Math.round(zoom  * 3033 / 3000);	
		var factorCoordinatenX 	= targetwidth / (3000);
		var factorCoordinatenY 	= targetheight / (3033);	
		mover('map',((-1*x*factorCoordinatenX) + (691/2)),((-1*y*factorCoordinatenY) + (440/2)),targetwidth,targetheight,2);
		

	}else{
		x = Math.round((x-19.3835719335) / 0.00310091048593) - 8;
		y = Math.round((y-42.0358984725) / -0.00246750509165) - 8;
		var targetwidth 		= parseInt($('map').style.width);
		var targetheight 		= Math.round(parseInt($('map').style.width)  * 3033 / 3000);	
		var factorCoordinatenX 	= targetwidth / (3000);
		var factorCoordinatenY 	= targetheight / (3033);	
		mover('map',((-1*x*factorCoordinatenX) + (691/2)),((-1*y*factorCoordinatenY) + (440/2)),false,false,2);	
	}
}
mapChangeTO = false

function checkMapImage(type){
	if(type == 'low'){
		showImage = 'map_img_small';
		hideImage = 'map_img_big';		
	}else{
		showImage = 'map_img_big';	
		hideImage = 'map_img_small';			
	}
	if($(showImage).style.display != 'visible'){
		$(showImage).style.visibility = 'visible';
		$(hideImage).style.visibility = 'hidden';		
	}				
}


function checkMapImageOld(type){
	if(type == 'low'){
		imagesrc = 'images/map_500.gif';
	}else{
		if(parseInt($('map').style.width) <= 500) 			imagesrc = 'images/map_500.gif';
		else if(parseInt($('map').style.width) <= 1000) 	imagesrc = 'images/map_1000.gif';		
		else if(parseInt($('map').style.width) <= 1500) 	imagesrc = 'images/map_1500.gif';			
		else if(parseInt($('map').style.width) <= 2000) 	imagesrc = 'images/map_2000.gif';
		else 												imagesrc = 'images/map_3000.gif';			
		imagesrc = 'images/map_3000.gif';		
	}
	if($('map_img').src.indexOf(imagesrc) == -1){
		clearTimeout(mapChangeTO);
		trace('changemap: ' + imagesrc)
		mapChangeTO = setTimeout('$(\'map_img\').src = \'' + imagesrc + '\'',5);	
	}				
}
function setZoom(width,type){
	
	var factor 				= width / parseInt($('map').style.width);
	target_width 			= width;
	target_height 			= Math.round(width  * 3033 / 3000);
	oldwidth 				= parseInt($('map').style.width);
	oldheight 				= parseInt($('map').style.height);	
	oldleft 				= parseInt($('map').style.left);
	oldtop					= parseInt($('map').style.top);		

	middelpunt 		= (parseInt($('map').style.left)*-1) + (691/2);
	newmiddelpunt 	= middelpunt * factor;
	newleft			= (newmiddelpunt - (691/2))*-1;

	middelpunt 		= (parseInt($('map').style.top)*-1) + (440/2);
	newmiddelpunt 	= middelpunt * factor;
	newtop			= (newmiddelpunt - (440/2))*-1;
	
	if(type == 'smooth'){		
		mover('map',newleft,newtop,target_width,target_height,3,false,false,'clearzoom()');	
	}else if(type == 'direct'){	
		$('map').style.width 	= target_width + 'px';
		$('map').style.height 	= target_height + 'px';	
		$('map').style.top 		= newtop + 'px';
		$('map').style.left 	= newleft + 'px';
		reArrangePlaatsen()
	}else{
		mover('map',false,false,target_width,target_height,3,false,false,'clearzoom()');		
	}
}


function setMap(){
	$('map').style.left 	= ((3000 - 691) / -2) + 'px';
	$('map').style.top 		= ((3033 - 440) / -2) + 'px';	
	setZoom(450,'direct');
	setDragMap();
//	zoekAccomodaties();
}
 
function setDragMap(){
	mapwidth 	= parseInt($('map').style.width);
	mapheight 	= parseInt($('map').style.height);
	if(mapwidth < 691) 	mapwidth = 691;
	if(mapheight < 440) mapheight = 440;
	
	minx = (691-mapwidth) - 400;
	maxx = 631;		
	
	miny = (440-mapheight) - 380;
	maxy = 380;
	if(minx > maxx){
		minxoud = minx;
		minx 	= maxx;
		maxx 	= minxoud;			
	}
	if(miny > maxy){
		minyoud = miny;
		miny 	= maxy;
		maxy 	= minyoud;			
	}		
//	alert('X - current: '+parseInt($("map").style.left) + ' ; min: ' +minx + ' ; max: '+ maxx + ' ; map width:' + mapwidth + ' \ ' + target_width)
//	alert('Y - current: '+parseInt($("map").style.top) + ' ; min: ' +miny + ' ; max: '+ maxy + ' ; map height:' + mapheight)
	
	if(parseInt($("map").style.left) < minx) 	$("map").style.left 	= minx + 'px';
	if(parseInt($("map").style.left) > maxx) 	$("map").style.left 	= maxx + 'px';	
	if(parseInt($("map").style.top) < miny) 	$("map").style.top 		= miny + 'px';
	if(parseInt($("map").style.top) > maxy) 	$("map").style.top 		= maxy + 'px';	
	
	Drag.init($("map"),$("map"),minx,maxx,miny,maxy);	
	$('map').ondblclick = function(){
		alert(' left:' + this.style.left + ' top:' + this.style.top + ' width:' + this.style.width + ' height:' + this.style.height);	
	}
}

var plaatsen 		= new Array();
var plaatsenover 	= new Array();	
var opties 			= new Array();	
var toPlaatsen		= new Object();
var highestZ		= 100;
function newZ(){
	highestZ++;
	return highestZ;
}


function clickPlaats(id){
	if(!plaatsen[id]){
		plaatsen[id] = id;
		$('plaats_'+id).className = 'plaats_on';			
	}else{
		plaatsen[id] = '';
		$('plaats_'+id).className = 'plaats_on';			
	}
	zoekAccomodaties();
}

function showPlaatsNaam(id){
	$('plaats_'+id).style.zIndex = newZ();
	mover('plaatshider_'+id, (-1*($('plaatsnaam_'+id).offsetWidth)+8), false, $('plaatsnaam_'+id).offsetWidth, false, 3, false, false);		
}

function hidePlaatsNaam(id){
	mover('plaatshider_'+id, '8', false, 1, false, 3, false, false);	
}
function mouseoverPlaats(id){
	clearTimeout(toPlaatsen[id]);	
	$('plaats_'+id).style.zIndex = newZ();
	if(!plaatsen[id]){
//		mover('plaatsnaam_'+id, '0', false, false, false, 3, false, true);
		showPlaatsNaam(id)
	}
}	

function mouseoutPlaats(id){
	toPlaatsen[id] = setTimeout('mouseoutPlaats2('+id+')',100);
}	

function mouseoutPlaats2(id){
	clearTimeout(toPlaatsen[id]);
	if(!plaatsen[id]){
		hidePlaatsNaam(id)		
	}
}		

function clickOptie(id){
	if(!opties[id]){
		opties[id] = id;
		$("optie_"+id).className = 'optieover';
	}else{
		opties[id] = '';
		$("optie_"+id).className = 'optie';
	}
	zoekAccomodaties();		
}	


function toggleMap(){	
	if(mapClosed){
		mapClosed = false;
		ar = $('button_sluiten').style.backgroundPosition.split(' ');
		$('button_sluiten').style.backgroundPosition='0px '+ ar[1];
		$('maplabel').style.backgroundPosition='0px 120px'
		mover('map_container',false,false,false,440,3);
	}else{
		mapClosed = true;
		ar = $('button_sluiten').style.backgroundPosition.split(' ');
		$('button_sluiten').style.backgroundPosition=(-3*24) + 'px '+ ar[1];		
		$('maplabel').style.backgroundPosition='0px 120px'		
		mover('map_container',false,false,false,'34',3);
	}
}
