$(document).ready(function(){
   $(".menu-fader").hover(function(){
     $(this.childNodes.item(0)).fadeIn(500);
   },function(){
     $(this.childNodes.item(0)).fadeOut(200);
   });
   $(".cartoncini").click(function(){
	document.getElementById("testi-intro").style.display = "none";
	if(this.id != "antipasti"){
		$("#antipasti div").fadeOut();
		document.getElementById("testi-antipasti").style.display = "none";
	}
	if(this.id != "primi"){
		$("#primi div").fadeOut();
		document.getElementById("testi-primi").style.display = "none";
	}
	if(this.id != "carne"){
		$("#carne div").fadeOut();
		document.getElementById("testi-carne").style.display = "none";
	}
	if(this.id != "straccetti"){
		$("#straccetti div").fadeOut();
		document.getElementById("testi-straccetti").style.display = "none";
	}
	if(this.id != "contorni"){
		$("#contorni div").fadeOut();
		document.getElementById("testi-contorni").style.display = "none";
	}
	if(this.id != "carne2"){
		$("#carne2 div").fadeOut();
		document.getElementById("testi-carne2").style.display = "none";
	}
		$(this.childNodes.item(0)).fadeIn();
		idTesti = "#testi-"+this.id;
		$(idTesti).fadeIn();
   });
   
});

jQuery(function($){ 
        $.datepicker.regional['it'] = { 
            clearText: 'Svuota', clearStatus: '', 
                clearStatus: 'Cancella la data corrente', 
                closeText: 'Chiudi', closeStatus: '', 
                closeStatus: 'Chiudi senza cambiamenti', 
                prevText: '&lt;Prec', prevStatus: '', 
                prevStatus: 'Mostra il mese precedente', 
                nextText: 'Succ&gt;', nextStatus: '', 
                nextStatus: 'Mostra il mese successivo', 
                currentText: 'Oggi', currentStatus: '', 
                currentStatus: 'Mostra il mese corrente', 
                monthNames: 
['Gennaio','Febbraio','Marzo','Aprile','Maggio','Giugno', 
                'Luglio','Agosto','Settembre','Ottobre','Novembre','Dicembre'], 
                monthNamesShort: ['Gen','Feb','Mar','Apr','Mag','Giu', 
                'Lug','Ago','Set','Ott','Nov','Dic'], 
                monthStatus: 'Mostra un altro mese', 
                yearStatus: 'Mostra un altro anno', 
                weekHeader: 'Sm', weekStatus: '', 
                weekStatus: 'Settimana dell\'anno', 
                dayNames: 
['Domenica','Luned&#236','Marted&#236','Mercoled&#236','Gioved&#236','Vener d&#236','Sabato'], 
                dayNamesShort: ['Dom','Lun','Mar','Mer','Gio','Ven','Sab'], 
                dayNamesMin: ['Do','Lu','Ma','Me','Gio','Ve','Sa'], 
                dayStatus: 'Imposta DD come primo giorno della settimana', 
                dateStatus: 'Seleziona DD, M d', 
                //dateFormat: 'dd/mm/yy', 
				firstDay: 1, 
                initStatus: 'Seleziona una data', 
                isRTL: false 
        }; 
        $.datepicker.setDefaults($.datepicker.regional['it']); 
}); 


$(function() {
		$("#datepicker").datepicker({
									minDate: 0, 
									maxDate: '+1M +10D'
									
									});
	});

function slideSwitch() {
    var $active = $('#pannello IMG.active');

    if ( $active.length == 0 ) $active = $('#pannello IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#pannello IMG:first');

    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch()", 5000 );
});

function showCal(){
	document.getElementById('data-label').style.display='none';
	document.getElementById('datepicker').style.display='inline';
	document.getElementById("modulo-prenotazione").style.display="none";
	document.getElementById('datepicker').focus();
	document.getElementById('datepicker').value = "";
}

var mese = new Array("Gennaio","Febbraio","Marzo","Aprile","Maggio","Giugno","Luglio","Agosto","Settembre","Ottobre","Novembre","Dicembre");

function setData(){
	document.getElementById('data-label').style.display='inline';
	data = new Date(document.getElementById('datepicker').value);
	
	document.getElementById('data-label').innerHTML = '<span class="giorno">'+data.getDate()+'</span> '+mese[data.getMonth()]+' '+data.getFullYear();
	document.getElementById('datepicker').style.display='none';
	if(document.getElementById('datepicker').value != ""){
		//document.getElementById('modulo-prenotazione').style.display='block';
		$(function(){
     		$("#modulo-prenotazione").fadeIn(500);
   		});
	}
}


function createRequestObject() {  
    var ro;  
    var browser = navigator.appName;  
    if(browser == "Microsoft Internet Explorer"){  
        ro = new ActiveXObject("Microsoft.XMLHTTP");  
    }else{  
        ro = new XMLHttpRequest();  
    }  
    return ro;  
}  

var http = createRequestObject();  

