// JavaScript Document
jQuery(function(){    
	jQuery('.easy-form').EasyForms();
	jQuery('.striped li:odd').addClass('alt');
	jQuery('#input-search').focus();
	jQuery("input.stdinput,textarea.stdinput").focus(function(){jQuery(this).addClass("stdinput-sel");jQuery(this).parent().parent().parent().addClass("focused");jQuery(this).parent().parent().addClass("focused");}).blur(function(){jQuery(this).removeClass("stdinput-sel");jQuery(this).parent().parent().parent().removeClass("focused");jQuery(this).parent().parent().removeClass("focused")});
	jQuery(".photogallery li,.videoclips li").mouseover(function(){jQuery(this).addClass("over");}).mouseout(function(){jQuery(this).removeClass("over");});
	
	if (jQuery("#evento-tabs > ul").length > 0){
		var jQuerytabs = jQuery("#evento-tabs > ul").tabs({cache: false});
	}
	if (jQuery("#emotion-home-tabs > ul").length > 0){
		var jQuerytabs = jQuery("#emotion-home-tabs > ul").tabs();
	}	
	
	jQuery("ul.list li ,ul.filelist li").mouseover(function(){jQuery(this).addClass('over');}).mouseout(function(){jQuery(this).removeClass('over');}).click(function() {if (jQuery(this).find("a").length > 0){window.location = jQuery(this).find("a:first").attr('href');}});
	
	// Datepicker
	if (jQuery("#linkedDates > ul").length > 0){
	jQuery("#linkedDates").datepicker({
		maxDate: "-18y",
		yearRange: "-100:+0", 
		beforeShow: readLinked,
		onSelect: updateLinked,
		showOn: "both",
		showAnim: "fadeIn",
		buttonImage: "/images/calendar.gif",
		buttonImageOnly: true,
		hideIfNoPrevNext: true,
		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"],
		dayNames: ["domenica", "luned&iacute;", "marted&iacute;", "mercoled&iacute;", "gioved&iacute;", "venerd&iacute;", "sabato"],
		dayNamesShort: ["Dom", "Lun", "Mar", "Mer", "Gio", "Ven", "Sab"],
		dayNamesMin: ["Do", "Lu", "Ma", "Me", "Gi", "Ve", "Sa"],
		firstDay: 1
		}); 
	}
	
	// Accordion
	//jQuery("ul#archivio-news").accordion({header: '.content-list', alwaysOpen: false, autoHeight: false}); 
	
	// Datepicker
	jQuery("#form-dd, #form-aaaa").blur(checkLinkedDays);	
	// Highlight dei messaggi.
	if (jQuery(".message,.warning,.success").length > 0){
		jQuery(".message,.warning,.success").hide().fadeIn("slow").effect("highlight", {}, 2000);	
	}
	// Ottimizzazione allineamento immagini.
	jQuery("div.text-content img[style]").each(function(){
		if (jQuery(this).attr('style') == 'float: left;'){jQuery(this).addClass("align-left").removeAttr('style')};
		if (jQuery(this).attr('style') == 'float: right;'){jQuery(this).addClass("align-right").removeAttr('style')};
	});	
	jQuery('#open-sponsorship').click(function() { // bind click event to link
		jQuerytabs.tabs('select', 'sponsorship'); // switch to third tab	  
	});
	jQuery('#open-programma').click(function() { // bind click event to link
		jQuerytabs.tabs('select', 'programma'); // switch to third tab		
	});	
	
	
	// Gallerie interattive a scomparsa
	jQuery("li.gallery-more a").click(function(){
	 var galleryUrl = jQuery(this).attr('href');
	 var self = jQuery(this);
	 var galleryContainer = jQuery(this).parent().parent();
	 self.addClass('loading');	
	 jQuery.ajax({		
			url: galleryUrl + "?embed=1",			
			dataType: "html",
			type: "GET",
			success: function(data){				
			galleryContainer.html(data);
			galleryContainer.parent().find('.more-disclaimer').hide();
			tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox				
	  		}
		});
	 return false
	 });	 
	
});
/*function openDialog(id){
jQuery(id).dialog({ 
    modal: true, 
    overlay: { 
        opacity: 0.5, 
        background: "white" 
    } 
});
}*/
// Prepare to show a date picker linked to three select controls 
function readLinked() { 
    jQuery("#linkedDates").val(jQuery("#form-mm").val() + "/" + 
        jQuery("#form-dd").val() + "/" + jQuery("#form-aaaa").val()); 
    return {}; 
}  
// Update three select controls to match a date picker selection 
function updateLinked(date) { 
    jQuery("#form-mm").val(date.substring(0, 2)); 
    jQuery("#form-dd").val(date.substring(3, 5)); 
    jQuery("#form-aaaa").val(date.substring(6, 10)); 
}  
// Prevent selection of invalid dates through the select controls 
function checkLinkedDays() { 
    var daysInMonth = 32 - new Date(jQuery("#form-aaaa").val(), 
        jQuery("#form-mm").val() - 1, 32).getDate();   
    if (jQuery("#form-dd").val() > daysInMonth) { 
        jQuery("#form-dd").val(daysInMonth); 
    } 
} 
// More usable Forms V 2.3  By Oliver Astrologo
jQuery.fn.EasyForms=function(){
this.submit( function() {
			var submitForm = this;
			jQuery(submitForm).find("label").not(".radiolabel").each(function(){
				var current=jQuery(this);
				var targetForm =  jQuery('#'+current.attr("for"));				
				if (targetForm.val() == current.html()){
				targetForm.val('');
				};																			  
			});
		return true;
	});	
	this.find("label").not(".radiolabel").each(function(){
		var current=jQuery(this);		
		var targetForm = jQuery('#'+current.attr("for"));	   
	   if (targetForm.val() == ''){
			targetForm.val(current.html());		
			}	   
	   targetForm.click(function(){		
		if (jQuery(this).val() == current.html()){
			jQuery(this).val('');			
			}
		});
		targetForm.blur(function(){		
		if (jQuery(this).val() == ''){
			jQuery(this).val(current.html());			
			}
		});
		current.hide();	
	});			
}

jQuery.fn.confirm_prompt = function(stringa) {
newlocation = jQuery(this).get(0);	
this.click(function() {
	 if (confirm(stringa)) {
      window.location = newlocation;
    }else{
	return false;
	}});
}



// Get selected text
function getSelectedText(){
	if(window.getSelection){
		return window.getSelection().toString();
	}
	else if(document.getSelection){
		return document.getSelection();
	}
	else if(document.selection){
		return document.selection.createRange().text;
	}
};
function UpdateCosto(val) {jQuery('#CostoTotale').html(((jQuery('#CostoTotale').html()-1+1) + val).toFixed(2));}




































