var dom=(document.getElementById)?true:false;
var ns5=((navigator.userAgent.indexOf("Gecko")>-1)&&dom)?true:false;
var ie5=((navigator.userAgent.indexOf("MSIE")>-1)&&dom)?true:false;
var ns4=(document.layers&&!dom)?true:false;
var ie4=(document.all&&!dom)?true:false;
var nodyn=(!ns5&&!ns4&&!ie4&&!ie5)?true:false;
var origWidth,origHeight;
if(ns4){
	origWidth=window.innerWidth;
	origHeight=window.innerHeight;
	window.onresize=function(){if(window.innerWidth!=origWidth||window.innerHeight!=origHeight)history.go(0);}
}
if(nodyn){event="nope"}
var theDiv,divCSS;
function initDiv(){
	if(nodyn)return;
	theDiv=(ns4)?document.imgDiv.document:(ie4)?document.all['imgDiv']:(ie5||ns5)?document.getElementById('imgDiv'):null;
	divCSS=(ns4)?document.imgDiv:theDiv.style;
	if (ie4||ie5||ns5) {
		divCSS.backgroundColor = "#ffffff";
		divCSS.borderWidth = "1px";
		divCSS.padding = "5px";
		divCSS.borderStyle = "ridge";
	}
	if(theDiv){
		if(ns4)document.captureEvents(Event.MOUSEMOVE);
		document.onmousemove=trackMouse;
	}
}
window.onload=initDiv;
var t1,t2;
var imgOn=false;
function showImg(evt,theImg){
	if(!theDiv)return;
	if(t1)clearTimeout(t1);
	if(t2)clearTimeout(t2);
	imgOn=true;
	alert("2");
	if(ns4){
		theDiv.write('<img src="'+theImg+'" border="1" width="200" />');
		theDiv.close();
	}else if(ie4||ie5||ns5){
		theDiv.innerHTML='<img src="'+theImg+'" border="1" width="200" />';
	}
	t1=setTimeout("divCSS.visibility='visible'",100);
}
function trackMouse(evt) {
	var mouseX = (ns4||ns5)? evt.pageX: window.event.clientX + document.body.scrollLeft;
	var mouseY = (ns4||ns5)? evt.pageY: window.event.clientY + document.body.scrollTop;
	var tpWd = (ns4)? theDiv.width: (ie4||ie5)? theDiv.clientWidth: theDiv.offsetWidth;
	var tpHt = (ns4)? theDiv.height: (ie4||ie5)? theDiv.clientHeight: theDiv.offsetHeight;
	var winWd = (ns4||ns5)? window.innerWidth-20+window.pageXOffset: document.body.clientWidth+document.body.scrollLeft;
	var winHt = (ns4||ns5)? window.innerHeight-20+window.pageYOffset: document.body.clientHeight+document.body.scrollTop;
	if ((mouseX+20+tpWd)>winWd)
		divCSS.left = (ns4)? mouseX-(tpWd+20): mouseX-(tpWd+20)+"px";
	else divCSS.left = (ns4)? mouseX+20: mouseX+20+"px";
	if ((mouseY+12+tpHt)>winHt)
		divCSS.top = (ns4)? winHt-(tpHt+12): winHt-(tpHt+12)+"px";
	else divCSS.top = (ns4)? mouseY+12: mouseY+12+"px";
}
function hideImg(){
	if(!theDiv)return;
	t2=setTimeout("divCSS.visibility='hidden'",100);
	imgOn=false;
}

function checkformpreventivo() {
	var commento = document.getElementById("commento");
	var email = document.getElementById("email");	
	var alertmsg2 = document.getElementById("alertmsg");	
	if(commento.value.length == 0 || email.value.length == 0) {
		alertmsg2.className='alertvisible';
		return false;
	} else {
		return true;	
	}
}
function startmenu()
{
	document.getElementById('menu1').style.display = "none";
	document.getElementById('menu2').style.display = "none";
	document.getElementById('menu3').style.display = "none";
}

function menufunc(menuId)
{
	if(document.getElementById(menuId).style.display == "none")
	{
		startmenu();
		document.getElementById(menuId).style.display = "block";
	}
	else
	{
		startmenu();
	}
}




