var mapPoints=new Array();

function load() {
  if (GBrowserIsCompatible()) {
    var map = new GMap2(document.getElementById("map"),{mapTypes:[G_SATELLITE_MAP]});
	// Copy mapType (this works!)
    //MVMapType = copy_obj(map.mapTypes[0]);
    //MVMapType.bounds = new GBounds(45.46530778161601, 12.29593276977539,45.32415109747755, 12.37661361694336);
    map.addControl(new GSmallMapControl());
	//map.addControl(new GMapTypeControl());
    map.setCenter(new GLatLng(45.43736964827511, 12.335071563720703), 13);
	for(i=0;i<mapPoints.length;i++){
		mapPoint=mapPoints[i];
		//alert('Lat:' + mapPoint['lat'] + ' Long:' + mapPoint['lon']);
		var point = new GLatLng(mapPoint['lat'],mapPoint['lon']);
		map.addOverlay(createMarker(point, mapPoint['html_text'], i));
		/*
		mapPoint=mapPoints[i];
		var point = new GLatLng(mapPoint['lat'],mapPoint['lon']);
		map.addOverlay(createMarker(point, mapPoint['image_url'], mapPoint['html_text']));
		if(mapPoint['center']){
			map.setCenter(new GLatLng(mapPoint['lat'],mapPoint['lon']));
		}
		*/
	}
  }
}

// Copy Object Function
function copy_obj(o) {
      var c = new Object();
      for (var e in o) {
          if (typeof o[e] =='array' && o[e].constructor == Array) {
             c[e] = o[e].copy();
          }
          else {
             c[e] = o[e]; 
          }
      }
      return c;
}

function showMap(){
	xDisplay('map','block');
	xDisplay('flash','none');
	xDisplay('wrapper','none');
	load();
}

function toogleSeoToolkit(){
	if(xDisplay('sef_toolkit_content')=='none'){
		xDisplay('sef_toolkit_content','block');
		xDisplay('flash','none');
		xZIndex('sef_toolkit',3);
	}else{
		xDisplay('sef_toolkit_content','none');
		xDisplay('flash','block');
		xZIndex('sef_toolkit',0);
	}
}
	
function goTo(id){
	var link = document.getElementById(id);
	window.location.href=link.href;
	return false;
}

function goToA(){
	url='';
	for(var i=arguments.length-1;i>=0;i--){
		url+=((url=='')?'':'.') + arguments[i];
	}
	if(url!=''){
		window.open('http://' + url + '/');
	}
	return false;
}

function adjustLayout(){
	var height=Math.max(Math.max(xHeight('mainColumnR'),xHeight('mainColumnC')+50),xHeight('mainColumnL'));
	if(xGetElementById('advBottom')){
		xTop('advBottom',height);
		xVisibility('advBottom',1);
		xTop('disclaimer',height+100);
	}else{
		xTop('disclaimer',height);
	}
	xVisibility('disclaimer',1);
}

function addMapMarker(lat,lon,image_url,html_text,center){
	mapPoint=new Array();
	mapPoint['lat']=lat;
	mapPoint['lon']=lon;
	mapPoint['image_url']=image_url;
	mapPoint['html_text']=html_text;
	mapPoint['center']=center;
	mapPoints[mapPoints.length]=mapPoint;
}

// Create a base icon for all of our markers that specifies the
// shadow, icon dimensions, etc.
var baseIcon = new GIcon();
baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
baseIcon.iconSize = new GSize(20, 34);
baseIcon.shadowSize = new GSize(37, 34);
baseIcon.iconAnchor = new GPoint(9, 34);
baseIcon.infoWindowAnchor = new GPoint(9, 2);
baseIcon.infoShadowAnchor = new GPoint(18, 25);

// Creates a marker whose info window displays the letter corresponding
// to the given index.
function createMarker(point, html_text, index) {
  // Create a lettered icon for this point using our icon class
  var letter = String.fromCharCode("A".charCodeAt(0) + index);
  var letteredIcon = new GIcon(baseIcon);
  letteredIcon.image = "http://www.google.com/mapfiles/marker" + letter + ".png";

  // Set up our GMarkerOptions object
  markerOptions = { icon:letteredIcon };
  var marker = new GMarker(point, markerOptions);

  GEvent.addListener(marker, "click", function() {
    marker.openInfoWindowHtml(html_text);
  });
  return marker;
}

window.onload = function(){ 
	adjustLayout();
	load();
	//init base Icon for Google Map Pointers
	baseIcon = new GIcon();
	baseIcon.iconAnchor = new GPoint(9, 34);
	baseIcon.shadow = null;
	baseIcon.infoWindowAnchor = new GPoint(9, 2);
}

function display(){
	if(xDisplay('map') == 'block'){
		xDisplay('map','none');
		xDisplay('flash','block');
		xDisplay('show_map','block');
		xDisplay('show_visual','none');
	}else{
		xDisplay('map','block');
		xDisplay('flash','none');
		xDisplay('show_map','none');
		xDisplay('show_visual','block');
		load();
	}
}

function showImage(img_path){
	return PopupPic(img_path);
}

function PopupPic(sPicURL) {
	window.open( "popup.htm?"+sPicURL, "_popup_image","resizable=1,HEIGHT=200,WIDTH=200");
}

