$(document).ready( start );


// eseguita al caricamento della pagina

function start(){

	// ##### ---> angoli arrotondati
	
 	$("h1").corner(); 
 	// $("#smallmenu").corner(); // da errore in explorer
 	// $("#soluzioni h2").corner(); da errore in explorer

	// ##### ---> animazione nella pagina dei contatti
	
	if( $("div#contatti").size()!=0 ) {
		$("div#contatti > div.casella_contatto").corner();
		function animaBackground() {
			$("div#casella_contatto_1 > div").css("background","url('grafica/capoverso_verde.png') no-repeat 3% 0%");
			$("div#casella_contatto_2 > div").css("background","url('grafica/capoverso_arancio.png') no-repeat 3% 0%");
			$("div#casella_contatto_3 > div").css("background","url('grafica/capoverso_rosso.png') no-repeat 3% 0%");
			$("div#casella_contatto_4 > div").css("background","url('grafica/capoverso_blu.png') no-repeat 3% 0%");
			if ( $.browser.msie ) {
				$("div.casella_contatto h3").addClass("ie");
			}				
			$("div.casella_contatto span:first").fadeOut("slow").addClass("bianco").fadeIn("slow").animate({fontSize:'170%', marginRight:'17px'}, "slow");

		}
		setTimeout( animaBackground, 500);
	}
	
	// ##### ---> top menu: toglie il focus dal pulsante cliccato
	
	$("#top_menu a").focus( function(){
		$(this).blur()
	});
	
	// ##### ---> top menu: aggiusta l'altezza dei pulsanti in mozilla e msie
	
	if ($.browser.mozilla) { $("#top_menu a").css("height","100px") };
	if ($.browser.msie)    { $("#top_menu a").css("height","120px") };
	
	// ##### ---> top menu: aggiunge le icone e gestisce il click
	
	var immagine_menu=new Array();
	immagine_menu[0]="grafica/menu_home.png";
	immagine_menu[1]="grafica/menu_infestanti.png";
	immagine_menu[2]="grafica/menu_soluzioni.png";
	immagine_menu[3]="grafica/menu_contatti.png";
	
	$("#top_menu a")
		.each(
			function(key){
				$(this).append("<br><img src='" +immagine_menu[key]+ "' />");
				$(this).not(".attivo").children().filter("img").fadeTo("fast","0.5");
				$(this).not(".attivo").hover(function(){$(this).children("img").fadeTo("fast","1")},function(){$(this).children("img").fadeTo("fast","0.5")});
			}
		)
		.click( function () 
			{
			$("#top_menu a.attivo").removeClass("attivo").children("img").fadeTo("fast","0.5");
			$(this).toggleClass("attivo").children("img").fadeTo("fast","1");
			}
		)
	;

	// ##### ---> effetti del mio logo EMF

	$("img#emf_logo")
		.mouseover(function () 
			{
			$(this).fadeOut("fast").fadeIn("slow");
			}
		)
		.click(function()
			{
				$("div#footerCopyright")
					.append("<div id='emf_widget'><p><strong>Enrico M. Fumanti</strong></p><p>Idea, realizzazione e grafica<br>febbraio 2009<br>Scrivimi a: <a href='mailto:fumanti@gmail.com'>fumanti@gmail.com</a></p></div>")
				;
				$("#emf_widget")
					.fadeIn("slow")
					.click(function(){$("#emf_widget").fadeOut("slow")})
				;
			}
		)
	;
	
	// ##### ---> rollover "scarica skype"
	
	$("#img_scarica_skype").hover(
		function (){
			$(this).attr("src","grafica/downloadSkypeOn.png");
		},
		function (){
			$(this).attr("src","grafica/downloadSkype.png");
		}
	);

	// ##### ---> INFESTANTI: finestra dialog per ulteriori informazioni
	
/*	$("#infestanti a.leggiTutto, #infestanti a.leggiTuttoImg").click( function ( ) {
		xPosition=screen.availWidth - 350;
		if ($("#dialog").size()==0 ) {
			$("head").append('<script type="text/javascript" src="script/jquery-ui.js"></script><link type="text/css" href="script/theme/ui.all.css" rel="stylesheet" />');
			$("body").append("<div id=dialog></div>");
			$("#dialog").dialog({height:400, width: 300, position: [xPosition,"center"]  });
		} else {
			$("#dialog").dialog('open');
		}
		
		$("#dialog").dialog("option", "title", $(this).attr("title") );
		$("#dialog").html("<br><br><center><img src='grafica/loader.gif'></center>");
		
		//indirizzo="contenuti/documentazione-infestanti/" + $(this).attr("href") + ".php";
		indirizzo=$(this).attr("href");
		$.post( indirizzo, function(data){ $("#dialog").html(data) } );
		return false;
	});*/
	
	// ##### ---> ANIMAZIONE SMALLMENU
	
	$("#smallmenu > ul ul ").prev()
		.prepend(
  			"<img class='right' src='grafica/arrow.png'  />"
		)
		.click(
			function(){
				$("#smallmenu img.right").attr("src","grafica/arrow.png");
				$("#smallmenu > ul ul").slideUp("slow");

				if ( $(this).next().css("display")=="none") {
					$(this).children("img.right").attr("src","grafica/arrow_down.png");
					$(this).next().slideDown("slow" );
				}
				
				$("#smallmenu a").blur();
				return false;
			}
		);
	
	// ##### ---> ANIMAZIONE leggi_tutto

	$(".leggi_tutto > a").click(function(){
		dest = "#" + $(this).attr("title");
		$(dest).toggle("slow");
		if ($(this).text()=="leggi tutto") {
			$(this).text("nascondi");
		} else {
			$(this).text("leggi tutto");
		}
		$(this).blur();
		return false;
	});
	
	// ##### ---> MODIFICHE AL CSS per mozilla e msie
	
	if ($.browser.mozilla) {
		$("#smallmenu ul").addClass("ulMozilla");
	}
	if ($.browser.msie) {
		$("#smallmenu ul ul").addClass("sottomenuIe");
	}

	// ##### ---> CARICA GOOGLE MAPS nella pagina contatti

	if ( $("#contatti").size() > 0 ) {
		function inserisciMappa() {
			$("#mappa_google img").remove();
			$("#mappa_google").append('<iframe width="580" height="380" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.it/maps?f=q&amp;source=s_q&amp;hl=it&amp;geocode=&amp;q=roma,+via+monteleone+sabino+12&amp;sll=41.961788,12.642174&amp;sspn=0.138623,0.352936&amp;ie=UTF8&amp;ll=41.952724,12.603636&amp;spn=0.025533,0.052443&amp;z=14&amp;iwloc=addr&amp;output=embed"></iframe><br /><small><a href="http://maps.google.it/maps?f=q&amp;source=embed&amp;hl=it&amp;geocode=&amp;q=roma,+via+monteleone+sabino+12&amp;sll=41.961788,12.642174&amp;sspn=0.138623,0.352936&amp;ie=UTF8&amp;ll=41.952724,12.603636&amp;spn=0.025533,0.052443&amp;z=14&amp;iwloc=addr" style="text-align:left">Visualizzazione ingrandita della mappa</a></small>');
		}
		setTimeout (inserisciMappa,3000);
	}

	// ##### ---> allinea correttamente l'immagine ozon3

	$("img").filter("[alt=ozon3]").css("vertical-align","middle");

	// ##### ---> animazione banner ozon3 nella barra laterale

	function bannerSlide() {
		if ( $("img#ozon3Banner").attr("src")=="grafica/ozon3_textBanner_1.png" ) {
			immagine="grafica/ozon3_textBanner_2.png";
		} else {
			immagine="grafica/ozon3_textBanner_1.png";
		}
		$("img#ozon3Banner").animate(
			{
				marginTop: "180px",
				width:"0px"
			},
			"slow",
			"swing",
			function () {
				$(this).attr("src",immagine).css({marginTop:"-180px"}).animate(
					{
					marginTop:"0px",
					width:"200px"
					},
					"slow",
					"linear"
				)
			}
		);
	};
	animazione=setInterval(bannerSlide,4000);
	
	// ##### ---> animazione coccinella
	
	function animaCoccinella(){
		$("#coccinella").animate(
			{
				marginLeft:"+=50px"
			},
			3000,
			"swing",
			function() { 
				
				possibleStep=(screen.width-900)/2+250;
				
				if ( parseInt($(this).css("marginLeft")) > possibleStep ) {
					$(this).fadeOut().css("marginLeft","4px").fadeIn();
				}
				setTimeout(animaCoccinella,10000)
			}
		);
	}
	animazioneCoccinella=setTimeout(animaCoccinella,5000);

}

// ### fine "ready" ###