function initialize(punto_interesse) {
	if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById("map"));
		var center = new GLatLng('43.815724', '11.223230');
		var indirizzo = "Via Pietro Fanfani 111A";
		var cap = "50127";
		var testo_descrittivo = "<b>Unosistemi</b><br />"+indirizzo+"<br />"+cap+" Firenze<br /><a href=\"javascript:streetview()\" style=\"font-weight:bold;\">Street view</a>";
		if(punto_interesse==0)
			map.setCenter(center, 13);
		map.addControl(new GMapTypeControl());
		map.setMapType(G_HYBRID_MAP);
		map.addControl(new GLargeMapControl());
		map.addControl(new GScaleControl());
		if(punto_interesse==0) 
			map.openInfoWindow(center, testo_descrittivo);
		var icon = new GIcon();
		//icon.image = "http://www.unosistemi.net/img/marker.png";
		icon.iconSize = new GSize(36, 40);
		icon.shadow = "http://www.unosistemi.net/images/shadow.png";
     	icon.shadowSize = new GSize(57, 40);
		icon.iconAnchor = new GPoint(5, 34);
      	icon.infoWindowAnchor = new GPoint(50, 20);
		icon.iconAnchor = new GLatLng('43.815724', '11.223230');
		icon.infoWindowAnchor = new GLatLng('43.815724', '11.223230');
		
		var marker = new GMarker(center, icon);
		
		GEvent.addListener(marker, 'mouseover', function() {
			marker.openInfoWindow(testo_descrittivo);
		});
		map.addOverlay(marker);
		var div_tasto_map = document.getElementById("return_map");
	  	div_tasto_map.style.display='none';
	/*	if(punto_interesse==0) {
			GDownloadUrl("/creaxml.php?id_ap=<?php echo $id_apartment;?>", function(data) {
				var xml = GXml.parse(data);
				var markers = xml.documentElement.getElementsByTagName("marker");
				for (var i = 0; i < markers.length; i++) {
					var denom = markers[i].getAttribute("denom");
					var foto_punto_int = markers[i].getAttribute("foto_punto_int");
					var	point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
					parseFloat(markers[i].getAttribute("long")));
					var marker2 = createMarker(point, denom, foto_punto_int, punto_interesse);
					map.addOverlay(marker2);
				}
			});
		} else {
			GDownloadUrl("/creaxml.php?id_punto="+punto_interesse, function(data) {
				var xml = GXml.parse(data);
				var markers = xml.documentElement.getElementsByTagName("marker");
				for (var i = 0; i < markers.length; i++) {
					var denom = markers[i].getAttribute("denom");
					var indirizzo_punto_int = markers[i].getAttribute("indirizzo");
					var cap_punto_int = markers[i].getAttribute("cap");
					var citta_punto_int = markers[i].getAttribute("citta");
					var foto_punto_int = markers[i].getAttribute("foto_punto_int");
					var lat_punto_int = parseFloat(markers[i].getAttribute("lat"));
					var long_punto_int = parseFloat(markers[i].getAttribute("long"));
					var	point = new GLatLng(parseFloat(markers[i].getAttribute("lat")), parseFloat(markers[i].getAttribute("long")), 9);
					var marker2 = createMarker(point, denom, foto_punto_int, punto_interesse);
					map.addOverlay(marker2);
					var directionsPanel = document.getElementById("my_textual_div");

      				var directions = new GDirections(map, directionsPanel);
      				//directions.load("from: "+indirizzo+", Firenze, "+cap+" to: "+indirizzo_punto_int+", "+citta_punto_int+", "+cap_punto_int, {"locale": "en_US"}, G_TRAVEL_MODE_DRIVING);				
      				directions.load("from: <?php echo $rowAp["latitudine"]?>, <?php echo $rowAp["longitudine"]?> to: "+lat_punto_int+", "+long_punto_int, {"locale": "en_US"}, G_TRAVEL_MODE_DRIVING);				
	
				}
			});
		}*/
	}
}
function createMarker(point, denom, foto_punto_int, punto_interesse) {
var marker = new GMarker(point);
var html = "<b>"+denom+"</b><br /><img src=\"<?php echo $dominio?>/foto/firenze/"+foto_punto_int+"\" alt=\"\" width=\"100\" height=\"77\" style=\"border:1px solid #3461bf;\">";
GEvent.addListener(marker, 'mouseover', function() {
	marker.openInfoWindowHtml(html);
});
return marker;
}
var myPano;
function streetview() {
  var fenwayPark = new GLatLng('43.815724', '11.223230');
  panoramaOptions = { latlng:fenwayPark };
  myPano = new GStreetviewPanorama(document.getElementById("map"), panoramaOptions);
  GEvent.addListener(myPano, "error", handleNoFlash);
  var div_tasto_map = document.getElementById("return_map");
  div_tasto_map.style.display='block';
}

function handleNoFlash(errorCode) {
  if (errorCode == FLASH_UNAVAILABLE) {
	alert("Error: Flash doesn't appear to be supported by your browser");
	return;
  }
} 

function showvideo() {
	document.getElementById("video").style.display="block";
}
function hidevideo() {
	document.getElementById("video").style.display="none";
}

