$(document).ready(function(){
    $("a[rel=popup]").click(function() {
        var sUrl = this.href;

        if (sUrl.indexOf("javascript") < 0)
            window.open(sUrl);
        else {
            setTimeout(sUrl.replace("javascript:", ""), 0);
        }

        return false;
    });

    $("a[rel=popup]").bind("onkeydown", function() {
        if (sUrl.indexOf("javascript") < 0)
            window.open(sUrl);
        else
            setTimeout(sUrl, 0);

        return false;
    });

/*///////////// TOOLS //////////////////////////////*/
	try {
		$(".items a").overlay({
			target: '#gallery',
			expose: '#000000'
		
		}).gallery({
			speed: 800,
			template: '<strong>${title}</strong> <span>Foto ${index} di ${total}</span>'
		});
	} catch(e) {
		
	}
	
	$("input[type=text]").addClass("inputtext");
	
/*/////// SROLLER PHOTOGALLERY /////////////////////////////////////*/	
	try {
		$("div.scrollable").scrollable({
			size: 6
		// ... the rest of the configuration properties 
		}).mousewheel();
	} catch(e) {
		
	}

	
/*//////////////////////// BIG TARGET ////////////////////////////////////////////////////////////////////////////////////////*/

	$(".titoloNews a").bigTarget({	   		
        clickZone : 'div:eq(0)',
        hoverClass: 'contenutoNewsOver'
    });

	
	$(".news a").bigTarget({	   		
        clickZone : 'div:eq(0)',
        hoverClass: 'newsOver'
    });
	
	
	$(".filiale a").bigTarget({	   		
        clickZone : 'div:eq(0)',
        hoverClass: 'filialeOver'
    });
	
	


/*//////////////////// TOOLTIP ////////////////////////////////////////////////*/

	$('.subNav li a').tooltip({
		showURL: false,
		track: true,
		fade: 0,
		left: 26,
		top: -22
	});	

	
	$('.listaIconeSx2 li a').tooltip({
		showURL: false,
		track: true,
		fade: 0,
		left: -45,
		top: -50
	});	
	
	
	
	$('.elementoBlocchi li a').tooltip({
		showURL: false,
		fade:  0,
		track: true,
		left: -90,
		top: -80
	});	
	
});



// GOOGLE MAPS 
function caricaCoordinate(luogo, tipo, id){
	if(luogo != undefined && luogo != ''){
		$.getJSON('carica_coordinate.php', 
   					{
   					luogo: luogo,
					tipo: tipo,
					id: id
   					}, 
   					caricaCoordinate2);
	}
}
	
	function caricaCoordinate2(data){
	if($("#map").length > 0){ //se esiste la mappa di google allora ricarico le coordinate...
			posizionaMarker(data['lat'], data['lon'], data['zoom']);
	}
	//setto l'id della via trovata nella form...
	$("#viaID").val(data['id']);
}

function posizionaMarker(lat, lon, zoom) {
		//cancello tutti i marker della mappa...
	mgr.clearMarkers();
	
		if(lat == '' && lon == '' && zoom == ''){
			lat = 41.90125491287279;
			lon = 12.49420166015625;
			zoom = 6;
		}
		
		zoom = Number(zoom);
		latlng = new GLatLng(lat, lon);
	marker = new_marker(latlng);
		//marker.setLatLng(latlng);
	markers.push(marker);
	mgr.addMarkers(markers, 0, 17);
	mgr.refresh();
				
	map.setCenter(latlng, zoom);
	
	}
	
function new_marker(latlng){
	
	var icon = new GIcon(G_DEFAULT_ICON);
   	icon.image = "http://www.bcccarate.it/images/marker.png";
    //icon.iconAnchor = new GPoint(16, 16);
    //icon.infoWindowAnchor = new GPoint(16, 0);
    //icon.iconSize = new GSize(32, 32);
    //icon.shadowSize = new GSize(59, 32);
	
	return new GMarker(latlng, { icon:icon });
}

