// JavaScript Document

var sez = "home";		// sezione attuale
var posLogo = 0;		// Posizione del logoMF


/*

Identifica il browser

*/

ua   = navigator.userAgent.toLowerCase();
ie  = (ua.indexOf("msie") && document.all && ua.indexOf("netscape") == -1);
nnf  = (ua.indexOf("netscape")  != -1 && ua.indexOf("gecko") != -1);
nni  = (ua.indexOf("netscape")  != -1 && ua.indexOf("msie") != -1);
nn6  = (ua.indexOf("netscape")  != -1);
gek  = (ua.indexOf("gecko")     != -1);
ff1  = (ua.indexOf("firefox")   != -1);
opr  = (ua.indexOf("opera")     != -1);
mac  = (ua.indexOf("mac")       != -1);
web  = (ua.indexOf("webtv")     != -1);
saf  = (ua.indexOf("safari")    != -1);
kon  = (ua.indexOf("konqueror") != -1);
chr  = (ua.indexOf("chrome") != -1);
nn4  = (document.layers);


/*

Metodo richiamato quando la pagina è stata caricata

*/

jQuery(document).ready(function(){
	jQuery(document).pngFix(); 
	posizionaLogoMf();
	initButtonMenu();	
	
	jQuery("#head").click(function(){window.location.href = "?sezione=home";});
	jQuery("#twitter").click(function(){window.open("http://twitter.com/giannimelito");});
	jQuery("#facebook").click(function(){window.open("http://www.facebook.com/editaccount.php?ads#!/profile.php?id=100001112170467");});
	jQuery('#logoMf').click(function(){window.open("http://www.mauroferrario.com");});
	jQuery("#youtube").click(function(){window.open("http://www.youtube.com/user/necroskull83");});
	jQuery("#linkedin").click(function(){window.open("http://it.linkedin.com/in/giannimelito");});
	
	
	
	
	jQuery(window).resize(posizionaLogoMf);
	jQuery(window).scroll(posizionaLogoMf);
	
	if(sez=="tred"||sez=="video"||sez=="dued"||sez=="mattepainting"||sez=="sketch")
		initCoperturaMini();
	else if(sez=="home")
		initShowreelButton();
	else if(sez=="info")
		initCVButton();
	else if(sez == "contact")
		initContactButton();
		
		
		
});

/*

Inizializza il bottone per lo showreel

*/

function initShowreelButton()
	{
		jQuery("#showreel a").hover(
		  function () {
			jQuery("#showreel a #showReelOver").fadeIn("fast");
		  }, 
		  function () {
			 jQuery("#showreel a #showReelOver").fadeOut("fast");
		  }
		);
	}

/*

Inizializza il bottone per il cv

*/

function initCVButton()
	{
		jQuery("#curriculum a").hover(
		  function () {
			jQuery("#curriculum a #curriculumOver").fadeIn("fast");
		  }, 
		  function () {
			 jQuery("#curriculum a #curriculumOver").fadeOut("fast");
		  }
		);
	}


/*

Inizializza il bottone per contact

*/

function initContactButton()
	{
		jQuery("#contact a").click(inviaRichiesta);
		jQuery("#contact a").hover(
		  function () {
			jQuery("#contact a #sendMailOver").fadeIn("fast");
		  }, 
		  function () {
			 jQuery("#contact a #sendMailOver").fadeOut("fast");
		  }
		);
	}

/*

Funzione per posizionare il logo verticalmente

*/

function posizionaLogoMf()
	{ 
		if(ie)
			 posLogo = jQuery(this).height()+ document.documentElement.scrollTop - jQuery("#logoMf").height();
		else
			 posLogo = jQuery(this).height()+window.scrollY - jQuery("#logoMf").height();		
		jQuery('#logoMf').css("top",posLogo+"px");
	}

/*

Funzione per la gestione del rollOver e rollOut sulle mini

*/

function initCoperturaMini()
	{
		jQuery(".coperturaMini").hover(
		  function () {
		  }, 
		  function () {
			  jQuery(this).fadeOut("fast");
		  }
		);
		
		jQuery("ul li").hover(
		  function () {
			jQuery("#"+jQuery(this).attr("id")+" :first-child").fadeIn("fast");
		  }, 
		  function () {
		  }
		);
	}

/*

Inizializza i bottono del menu

*/

function initButtonMenu()
	{
		switch(sez)
			{
				case "tred":
					jQuery("#mainMenu #menu_3d").attr("class","selected");
					jQuery("#mainMenu #menu_3d_in").css("display","block");
					break;
				case "dued":
					jQuery("#mainMenu #menu_2d").attr("class","selected");
					jQuery("#mainMenu #menu_2d_in").css("display","block");
					break;
				case "video":
					jQuery("#mainMenu #menu_video").attr("class","selected");
					jQuery("#mainMenu #menu_video_in").css("display","block");
					break;
				case "mattepainting":
					jQuery("#mainMenu #menu_mattepainting").attr("class","selected");
					jQuery("#mainMenu #menu_mattepainting_in").css("display","block");
					break;
				case "sketch":
					jQuery("#mainMenu #menu_sketch").attr("class","selected");
					jQuery("#mainMenu #menu_sketch_in").css("display","block");
					break;
				case "info":
					jQuery("#mainMenu #menu_info").attr("class","selected");
					jQuery("#mainMenu #menu_info_in").css("display","block");
					break;
				case "contact":
					jQuery("#mainMenu #menu_contact").attr("class","selected");
					jQuery("#mainMenu #menu_contact_in").css("display","block");
					break;
			}
		jQuery("#mainMenu li").click(clickButtonMainMenu);
		jQuery("#mainMenu li").hover(
		  function () {
			jQuery("#"+jQuery(this).attr("id")+" :first-child").fadeIn("fast");
		  }, 
		  function () {
			  if(jQuery(this).attr("class") != "selected")
				jQuery("#"+jQuery(this).attr("id")+" :first-child").fadeOut("fast");
		  }
		);
	}


/*

Funzione richiamata quando si clicca su un bottone del menu

*/

function clickButtonMainMenu()
	{
		var sez = "";
		switch(jQuery(this).attr("id"))
			{
				case "menu_2d":
					sez = "dued";
					break;
				case "menu_3d":
					sez = "tred";
					break;
				case "menu_mattepainting":
					sez = "mattepainting";
					break;
				case "menu_video":
					sez = "video";
					break;
				case "menu_sketch":
					sez = "sketch";
					break;
				case "menu_info":
					sez = "info";
					break;
				case "menu_contact":
					sez = "contact";
					break;
			}
		window.location.href = "?sezione="+sez;
	}

/*

Funzione richiamata per inviare i dati del form contact

*/

function inviaRichiesta()
	{
		jQuery.post("./php/sendMail.php", { name: jQuery("#inputName").attr("value"), surname: jQuery("#inputSurname").attr("value") , mail : jQuery("#inputMail").attr("value"), phone : jQuery("#inputPhone").attr("value"), company : jQuery("#inputCompany").attr("value"),  city : jQuery("#inputCity").attr("value"),  country : jQuery("#inputCountry").attr("value"),  zipCode : jQuery("#inputZipcode").attr("value"), address : jQuery("#inputAddress").attr("value"),message : jQuery("#inputMessage").attr("value") },
		  function(data){
				if(data == "true")
					{
						alert("Message correctly send!");
						jQuery("input").attr("value","");
						jQuery("textarea").attr("value","");
					}
				else
		  			{
						alert("Compile all the form!");
					}
		  });
	}

