$(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;
    });

	
	/*////////// SEZIONE FORM ELENCO OFFICINE /////////////////////////////////////////////////////////*/

														
			$('.ico-citta').hover(function() {
          		$('.apparitoreUp').show();
				$('.apparitoreDown').hide();
            }, function() {
               $('.apparitoreUp').hide();
            });
                       	
			$('.apparitoreUp').hover(function () {
                $(this).show();
				$('.apparitoreDown').hide();
                }, function () {
               	$(this).hide();
			});

			
			$('.ico-raggio').hover(function() {
          		$('.apparitoreDown').show();
				$('.apparitoreUp').hide();
            }, function() {
               $('.apparitoreDown').hide();
            });
                       	
			$('.apparitoreDown').hover(function () {
                $(this).show();
				$('.apparitoreUp').hide();
                }, function () {
               	$(this).hide();
			});
			
				
			
			$('.btn2 a').click(function() {
          		$('.apparitore03').show();
				return false;
            });
                       	
			$('.apparitore03').hover(function () {
                $(this).show();
                }, function () {
               	$(this).hide();
			});	
				
				

	/*////////// BIG TARGET /////////////////////////////////////////////////////////////////////////*/
	
	
	$(".riga a.continua").bigTarget({
		clickZone: 'div:eq(1)',
		hoverClass: 'sfondoOver' 
	});

	$(".sfondino .minithumb a").bigTarget({
		clickZone: 'div:eq(1)',
		hoverClass: 'sfondinoOver' 
	});
	
	
	
	$(".sfondoOfficina a").bigTarget({
		clickZone: 'div:eq(1)',
		hoverClass: 'officinaOver' 
	});
	
	/*//////// PHOTOGALLERY ////////////////////////////////////////////////////////////////////////*/
	
	if($(".photogallery").length > 0){
	
    	$("div.scrollable").scrollable({
    			// one configuration property 
    			size: 6
    		// ... the rest of the configuration properties 
    	}).mousewheel();
    	
    	
    	/*//////// OVERLAY ////////////////////////////////////////////////////////////////////////////*/

    	$(".thumbGallery a").overlay({
    		target: '#gallery',
    		expose: '#000000'
    		
    	}).gallery({
    		speed: 800,
    		template: '<strong>${title}</strong> <span>Foto ${index} di ${total}</span>'
    	});
    	
    	
    	$('.simple_overlay .close').addClass('png_bg');
	}


	/*//////////// TOOLTIP ////////////////////////////////////////////////////////////////////////////////////////*/
	
		$("ul li abbr").tooltip('.tooltip'); 

	
	/*/////////// SEZIONE DELLE FAQ //////////////////////////////////////////////////////////////////////////////*/
	
	
	// close the offDiv content sections
          
		  
		 //(doing this with js instead of css means if no js, content is all visible)
         $('.paragrafoSupporto > .testoSupporto').hide();
         // show the correct buttons for each div
         // they are hidden with css for no-js users
         $('.paragrafoSupporto > .titoloDomanda .showLink').show();
         $('.paragrafoSupporto > .titoloDomanda .hideLink').hide();
                          
						       	
          // show all link
          $('a.showAll').click(function(e){
			e.preventDefault();																		
         $('#categoriaFaq' + $(this).attr('href') + ' .testoSupporto').slideDown('fast');
         $('#categoriaFaq' + $(this).attr('href') + ' .paragrafoSupporto').removeClass().addClass('paragrafoSupporto2');
         $('#categoriaFaq' + $(this).attr('href') + ' a.hideAll').show();
         $('#categoriaFaq' + $(this).attr('href') + ' a.hideLink').show();
         $('#categoriaFaq' + $(this).attr('href') + ' a.showLink').hide();    								
         return false;
         });
					
         // hide all link
         $('a.hideAll').click(function(e){
			e.preventDefault();
         $('#categoriaFaq' + $(this).attr('href') + ' .testoSupporto').slideUp('fast');
         $('#categoriaFaq' + $(this).attr('href') + ' .paragrafoSupporto2').removeClass().addClass('paragrafoSupporto');
         $('#categoriaFaq' + $(this).attr('href') + ' a.showLink').show();
         $('#categoriaFaq' + $(this).attr('href') + ' a.hideLink').hide();
         $('#categoriaFaq' + $(this).attr('href') + ' a.showAll').show();
         return false;
         });
                	
         // title is clickable, and toggles the content
         $(".paragrafoSupporto2 >.titoloDomanda").click( function() { 
         
		 	$(this).next("div").slideToggle('fast');
         	$(this).parent("div").toggleClass('paragrafoSupporto2');
            $(this).parent("div").toggleClass('paragrafoSupporto');
            $(this).siblings("a").toggle();                			
         });
                		 
         $(".paragrafoSupporto > .titoloDomanda").click( function() { 
           $(this).next("div").slideToggle('fast');
           $(this).parent("div").toggleClass('paragrafoSupporto');
           $(this).parent("div").toggleClass('paragrafoSupporto2');
           $(this).siblings("a").toggle();
         });		 
                		                     
         $(".titoloRosso").click( function() { 
           $(this).next("div").slideToggle('slow');
           $(this).siblings("a").toggle();
         });
});


// 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://eurorepar-it.axura.com/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 });
}
