document.write('<scr'+'ipt type="text/javascript" src="/js/jquery.cookie.js"></scr'+'ipt>');
$(document).ready(function(){

	var COOKIE_NAME = 'formReferrer';
	if( ($.cookie(COOKIE_NAME) == "" || $.cookie(COOKIE_NAME) == null) && (document.referrer || document.referrer != '')  )
		$.cookie(COOKIE_NAME, document.referrer, { path: '/', expires: 0 });


    $('a#bottom_news_button').click(function(){
        $('#bottom_news').slideToggle('slow');
    });

	
	setTimeout("$('#bottom_news').slideToggle('slow')",5000);

	/* Pannello */
	var p = $('#pannello');
	var config = {    
		 sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
		 interval: 200, // number = milliseconds for onMouseOver polling interval    
		 over: apriPannello, // function = onMouseOver callback (REQUIRED)    
		 timeout: 400, // number = milliseconds delay before onMouseOut    
		 out: chiudiPannello // function = onMouseOut callback (REQUIRED)    
	};

	$('#lnk_corsi_lauree_e_master').hoverIntent(config)													   

	
	function apriPannello() {
		if (!$('#lnk_corsi_lauree_e_master').hasClass('active')) {
			$('#lnk_corsi_lauree_e_master a.submenu').attr('style','background:none;');
		}
		p.fadeIn(100);
	}

	function chiudiPannello() {
		p.fadeOut(100);
		if (!$('#lnk_corsi_lauree_e_master').hasClass('active')) {
			$('#lnk_corsi_lauree_e_master a.submenu').attr('style','background:url("../immagini/menu/freccina.gif") no-repeat scroll center 28px transparent;');
		}
	}
	
	var config2 = {    
		 sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
		 interval: 150, // number = milliseconds for onMouseOver polling interval    
		 over: apriTendina, // function = onMouseOver callback (REQUIRED)    
		 timeout: 300, // number = milliseconds delay before onMouseOut    
		 out: chiudiTendina // function = onMouseOut callback (REQUIRED)    
	};

	$('li.tendina').hoverIntent(config2)													   

	
	function apriTendina() {
		$(this).children('a.submenu').removeClass('submenu');
		$(this).children('.menu_tendina').fadeIn(100);
	}

	function chiudiTendina() {
		$(this).children('.menu_tendina').fadeOut(100);
		$(this).children('a').addClass('submenu');
	}
	
	/* Contatti */
	$('#sede').change(function(){
		$('#td_inizio select').attr('disabled','disabled');						   
		var id_sede = $(this).val();	
		$.ajax({
			type: "POST",
			url: "/include/ajax.carica_corsi_sede.php",
			data: {id_sede: id_sede},
			dataType: "html",
			success: function(risposta) {  
				$('#td_corso').html(risposta);
				attivaCorso();
			}
		});	
	});
	
	function attivaCorso() {
		$('#corso').change(function(){
			var id_sede = $('#sede').val();	
			var id_corso = $(this).val();	
			$.ajax({
				type: "POST",
				url: "/include/ajax.carica_corsi_sede_calendario.php",
				data: {id_sede: id_sede,id_corso:id_corso},
				dataType: "html",
				success: function(risposta) {  
					$('#td_inizio').html(risposta);
				}
			});	
		});	
	}
	if ($("#modulo").length>0) {
		$("#modulo").validate({
			invalidHandler: function(form, validator) {
				  var errors = validator.numberOfInvalids();
				  if (errors) {
					var message = errors == 1
					  ? '1 field was not filled correctly. It has been highlighted.'
					  : errors + ' fields were not filled correctly. They have been highlighted.';
					$("div.error span").html(message);
					$("div.error").show();
				  } else {
					$("div.error").hide();
				  }
			},
			highlight: function(element, errorClass) {
				$(element).addClass('error');
				$(element).prev().addClass('error2');
			},
			unhighlight: function(element, errorClass) {
				$(element).removeClass('error');
				$(element).prev().removeClass('error2');
			},
			rules: {
				nome: "required",
				cognome: "required",
				giorno: "required",
				mese: "required",
				anno: "required",				
				nazionalita: "required",				
				sede: "required",				
				prefisso: "required",
				telefono: "required",
				corso: "required",
				email: {
					required: true,
					email: true
				},
				inizio: "required"
			}			
		});
	}
	/* Eventuale photogallery */
	if ($("#photogallery a").length>0) {
		$("#photogallery a").lightBox();
	}
	/* Menu sedi */
	$('a.a_sede').click(function(){

		var div_info_sede = $(this).siblings('div.info_sede');	
		if (div_info_sede.css('display')=='none') {
			$('div.info_sede').hide();
			div_info_sede.show();
		} else {
			$('div.info_sede').hide();
		}
		return false;
	});
	/* Quick links */
	$('#quicklink').change(function(){
		url = $('#quicklink option:selected').val();
		document.location = url; 
	});
	/* Photogallery */	
	if ($("#photos").size()>0) {
		/*
		$.ajax({
			type: "GET",
			url: "ajax.load_photogallery.php",
			dataType: "html",
			success: function(risposta) {  
				if (risposta != '') {
					$('#photos').css('background-image','none').html(risposta).galleryView({
						panel_width: 512,
						panel_height: 308,
						transition_speed: 1500,
						transition_interval: 5000,
						nav_theme: 'dark',
						border: '1px solid white',
						pause_on_hover: true
	
					});				
				}
			}
		});
		*/
		$('#photos').css('background-image','none').galleryView({
			panel_width: 512,
			panel_height: 308,
			transition_speed: 1500,
			transition_interval: 5000,
			nav_theme: 'dark',
			border: '1px solid white',
			pause_on_hover: true

		});					
	}
	$('#interessi_no').click(function() {
		if($(this).is(':checked')) {
			$('#interessi_management,#interessi_economia,#interessi_finanza,#interessi_moda,#interessi_sport,#interessi_marketing').attr('checked','');
		}
	});	
	$('#interessi_management,#interessi_economia,#interessi_finanza,#interessi_moda,#interessi_sport,#interessi_marketing').click(function() {
		$('#interessi_no').attr('checked','')
	});
	$('#dove_no').click(function() {
		if($(this).is(':checked')) {
			$('#dove_londra,#dove_firenze,#dove_milano,#dove_new_york,#dove_roma,#dove_madrid').attr('checked','');
		}
	});	
	$('#dove_londra,#dove_firenze,#dove_milano,#dove_new_york,#dove_roma,#dove_madrid').click(function() {
		$('#dove_no').attr('checked','')
	});	
	
	$('.aforisma_1,.aforisma_int_1').click(function() {
		document.location='/about-ese/educational-philosophy.html';
	});
});
function CheckMultiple1(frm, name) {
	for (var i=0; i < frm.length; i++)
	{
		fldObj = frm.elements[i];
		fldId = fldObj.id;
		if (fldId) {
			var fieldnamecheck=fldObj.id.indexOf(name);
			if (fieldnamecheck != -1) {
				if (fldObj.checked) {
					return true;
				}
			}
		}
	}
	return false;
}
function CheckForm1(f) {
    if (f.email.value == "") {
        alert("Please enter your email address");
        f.email.focus();
        return false;
    }
    _gaq.push(['_trackEvent', 'Contact Forms', 'Newsletter Signup', 'Home Page']);
    return true;
}

/**
 * Funzione per il tracking di obiettivi tramite Analytics
 */
Tracking = {
    pulsantiGallery: function(){
        $("#photos img.nav-next").live('click', function(){
            _gaq.push(['_trackEvent', 'SlideShow', 'Destra']);
        });
        $("#photos img.nav-prev").live('click', function(){
            _gaq.push(['_trackEvent', 'SlideShow', 'Sinistra']);
        });
    },
    social: function(page){
        return function(){
            $("p.contact_facebook, p.contact_youtube, p.contact_twitter").click(function(){
                _gaq.push(['_trackEvent', 'Social Media', page, $(this).text()]);
            });
        };
    },
    quicklink: function(){
        $("#quicklink").change(function(){
            _gaq.push(['_trackEvent', 'Quick Links', 'Home Page', $("option:selected",this).text()]);
        });
    },
    aforismi: function(){
        $('.aforisma_1,.aforisma_int_1').one('click', function() {
            $(this).find('a:first').click().attr("href");
        });
    }
};

function toggleBottomButtons(el){
	if(el.className == "bottom_news_btn_on") 
		el.className="bottom_news_btn_off";
	else 
		el.className="bottom_news_btn_on";
}
