  var global_markers = new Array();
  var map;
//----------------------------------------------------------
  function createMarker(point, content, cap) {
	var opt = new Object();
	opt.title = cap;
	var marker = new GMarker(point, opt);  
	GEvent.addListener(marker, "click", function() {map.setCenter(point, zoom); marker.openInfoWindowHtml(content);  });  
	return marker;
	}
//----------------------------------------------------------
function formatDegrees(x){
	var res = "";
	var absx=Math.abs(x);
	res += Math.floor(absx);
	res +="°";

	mn = (x-Math.floor(x))*(60/100)*100;
	res += Math.floor(mn);
	res +="'";

	sc = (mn - Math.floor(mn))*(60/100)*100;
	res +=sc.toFixed(2);
	res +='"';

	return res;
}

// format gps coordinates
function formatGPS(x,y)
{
    var gps = x.toFixed(10) +", "+y.toFixed(5);

    gps = (x<0) ? "S" : "N";
    gps += formatDegrees(x) + ", ";
    //gps += x.toFixed(6) + ", ";
   
	gps += (y<0) ? "W" : "E";
    gps += formatDegrees(y);
    //gps += y.toFixed(6);
    
    return gps;
}




// will create the html representaion of the details


// print page
function printMap()
{		
	try { 
		window.print();
	}
	catch(e){
		GLog.write(e);
	}
}

function GetUrl( name )
{
	var regexexp = (name != null ) ? "[\\?&]"+name+"=([^&#]*)" : "\\?(.*)";
	var regex = new RegExp( regexexp );
	var tmpURL = window.location.href;
	var results = regex.exec( tmpURL );

	if( results == null ) return "";
	else
	{
		// first remove spaces and then decode from UTF8
		var result = results[1].replace(/\+/g, " ");
		try	{
			return decodeURIComponent(result);
		}
		catch(err) {
			return result;
		}
	}
}

function GId( id ){
	return document.getElementById(id);
}

function HtmlControl(html, title, printable, visible){
	this.html = html;
	this.isPrintable = printable;
	this.Title = title;
	this.isVisible = visible;
} 

HtmlControl.prototype = new GControl(); 
HtmlControl.prototype.initialize = function(map) { 
	var dive = document.createElement("div"); 
	dive.className = "htmlcontrol"; 
	dive.innerHTML = this.html; 
	dive.title = this.Title;
	if(this.isVisible)
		dive.style.visibility='visible';
	else
		dive.style.visibility='hidden';
		map.getContainer().appendChild(dive); 
	return dive; 
}

HtmlControl.prototype.getDefaultPosition = function() { 
	return new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(7, 30)); 
}

//----------------------------------------------------------
	function initialize() {

	var tinyIcon = new GIcon();
	tinyIcon.image = "http://www.czechtrade.net/images/ico_gmaps.png";
	tinyIcon.shadow = "http://www.czechtrade.net/images/ico_gmaps_shadow.png";
	tinyIcon.iconSize = new GSize(39, 46);
	tinyIcon.shadowSize = new GSize(53, 46);
	tinyIcon.iconAnchor = new GPoint(17, 44);
	tinyIcon.infoWindowAnchor = new GPoint(19, 48);
	markerOptions = { icon:tinyIcon };	
	
	map = new google.maps.Map2(document.getElementById("map"));

	if( set_control_print ) map.addControl(new GSmallMapControl());
	if( set_control ){
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.addControl(new GOverviewMapControl());
	}
	
	map.setCenter(new GLatLng(gps_n,gps_e), zoom);   

	if( set_control ){
		map.addControl(new HtmlControl('<div id="print" title="Tisknout" class="mapCustomButton"><img src="http://www.czechtrade.net/images/print.png" alt="Tisknout"></div>', 'Tisknout' ,false,true), new GControlPosition(G_ANCHOR_TOP_RIGHT,new GSize(7,60))); 
		GEvent.addDomListener(GId('print'), 'click', function() { window.open('http://map.czechtrade.net/'+directory+'/print');} );
		map.addControl(new HtmlControl('<div id="spnGPS" title="GPS souřadnice"><img src="http://www.czechtrade.net/images/gps.png"> <span id="gpstext">GPS souřadnice</span></div>', 'GPS souřadnice',false,true), new GControlPosition(G_ANCHOR_BOTTOM_LEFT,new GSize(70,7)));
		GEvent.addListener(map, "mousemove", function(pnt){ GId("gpstext").innerHTML = formatGPS(pnt.y, pnt.x);} );
	}
	
	var point =		new GLatLng(gps_n,gps_e);
	var marker = new GMarker(point, markerOptions);
	
	
	if( set_control_click ){
		GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(firm);});
	}
	map.addOverlay(marker);
	if( set_control_click ){
		marker.openInfoWindowHtml(firm);
	}
	if( set_control_print ) window.print(); 
  }      

  

function Cli(firm,logo,detail){
	if( logo ){
		document.imgcli.src = "http://www.czechtrade.net/images/cli.gif?f="+firm+"&r="+logo+Math.random()+"&d="+detail;
	}else{
		document.imgcli.src = "http://www.czechtrade.net/images/cli.gif?f="+firm+"&r="+Math.random()+"&d="+detail;
	}
}
