$(document).ready( function () {

	menu_hover();

	logo_hover();

	angoli_arrotondati();

	galleria_immagini();

	toggle_qr_code_help(); // nella pagina contatti
	toggle_gpg_help();

	// stessa_altezza_riquadri_home(); // problema in ie7 (da verificare ie8)

	paperli();

	twitter();
});


function menu_hover() {
	$("#top_menu a").hover(
		function() {
			$(this)
				.css("position","relative")
				.animate(
					{
						top: "+=5px"
					}
					,"fast"
				);
		},
		function() {
			$(this).animate(
				{
					top:"-=5px"
				},"fast"
			);
		}
	);
}

function logo_hover() {
$("#header")
	.hover(
		function () {
			$(this).append(" <div id='header-wrapper'> <div id='header-title'>Enrico M. Fumanti</div> <div id='header-text'>Siti Web<br />Applicazioni Web</div> </div> ");
			$("#header-wrapper").fadeIn("slow");
		},
		function () {
			$("#header-wrapper").fadeOut("fast",function () { $(this).remove() });
		}
	)
	.css(
		{
			//cursor: "pointer"
		}
	)
	.click(
		function () {
			//alert("ciao");
			document.location="http://www.henrysmoking.it";
		}
	);
}

function addCorners(elemento,opzioni){
	if (! opzioni) opzioni="5px";
	$(elemento).corner(opzioni)
}

function angoli_arrotondati() {

	addCorners(".corners");

	$("#riquadri .riquadro").corner("bottom 10px"); // riquadri in home page
	$(".riquadro h3").corner("top 10px");
	$("#lista_news").corner("bottom");
	$("#lista_news h3").corner("top");
	$("#menu_utente").corner();

	$(".news_note").corner("top 7px"); // nella pagina news
	$(".news_body").corner("top bottom 7px");
	if ( ! $.browser.msie ) { // da errore in ie
		$(".news_icon img:first").corner("tl");
		$(".news_icon img:last").corner("br");
	}

	$("#qr_code_help").corner(); // nei pagina dei contatti
	$("#gpg_help").corner();

}

function galleria_immagini() {
	$("#portfolio a.fancy, #pagina_news a.fancy").fancybox(
		{
			'zoomOpacity' : true,
			'overlayShow' : false,
			'zoomSpeedIn' : 500,
			'zoomSpeedOut' : 500
		}
	);
	$("#mappa").fancybox(
		{
			'frameWidth':	600,
			'frameHeight':	400
		}
	);
	$("#contatti #qrcode").fancybox();
}

function toggle_qr_code_help () {
	$("#contatti #qr_code_p").append(" &nbsp [ <a class=\"help\" title=\"Cos'è un QR-Code? \">?</a> ]");
	$("#qr_code_p a.help").toggle(
		function () {
			$("#gpg_help").fadeOut();
			$("#qr_code_help").slideToggle();
		},
		function () {
			$("#gpg_help").fadeOut();
			$("#qr_code_help").slideToggle();
		}
	)
}

function toggle_gpg_help () {
	$("#contatti #gpg_p").append(" &nbsp [ <a class=\"help\" title=\"Cos'è una chiave pubblica? \">?</a> ]");
	$("#gpg_p a.help").toggle(
		function () {
			$("#qr_code_help").fadeOut();
			$("#gpg_help").slideToggle();
		},
		function () {
			$("#qr_code_help").fadeOut();
			$("#gpg_help").slideToggle();
		}
	)

}

function stessa_altezza_riquadri_home() { // problema in ie7 (da verificare ie8)
	h1 = parseInt($("#riquadro_tl").height());
	h2 = parseInt($("#riquadro_tr").height());
	h3 = parseInt($("#riquadro_bl").height());
	h4 = parseInt($("#riquadro_br").height());

	max = Math.max(h1,h2,h3,h4);
	$(".riquadro").height(max);
}

function paperli() {
	$("#p_button").toggle(
		function(){
			$("#paperli").animate({right:"+=200px"});
		},
		function(){
			$("#paperli").animate({right:"-=200px"});
		}
	);
}
function twitter() {
	$("#t_button").toggle(
		function(){
			$("#twitter").animate({left:"+=250px"});
		},
		function(){
			$("#twitter").animate({left:"-=250px"});
		}
	);
}
