var gmap;
var geocoder ;
var overlayvw;
var latLngControl;
var desiredPoint = new google.maps.Point(160,530);
gmapClick = function(data) {
	//alert(data.latLng.lng());  
}

gmapCallback = function(results, status) {
				
	if (status == google.maps.GeocoderStatus.OK) {
	  if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
		
		gmap.setCenter(results[0].geometry.location);
		google.maps.event.addListener(gmap,'click',gmapClick);
								 
		
		var marker = new google.maps.Marker({
			map: gmap, 
			position: results[0].geometry.location
		});
		
		//traduco le coordinate geografiche in coordinate su schermo
		var thePoint = latLngControl.getPoint(results[0].geometry.location);
		var shiftX = thePoint.x - desiredPoint.x;
		var shiftY = thePoint.y - desiredPoint.y;
		
		
		gmap.panBy(shiftX,shiftY);
		
		
	  } else {
		alert("Google non ha trovato l'indirizzo che hai cercato.");
	  }
	} else {
	  alert("Geocode was not successful for the following reason: " + status);
	}

}

changemap = function(zoom) {
	gmap.setZoom(zoom);
	geocoder.geocode(
		{'address': 'Piazza Faravelli Località Moneta 07024 Isola La Maddalena'},
		gmapCallback
	);
	
}


function resizeMap() {
	var hieOffset = 0;
	var wieOffset = 0;
	// Target anything above IE6
	if ($.browser.msie && $.browser.version >= 6 ) {
		hieOffset = 5;
		wieOffset = 22;
	}
	
	$('#lamappa').width($('body').width()-wieOffset);
	$('#lamappa').height($('body').height()-hieOffset);

}

$(window).resize(
	function () {
		resizeMap();
	}
);


var slide_horiz ;
$(document).ready(function(){
	/*if($.url.param("loc")){
		$('#'+$.url.param("loc")).click();
	}else{
		loadFlash("../flash/gallery_home.swf");
	}
	if(document.location.href.match('booking.php')){ 		$('#booking').addClass('act');	}
	if(document.location.href.match('bookingInfo.php')){	$('#booking').addClass('act');	}
	
	if(document.location.href.match('contact.php')){		$('#contact').addClass('act');	}
	
	if(document.location.href.match('offerte.php')){ 		$('#offerte').addClass('act');	}
	if(document.location.href.match('offerta01.php')){ 		$('#offerte').addClass('act');	}
	if(document.location.href.match('offerta02.php')){ 		$('#offerte').addClass('act');	}
	if(document.location.href.match('offerta03.php')){ 		$('#offerte').addClass('act');	}
	if(document.location.href.match('offerta04.php')){ 		$('#offerte').addClass('act');	}*/
	

	slide_horiz = new Spry.Effect.Slide('slideItHorizontal', {horizontal: true, toggle: true});
	
});

$(document).ready(function() {
		if( ! document.location.href.match('bookingInfo.php') ){
		//	$("#content").draggable({ cursor: 'move' , scroll: false });
		}
		resizeMap();
				
		var myOptions = {
			zoom: 11,
			mapTypeId: google.maps.MapTypeId.TERRAIN
		};
		
		$('#lamappa').text('documento pronto');
		gmap = new google.maps.Map(document.getElementById("lamappa"), myOptions);
		geocoder = new google.maps.Geocoder();
		latLngControl = new LatLngControl(gmap);
		geocoder.geocode(
			{'address': 'Piazza Faravelli Località Moneta 07024 Isola La Maddalena'},
			gmapCallback
		);
	}
)
			
sliderIsHidden = function()
{
	return ($('#slideItHorizontal').width() == 0);
}	

sliderIsVisible = function(){return !sliderIsHidden();}

clickComeFromMenu = function(element){
		return $(element).hasClass('menuVoice');	
}

clickComesFromUnselectedMenuVoice = function(element){
		return $(element).hasClass('menuVoice') && !$(element).hasClass('act') ;	
}

toggleSlider = function(element)
{
	e = $(element);
	if ( ( ! clickComeFromMenu(e) && sliderIsVisible() ) || (clickComeFromMenu(e) && sliderIsHidden()) )
	{
		slide_horiz.start();
		clickOnMenu(e);
	}else if( clickComesFromUnselectedMenuVoice(e) ){
		clickOnMenu(e);
		
	}
	
	
}

removeAllActClass = function()
{
	$('ul.#listOne > li').each(function() { 
				$(this).children().first().removeClass('act'); 
			}
		);
}

clickOnMenu = function(element)
{
	e = $(element);
	if(e.hasClass('act'))
	{
		removeAllActClass();
	}else{
		removeAllActClass();
		e.addClass('act');
	}
}

loadFlash = function(fName){
	var flashvars = {};
	flashvars.languageID = "IT";
	var params = {
		wmode: 'transparent'
	};
	var attributes = {};
	swfobject.embedSWF(fName, "myFlash", "900", "485", "9.0.0", false, flashvars, params, attributes);
	$('flashElement').movie = fName;
}



  
		
		

navigateTo = function(element, flashName, mapValue){
	if(document.location.href.match('index.php'))
	{
		toggleSlider(element);
		loadFlash(flashName);
		changemap(mapValue);
		return false;
	}
	
	document.location.href = 'index.php?loc=' + element.id;
	return false;

}


