/* Funzioni ------------------------------------------------------------------------ */

	function hideLoader() {

		document.getElementById('pageLoader').style.visibility="hidden";
		document.getElementById('pageLoaderContent').style.visibility="hidden";

	}

	function targetBlank() {

		var i = 0;
		var collegamenti = document.links;

		for (i=0; i<collegamenti.length; i++) {

			if (collegamenti[i].title == "Link esterno" || collegamenti[i].title == "Lien externe" || collegamenti[i].title == "External link") {

				collegamenti[i].target = "_blank";

			}

		}

	}

	function isFilled(fieldList,isHtmlEditor) {

		var checkFields = fieldList.split("@");
		var check = true;

		if (isHtmlEditor) {

			tinyMCE.triggerSave();

		}

		for (i=0; i<checkFields.length; i++) {

			if (document.getElementById(checkFields[i])) {
				if (document.getElementById(checkFields[i]).value=="") {

					document.getElementById(checkFields[i]+'_alert').innerHTML = "<img src='img/layout/icoAlert.png' alt='' title='' />";
					check = false;

				} else {

					document.getElementById(checkFields[i]+'_alert').innerHTML = "";

				}
			} else {
				/* alert("DEBUG : campo non presente."); */
			}
		}

		return check;

	}

	function openGallery(idGallery) {

		$("#mainDx").html("<img src='img/layout/loader.gif' alt='' title='' />");

		$.get("call/getGalleryImage.inc.php?idGallery="+idGallery+"&currNumber=", function(data) {

			if (data.indexOf("viewedImage")!=-1) {
				
				/* MP3 player (DEPRECATO)
				play();
				*/

				$.get("call/getGalleryInfo.inc.php?idGallery="+idGallery, function(infodata) {

					$("#infoGallery").html(infodata);
					$("#infoGallery").show();
				});
			}

			$("#mainDx").html(data);

			tb_init('a.thickbox, area.thickbox, input.thickbox');

			/* $("#changeExplain").show(); */
			$("#changeLink").show();

			$('#menuGalleriesContainer').slideUp("fast");
		});
	}

	function loadImage() {

		/* MP3 player (DEPRECATO)
		play();
		*/

		var idGallery = $("#idGallery").val();
		var currNumber = $("#currNumber").val();

		$("#singleImage").html("<img src='img/layout/wloader.gif' alt='' title='' id='imageLoader' />");

		$.get("call/getGalleryImage.inc.php?idGallery="+idGallery+"&currNumber="+currNumber, function(data) {

			$("#singleImage").html(data);

			tb_init('a.thickbox, area.thickbox, input.thickbox');
		});
	}

	function listGalleries(idCat) {

		$("#menuGalleriesContainer").css("width","410px");

		if (document.getElementById('menuGalleriesContainer').style.display=="block") { $('#menuGalleriesContainer').hide(); }

		$.get("call/listGalleries.inc.php?idCat="+idCat, function(data) {

			$("#menuGalleriesContainer").html(data);
			$('#menuGalleriesContainer').slideDown("normal");
		});
	}

	function openSubMenu(idMenu) {

		$("#menuGalleriesContainer").css("width","195px");

		if (document.getElementById('menuGalleriesContainer').style.display=="block") { $('#menuGalleriesContainer').hide(); }

		$.post("call/getSubMenu.call.php",{ 
       			id_menu: idMenu
     		}, function(data) {
/*
			var newPosition = parseInt(document.getElementById('mainMenu').offsetLeft) + 18 - 1;
			$("#slaveMenuContainer").css("left",newPosition+"px");
*/
			$("#menuGalleriesContainer").html(data);
			$('#menuGalleriesContainer').slideDown("normal");
 		});
	}

	function loginGallery() {

		$.post("call/getGalleryImage.inc.php",{ 
       			idGallery: $("#idGallery").val(),
			pwd: $("#pwd").val()
     		}, function(data) {

			$("#mainDx").html(data);

			tb_init('a.thickbox, area.thickbox, input.thickbox');

			/* $("#changeExplain").show(); */
			$("#changeLink").show();

 		}); 
	}

	function startMap() { 

		var mapArea = "geoMap";
		var lat = "46.233892";
		var long = "6.126294";
		var popupMessage = "";
		var zoom = 17;

		load(mapArea,lat,long,popupMessage,zoom);
	}

	function discardMap() { 

		/* GUnload(); */
	}

	function viewGallery(idGallery) {

		$("#mainDx").html("<img src='img/layout/loader.gif' alt='' title='' />");

		$.get("call/getGallery.inc.php?idGallery="+idGallery, function(data) {

			$("#mainDx").html(data);

			tb_init('a.thickbox, area.thickbox, input.thickbox');

			$("#changeExplain").hide();
			$("#changeLink").hide();
		});
	}

	function setValue(field) {

		$("#"+field).val('');

	}

	function testValue(field) {

		if ($("#"+field).val()=="") { $("#"+field).val($("#"+field+"-label").val()); }

	}

	function subscribeNewsletter() {

		$.post("call/regEmail.call.php",{
       			address: $("#user-email").val()
     		}, function(data) { 

			alert(data);
 		}); 
	}

