var map;
var center;

function animate(oggetto){
    //tempo random dell'animazione
    var time=Math.floor(50000+Math.random()*50000);
    if(oggetto==1)
    {
    //lo squalo
    var height= Math.floor(100+Math.random()*60);
    $('#object1').animate({
            left: '+=1900'
        }, time,'linear', function() {
        $('#object1').css( "left", -300 );
        $('#object1').css( "top", height );
        animate(oggetto);
        });
    }
    else
    {
        var height= Math.floor(100+Math.random()*160);
        $('#object2').animate({
            left: '-=1800'
        }, time,'linear', function() {
        $('#object2').css( "left", 1600 );
        $('#object2').css( "top", height );
        animate(oggetto);
        });
    }    
}

$(document).ready(function(){
    
    //$("#dialog").dialog();
    /*
    $('#object2').animate({
        left: '-=1600'
    }, 100000,'linear', function() {
    // Animation complete.
    });
    
    $('#object1').animate({
        left: '+=1600'
    }, 100000,'linear', function() {
    // Animation complete.
    });
    
    */
    //animate(1);
    //animate(2);
    //$(".readmore").before("<p>Leggi ancora...</p>");
    var ct = $(".post").size();
    if(ct > 1){
		$(".readmore").css("display","none");
		$(".post").each(function(index) {
			var idpost= $(this).children("a").attr('name');
			$(this).attr("id",idpost);
			$(this).children(".post-body").children(".readmore").attr('id','more-'+idpost);
			$("<a style='font-weight:bold; cursor:pointer;' class='viewrm' id='rm-"+idpost+"'>Leggi ancora...</a>").insertBefore($(this).children(".post-body").children(".readmore"));
		});
		//per leggere tutto l'articolo
		$(".viewrm").click(function () { 
		  var tmp= this.id;
		  tmp=tmp.split("-");
		  tmp=tmp[1];
		  $(this).slideUp(); 
		  $("#more-"+tmp).slideDown();
		});
		//per far comparire solo un giorno alla volta
		/*
		var i=0;
		$(".date-posts").each(function(index) {
			$(this).attr("id","day"+i);
			if(i > 0)
				$(this).css("display","none");
			i++;
		});
		*/
	}
	var t=1;
	$("#navbar").hover(
	  	function () {
	  		if(t==1)
			$("#Navbar1").fadeIn(function () {
				t=0;
				});
	  	}, 
  		function () {
  			if(t==0)
    		$("#Navbar1").fadeOut(function () {
				t=1;
				});
  		}
	);
	var currentTime = new Date()
	var ora = currentTime.getHours() 
	//alert(ora);
	/*
	if(ora > 8 && ora <= 10)
		$("body").css('background','url("http://themes.googleusercontent.com/image?id=1fswGecVIxUR-lGZKqTZv8BWloSEtkTzRCx8sQGB3N7bf_pksGf6R9-1HCrCdu7HRtr2H") no-repeat fixed center top #3C352D');
    if(ora > 10 && ora <= 12)
		$("body").css('background','url("http://themes.googleusercontent.com/image?id=1ZygE97_U_mmMOtoTGkMZll-JNbyfsqhAUw6zsMRGgk4ZzWbQsBOLV5GkQDV8YuZ0THk0") repeat scroll center top #AD966C');
    if(ora > 12 && ora <= 14)
		$("body").css('background','url("http://themes.googleusercontent.com/image?id=1DUGuUZZVgme1NrK8EZNhuYce4LwJ9r9X6h8IiXRxnN4BiiAOyuLkHr4OOMmmtMneEiLz") no-repeat fixed center top #A3D848');
    if(ora > 14 && ora <= 16)
		$("body").css('background','url("http://themes.googleusercontent.com/image?id=0BwVBOzw_-hbMNTJjY2M1MmItM2Q5Ny00NmY5LTk5ZjItZWU2OGVhOTE0MTMw") no-repeat scroll center top #FFFEFF');
    */
    /*
    
    
    
    */
  	var checkmap = $("#map_canvas").size();
  	if(checkmap == 1)
  	{
  		initialize();
  		$("body").attr("onunload","GUnload()");
  	}
    $("#map_full_screen").click( function () {
      		$(".content-outer").animate({ width: "95%"}, 1000,function () {
				center = map.getCenter();
				//alert(center);
				$("#map_canvas").animate({ width: "100%" ,height:"600px"}, 1000,function () { 
					map.checkResize();
					map.panTo(center);
					map.addControl(new ExpandMap());
				});
			});
     });
     $("item").each(function(i) {
     
     });
    
	  // url: 'http://weather.yahooapis.com/forecastrss?p=ITXX0017&u=c',

	
});

function loadRSS() {
    $.get("http://weather.yahooapis.com/forecastrss?p=ITXX0017&u=c", function(data) {
        $(data).find("item").each(function(i, el) {
            var titolo = $(el).find("title").text();
            var desc = $(el).find("description").text();
              alert(titolo);
              alert(desc);
            //console.log(titolo);
            //console.log(collegamento);
        });
    });
}
//inizialiazza mappa di google
function initialize() {
   		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:6});
        banner.enable();
}
/**********************************************************************************/
//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 = "none";
  button.style.color = "#000000";
  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";
}
/**********************************************************************************/