// +------------------------------------------------------------------+
// | JavaScript version 1.0                                           |
// +------------------------------------------------------------------+
// | gmaps-viewer-v1.x.js – Widget load script						  |
// +------------------------------------------------------------------+
// | Copyright (c) 2009 MultiMove                                     |
// +------------------------------------------------------------------+
// | Authors: S.F.Beck <sander@multimove.nl>     					  |
// +------------------------------------------------------------------+

function resizeCaller() {
	var dyniframe=new Array()
	for (i=0; i<iframeids.length; i++){
		if (document.getElementById)
			resizeIframe(iframeids[i])
		if ((document.all || document.getElementById) && iframehide=="no"){
			var tempobj=document.all? document.all[iframeids[i]] : document.getElementById(iframeids[i])
			tempobj.style.display="block"
		}
	}
}

function resizeIframe(frameid){
	var currentfr=document.getElementById(frameid)
	if (currentfr && !window.opera){
		currentfr.style.display="block"
		if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) //ns6 syntax
			currentfr.height = currentfr.contentDocument.body.offsetHeight+FFextraHeight; 
		else if (currentfr.Document && currentfr.Document.body.scrollHeight) //ie5+ syntax
			currentfr.height = currentfr.Document.body.scrollHeight;
		if (currentfr.addEventListener)
			currentfr.addEventListener("load", readjustIframe, false)
		else if (currentfr.attachEvent){
			currentfr.detachEvent("onload", readjustIframe) // Bug fix line
			currentfr.attachEvent("onload", readjustIframe)
		}
	}
}

function readjustIframe(loadevt) {
	var crossevt=(window.event)? event : loadevt
	var iframeroot=(crossevt.currentTarget)? crossevt.currentTarget : crossevt.srcElement
	if (iframeroot)
	resizeIframe(iframeroot.id);
}

function loadintoIframe(iframeid, url){
	if (document.getElementById)
	document.getElementById(iframeid).src=url
}

function each(obj, fn, scope){
	for(var i = 0, len = obj.length; i < len; ++i)
		if(fn.call(scope || obj[i], obj[i], i, obj) === false) return;
}

if (typeof(window['gobt_map_width']) == "undefined")
    gobt_map_width = 300;

if (typeof(window['gobt_map_height']) == "undefined")
    gobt_map_height = 300;
	
if (typeof(window['gobt_map_legend_height']) == "undefined")
    gobt_map_legend_height = 0;

if (typeof(window['gobt_map_language']) == "undefined")
    gobt_map_language = 'nl';	
	
if (typeof(window['gobt_map_type']) == "undefined") 
   	gobt_map_type = 'region';

if (typeof(window['gobt_map_id']) == "undefined") 
   	gobt_map_id = Math.random(9999);

var gobt_total_height = gobt_map_height + 10;
if (window['gobt_map_legend_height'] != "auto")
    gobt_total_height += gobt_map_legend_height;

if( typeof(window['gobt_map_source_domain']) == "undefined" ){
	// determine script path automatically
	var path_re = /(.+)gmaps-viewer-v1.x\.js/i, path;	
	each(document.getElementsByTagName('script'), function(s){	
		if((path = path_re.exec(s.src)) != null){
			s.path = path[1];
			gobt_map_source_domain = s.path;
			return false;
		}
	});
}

var gobt_map_options = '';
if (typeof(window['gobt_map_type_options']) != "undefined") {	
	for( var i in gobt_map_type_options ){	
		gobt_map_options += '&map_type_option_'+i+'=' + escape(gobt_map_type_options[i]);
	}
}

/* NOT RECOMMENDED! */
if( gobt_map_legend_height == 'auto' ){	
	var iframeids=[gobt_map_id];
	var iframehide="no";
	var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1];
	var FFextraHeight=parseFloat(getFFVersion)>=0.1? 16 : 0; //extra height in px to add to iframe in FireFox 1.0+ browsers
	if (window.addEventListener)
		window.addEventListener("load", resizeCaller, false);
	else if (window.attachEvent)
		window.attachEvent("onload", resizeCaller);
	else
		window.onload = resizeCaller;
}
	
var html = '<iframe src="'+gobt_map_source_domain+'index.php'+    
	'?lang=' + escape(gobt_map_language) +
	'&module=' + escape('locations') +
	'&id=' + escape('interactieve_kaart') +
	'&maptype=' + escape(gobt_map_type) +
	'&mapheight=' + gobt_map_height +
	'&mapwidth=' + gobt_map_width +
	'&legendheight=' + gobt_map_legend_height + 
	'' + gobt_map_options + '" ' +
    'width="' + gobt_map_width + '" ' +
    'height="' + gobt_total_height + '" ' +	
    'scrolling="no" frameborder="0" allowtransparency="true" hspace="0" vspace="0" marginheight="0" marginwidth="0" style="border: none; overflow: hidden;" id="' + gobt_map_id + '" name="' + gobt_map_id + '"></iframe>';
document.write(html);