function redirect(url){
	document.location.href=url;
}
function hide(id){
	document.getElementById(id).style.display = 'none';
}
function show(id){
	document.getElementById(id).style.display = 'block';
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function move(direction, max){
	var str = null;
	var obj = null;
	if(direction == "left" || direction == "right"){
		obj = getObject("thumbnails-bottom");
		str = obj.style.marginLeft;
	}
	else{
		obj = getObject("thumbnails-top");
		str = obj.style.marginTop;
	}
	if(str.length > 0){
		str = parseInt(str.substring(0, (str.length-2)));
	}
	else{
		str = 0;
	}
	if(direction == "left"){
		if(str != 0){
			obj.style.marginLeft = (str+49) + "px";
		}
	}
	else if(direction == "right"){
		if(str > -max){
			obj.style.marginLeft = (str-49) + "px";
		}
	}
	else if(direction == "up"){
		if(str != 0){
			obj.style.marginTop = (str+78) + "px";
		}
	}
	else if(direction == "down"){
		if(str > -max){
			obj.style.marginTop = (str-78) + "px";
		}
	}
}

function set_margin(margin){
	obj = getObject("thumbnails-top");
	obj.style.marginTop = -(margin) + "px";
}

function getObject(id){
	obj = document.getElementById(id);
	if(obj != undefined){
		return obj;
	}
}

var current_id = '1';

function changePhoto(url, id){
	obj = getObject('photo' + current_id);
	obj.onmouseover = function() { changeBackground(this, 'bottom left'); };
	obj.onmouseout = function() { changeBackground(this, 'top left'); };
	obj.style.backgroundPosition = 'top left';
	//getObject('image-holder').src = img;
	
	updateDiv('display-image', url);
	
	obj2 = getObject('photo' + id);
	obj2.style.backgroundPosition = 'bottom left';
	obj2.onmouseover = function() { return false; };
	obj2.onmouseout = function() { return false; };
	current_id = id;
}

function changeBackground(obj, background){
	obj.style.backgroundPosition = background;
}

function showPopup(url){
	showBackground();
	show("popup");
	updateDiv('popup', url);
}

function closePopup(url){
	current_id = 1;
	hide("background");
	getObject('popup').innerHTML = '';
	hide("popup");
}

function updateDiv(obj, url){
	new Ajax.Updater(obj, url,
		{
			onComplete: function() { hide('loader'); }
		}
	);
}

function showBackground(){
	obj = document.getElementById('background');
	obj.style.display = 'block'
	var tmp_height = obj.offsetHeight;
	/*
	objs = document.getElementsByTagName('div');
	for(var i = 0; i < objs.length; i++){
		objpos = findPos(objs[i]);
		objheight = objs[i].offsetHeight;
		objtemp = objpos[1] + objheight;
		if(objtemp > tmp_height){
			tmp_height = objtemp;
		}
	}
	alert(tmp_height);
	*/
	obj.style.height = tmp_height + 'px';
}

/*
Google maps functions
*/

function initialize(){
	if(GBrowserIsCompatible()){
		
		var map = new GMap2(document.getElementById("image"));
		map.enableScrollWheelZoom();
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.setCenter(new GLatLng(51.58797635183770, 4.53919887542725), 14);
		
		var point = new GLatLng(51.59080262969847, 4.52589511871338);
		var marker = createMarker(point, '<b>Showroom</b><br />Prof. van Ginnekenstraat 34<br />4731 JZ Oudenbosch<br />T. 0165-312685<br />F. 0165-320532<br />M. 06-15065405<br />E. <a href="mailto:info@oudenhoven-trappen.nl" style="color:#000000;text-decoration:underline;">info@oudenhoven-trappen.nl</a><br /><br /><a href="http://maps.google.nl/maps?daddr=Prof+van+Ginnekenstraat+34,+4731+JZ+Oudenbosch+(Oudenhoven+Trappen)&geocode=CY6JRTPbWAgOFVw4EwMd7wxFACEsSnl0PSOqKA&dirflg=&f=d&sll=51.594562,4.525294&sspn=0.012397,0.038624&cid=2930193254412012076&ie=UTF8&z=14" style="color:#000000;text-decoration:underline;" target="_blank">Plan hier uw route naar de showroom.</a>');
		map.addOverlay(marker);
		
		var point = new GLatLng(51.59114923657710, 4.55563545227051);
		var marker = createMarker(point, '<b>Werkplaats</b><br />Blauwe Hoefweg 16<br />4731 DJ Oudenbosch<br />T. 0165-320871<br />F. 0165-320015<br />M. 06-15065405<br />E. <a href="mailto:info@oudenhoven-trappen.nl" style="color:#000000;text-decoration:underline;">info@oudenhoven-trappen.nl</a><br /><br /><a href="http://maps.google.nl/maps?daddr=Blauwe+Hoefweg+16,+4731+DJ+Oudenbosch+(Oudenhoven+Trappen)&geocode=CQF1uHdgrsnoFXU4EwMdlX9FACFRw6tvw1OGdw&dirflg=&f=d&hl=nl&sll=51.594162,4.544649&sspn=0.012397,0.038624&cid=8612663436249908049&ie=UTF8&z=14" style="color:#000000;text-decoration:underline;" target="_blank">Plan hier uw route naar de werkplaats.</a>');
		map.addOverlay(marker);
	}
}
	
function createMarker(point, html){
	var baseIcon = new GIcon();
	baseIcon.iconSize = new GSize(16, 16);
	baseIcon.iconAnchor = new GPoint(10, 20);
	baseIcon.infoWindowAnchor = new GPoint(10, 2);
	
	var icoontje = new GIcon(baseIcon);
	icoontje.image = "/assets/images/icon.gif";

	markerOptions = { icon:icoontje };
	
	var marker = new GMarker(point, markerOptions);
	GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(html); });
	return marker;
}