/* --------------------------------------------------------------------------------- */

/* Preload ------------------------------------------------------------------------- */

	$(document).ready(function() {
		$.ajax({
			url: "media/clack.mp3",
			success: function() {}     
		});
	});

/* --------------------------------------------------------------------------------- */

/* Load all'avvio ------------------------------------------------------------------ */

	window.addEventListener?window.addEventListener("load",hideLoader,false):window.attachEvent("onload",hideLoader);
	window.addEventListener?window.addEventListener("load",targetBlank,false):window.attachEvent("onload",targetBlank);
	window.addEventListener?window.addEventListener("load",startMap,false):window.attachEvent("onload",startMap);

	window.addEventListener?window.addEventListener("unload",discardMap,false):window.attachEvent("onunload",discardMap);

/* --------------------------------------------------------------------------------- */

/* Load alla chiusura -------------------------------------------------------------- */

	window.addEventListener?window.addEventListener("unload",discardMap,false):window.attachEvent("onunload",discardMap);

/* --------------------------------------------------------------------------------- */

/* Google Map ---------------------------------------------------------------------- */

	//<![CDATA[ 

	/*var zoom=17; */
	var debug=false; 

	function v2__load(nomeDiv,lat,long,SMS,zoom) {

		if (document.getElementById(nomeDiv)) {

		var latitudine = lat; 
		var longitudine = long; 
		var messaggio=SMS; 

		zoom = parseInt(zoom);

		document.getElementById(nomeDiv).style.display = "";
 
		if (debug) document.getElementById("debug").style.display="block"; 
		if (GBrowserIsCompatible()) { 
			var map = new GMap2(document.getElementById(nomeDiv)); 
			map.addControl(new GSmallMapControl()); 
			map.addControl(new GMapTypeControl()); 

			if (debug) { 
				GEvent.addListener(map, "moveend", function() { 
					var center = map.getCenter(); 
					document.getElementById("debug").innerHTML = center.toString();}); 

					GEvent.addListener(map, "click", function(marker, point) { 
					if (point) 
					document.getElementById("debug").innerHTML = point.toString();
				}); 
			} 

			map.setCenter(new GLatLng(latitudine, longitudine), zoom); 

			var point = new GLatLng(latitudine,longitudine); 

			/* PERSONALIZZAZIONE MARKER */
			var customIcon = new GIcon(G_DEFAULT_ICON, "img/layout/dotMap.png", null , "img/layout/dotMapShadow.png"); 
			customIcon.iconSize=new GSize(20,34); 
			customIcon.shadowSize=new GSize(37,34);
			var marker = new GMarker(point,customIcon);

			/* MARKER DI DEFAULT: var marker = new GMarker(point); */ 

			if (messaggio!="") {

				GEvent.addListener(marker, "click", function() { 
					marker.openInfoWindowHtml(messaggio);
				})
			} 

			map.addOverlay(marker); 

		} 

		}
	} 

	var geocoder;
	var map;

	function load(nomeDiv,latitude,longitude,popContent,zoomLevel) {

		if (document.getElementById(nomeDiv)) {

			var latlng = new google.maps.LatLng(latitude,longitude);

			var opt = { 
				center:latlng,
				zoom:zoomLevel,
				mapTypeId: google.maps.MapTypeId.ROADMAP,
				disableAutoPan:false,
				navigationControl:true,
				navigationControlOptions: {style:google.maps.NavigationControlStyle.SMALL },
				mapTypeControl:true,
				mapTypeControlOptions: {style:google.maps.MapTypeControlStyle.DROPDOWN_MENU}
			};

			map = new google.maps.Map(document.getElementById(nomeDiv),opt);

			var image = new google.maps.MarkerImage('img/layout/dotMap.png',
				new google.maps.Size(20,34) /* Dimensioni in pixel */,
				new google.maps.Point(0,0) /* Origine dell'immagine */,
				new google.maps.Point(10,34) /* Punto di ancoraggio */);

			var shadow = new google.maps.MarkerImage('img/layout/dotMapShadow.png',
				new google.maps.Size(37,34),
				new google.maps.Point(0,0),
				new google.maps.Point(10,34));

			var isClickable = false;

			if (popContent!="") {

				isClickable = true;
			}

			var marker = new google.maps.Marker({
				map: map,
				position: latlng,
				clickable: isClickable,
				icon: image,
				shadow: shadow
			});

			if (popContent!="") {

				var infowindow = new google.maps.InfoWindow({
					content: popContent
				});

				google.maps.event.addListener(marker, 'click', function() {
					infowindow.open(map,marker);
				});
			}
		}
	}

	//]]>

/* --------------------------------------------------------------------------------- */
