function loadScript(src) {
    var script = document.createElement("script");
    script.type = "text/javascript";
    document.getElementsByTagName("head")[0].appendChild(script);
    script.src = src;
}
loadScript("http://win.tangheri.com/sonosergiofiles/thickbox-code/thickbox.js");

$(document).ready(function() {

    $(".fullpost").each(function(i){
        this.id = "fullpost_" + i;
        $("<div>").text("Continua leggendo il resto dell'articolo").addClass("read-more");/*.insertAfter("#fullpost_1").click(
        function(){
            $(this).prev().slideDown("slow");
            $(this).remove();
        });*/
    });
//Mappa Google
    var center= null;
    
    if (GBrowserIsCompatible()) {
        
        map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(37.233747, 15.190000), 12);
        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
        geocoder = new GClientGeocoder();
        map.enableDoubleClickZoom();
        //map.enableScrollWheelZoom();
        panokml= new GLayer("com.panoramio.all");
        map.addOverlay(panokml);
        banner = new GAdsManager(map,"ca-pub-7410292200996947",{minZoomLevel:12});
        banner.enable();
        
        
        

        //la mia posizione
        if (geocoder) {
            geocoder.getLatLng(
                "via fimia 27, 95100, Catania",
                  function(point) {
                    if (!point) {
                      alert(address + " non trovato");
                    } else {
                      var mymarker = new GMarker(point);
                      map.addOverlay(mymarker);
                    }
                  }
            );
        }
    }
//funzione per ingrandire la mappa
/*
    $("#map_canvas").hover(
      function () {
            center = map.getCenter();
            //alert(center);
            $(this).animate({ width: "900px" ,height:"550px"}, 1000,function () { 
            map.checkResize();
            map.panTo(center);
            map.addControl(new ExpandMap());
        });
      });
*/      


});

//FINE JQUERY
//funzione cerca indirizzo mappa google
var marker;
function showAddress(address) {
        if (geocoder) {
            geocoder.getLatLng(
                address,
                  function(point) {
                    if (!point) {
                      alert(address + " non trovato");
                    } else {
                      map.setCenter(point, 15);
                      marker = new GMarker(point);
                      map.addOverlay(marker);
                      marker.openInfoWindowHtml(address+"<br/><a href=\"javascript:getDirection"+point+"\">Raggiungimi</a>");
                    }
                  }
            );
        }
}

var directionsPanel;
var directions;

function getDirection(point1,point2) {
    map.clearOverlays();
    directionsPanel = document.getElementById("route");
    directions = new GDirections(map, directionsPanel);
    directions.load("from: "+point1+","+point2+" to: via fimia 27, 95100, Catania",{ "locale": "it" });
}
//Pulsante all'interno della mappa

function ExpandMap(){}
    
ExpandMap.prototype = new GControl();
ExpandMap.prototype.initialize = function(map) {
    var container = document.createElement("div");

    var zoomInDiv = document.createElement("div");
    container.appendChild(zoomInDiv);
    this.setButtonStyle_(zoomInDiv)
    zoomInDiv.appendChild(document.createTextNode("Chiudi"));
    GEvent.addDomListener(zoomInDiv, "click", function() {
        center = map.getCenter();
        $("#map_canvas").animate({ width: "420px" ,height:"300px"}, 1000,function () { 
            map.checkResize();
            map.panTo(center);
        });
    });
    map.getContainer().appendChild(container);
    return container;
}
ExpandMap.prototype.getDefaultPosition = function() {
    return new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(7, 12));
}
    
    // Sets the proper CSS for the given button element.
ExpandMap.prototype.setButtonStyle_ = function(button) {
  button.style.textDecoration = "underline";
  button.style.color = "#0000cc";
  button.style.backgroundColor = "white";
  button.style.font = "small Arial";
  button.style.border = "1px solid black";
  button.style.padding = "2px";
  button.style.marginBottom = "3px";
  button.style.textAlign = "center";
  button.style.width = "6em";
  button.style.cursor = "pointer";
}
//carico le immagini dell'album di picasa
var picasakml= 0;
function picasa(){
    if (!picasakml){
        picasakml = new GGeoXml("http://picasaweb.google.it/data/feed/base/user/sonosergio?alt=kml&kind=album&hl=it_IT&access=public");
        map.addOverlay(picasakml);
        $("#picasa").addClass("selected");
    }
    else{
        map.removeOverlay(picasakml);
        picasakml=0;
        $("#picasa").removeClass("selected");
    }
}
//carico wikipedia
var wikikml= 0;
function wiki(){
    if (!wikikml){ 
        wikikml=new GLayer("org.wikipedia.it");
        map.addOverlay(wikikml);
        $("#wikipedia").addClass("selected");
    }
    else{
        map.removeOverlay(wikikml);
        $("#wikipedia").removeClass("selected");
        wikikml=0;
    }
}
//scarico e carico panoramio
function panoramio(){
    if (!panokml){ 
        panokml=new GLayer("com.panoramio.all");
        map.addOverlay(panokml);
        $("#panoramio").addClass("selected");
    }
    else{
        map.removeOverlay(panokml);
        $("#panoramio").removeClass("selected");
        panokml=0;
    }
}