function confezionaMail(f,tipo){
	str = "";
	switch(tipo){
		case "prenota":
			strMail = escape(document.getElementsByName("form-email").item(0).value);
			strNome = escape(document.getElementsByName("form-nome").item(0).value);
			strData = document.getElementById("data-label").innerText;
			strOra = document.getElementsByName("form-ore").item(0).value+":"+document.getElementsByName("form-minuti").item(0).value;
			strNum = escape(document.getElementsByName("form-persone").item(0).value);
			strTel = escape(document.getElementsByName("form-telefono").item(0).value);
			strNote = escape(document.getElementsByName("form-note").item(0).value);
			strDisclaimer="Si ricorda che è necessaria una conferma telefonica almeno due ore prima della data di prenotazione.";
			strRitorno = "La tua prenotazione per il giorno "+strData+" alle ore "+strOra+"  è stata inoltrata. Ti ricordiamo di telefonare almeno 2 ore prima per la conferma del tavolo. Grazie!";
			strMess ="LA TAVERNA DEL PARCO\n\nAbbiamo ricevuto una prenotazione con i seguenti dati:\n\tData: "+strData+" alle "+strOra+" \n\tPersone: "+strNum+" \n\tNome: "+strNome+"\n\tTelefono: "+strTel+"\n\tE-mail: "+strMail+"\n\tNote:"+strNote+"\n\n";
			str += "nome=" + strNome + "&";
			str += "email=" + strMail + "&";
			str += "oggetto=## Richiesta di prenotazione per il giorno "+strData+" ##&";
			str += "ritorno="+strRitorno+"&";
			str += "messaggio="+strMess+strDisclaimer;
			break;
		case "scrivici":
			strMail = escape(document.getElementsByName("sEmail").item(0).value);
			strNome = escape(document.getElementsByName("sNome").item(0).value);
			strNote = escape(document.getElementsByName("sMessaggio").item(0).value);
			alert(strNome);
			strRitorno = "In messaggio è stato inviato correttamente. Grazie!";
			strMess =strNote+"\n\n";
			str += "nome=" + strNome + "&";
			str += "email=" + strMail + "&";
			str += "oggetto=-- Messaggio dal sito inviato da "+strNome+" --&";
			str += "ritorno="+strRitorno+"&";
			str += "messaggio="+strMess;
			break;
		case "lavora":
			strMail = escape(document.getElementsByName("sEmail").item(1).value);
			strNome = escape(document.getElementsByName("sNome").item(1).value);
			strNote = escape(document.getElementsByName("sMessaggio").item(1).value);
			strRitorno = "In messaggio è stato inviato correttamente. Grazie!";
			strMess =strNote+"\n\n";
			str += "nome=" + strNome + "&";
			str += "email=" + strMail + "&";
			str += "oggetto=-- Messaggio dal sito inviato da "+strNome+" --&";
			str += "ritorno="+strRitorno+"&";
			str += "messaggio="+strMess;
			break;
	}
	sndMail(f,str);
}

function sndMail(f,str) {
		//var str = getFormValues(f,"validate");  
    	http.open('post', '/script/sendmail.php', true);  
		http.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
    	http.onreadystatechange = handleMail;
	
    	http.send(str);
		/*document.getElementsByName("nome").item(globalId).value = '';
		document.getElementsByName("email").item(globalId).value = '';
		document.getElementsByName("oggetto").item(globalId).value = '';
		document.getElementsByName("messaggio").item(globalId).value = '';*/
}

/*function getFormValues(fobj,valFunc)
{
	var str = "";
	str += "nome=" + escape(document.getElementsByName("nome").item(globalId).value) + "&";
	str += "email=" + escape(document.getElementsByName("email").item(globalId).value) + "&";
	str += "oggetto=" + escape(document.getElementsByName("oggetto").item(globalId).value) + "&";
	str += "mess=" + escape(document.getElementsByName("messaggio").item(globalId).value);
	return str;
}*/
  
function handleMail() {  
    if(http.readyState == 4){  
        var response = http.responseText;  
        //alert(response);
		Shadowbox.open({
        content:    response,
        player:     "html",
        title:      "Prenotazione",
        height:     150,
        width:      350
    });
    }  
}

jQuery.fn.liScroll = function(settings) {
		settings = jQuery.extend({
		travelocity: 0.07
		}, settings);		
		return this.each(function(){
				var $strip = jQuery(this);
				$strip.addClass("newsticker")
				var stripWidth = 0;
				var $mask = $strip.wrap("<div class='mask'></div>");
				var $tickercontainer = $strip.parent().wrap("<div class='tickercontainer'></div>");								
				var containerWidth = $strip.parent().parent().width();	//a.k.a. 'mask' width 	
				$strip.find("li").each(function(i){
				stripWidth += jQuery(this, i).outerWidth(true); // thanks to Michael Haszprunar
				});
				$strip.width(stripWidth);			
				var totalTravel = stripWidth+containerWidth;
				var defTiming = totalTravel/settings.travelocity;	// thanks to Scott Waye		
				function scrollnews(spazio, tempo){
				$strip.animate({left: '-='+ spazio}, tempo, "linear", function(){$strip.css("left", containerWidth); scrollnews(totalTravel, defTiming);});
				}
				scrollnews(totalTravel, defTiming);				
				$strip.hover(function(){
				jQuery(this).stop();
				},
				function(){
				var offset = jQuery(this).offset();
				var residualSpace = offset.left + stripWidth;
				var residualTime = residualSpace/settings.travelocity;
				scrollnews(residualSpace, residualTime);
				});			
		});	
};

$(function(){
	$("ul#ticker01").liScroll({travelocity: 0.03});
});


    /*$(document).ready(function(){ 
        $(document).pngFix(); 
    }); */


