/**
* JS La Scala
* Copyright (c) 2007 Engitel S.p.A.
*/

$(document).ready(function(){

// -------------------------------------------------- done_loading
/*
(new Image()).src = '/static/img/timer.gif?u=' + self.location + '&t=' +
	(((new Date()).getTime() - began_loading));
*/

// -------------------------------------------------- menu 
$("#nav-one li").hover(
		function(){ $("ul", this).fadeIn("fast"); },
		function() {});

if (document.all) {
	$("#nav-one li").hoverClass ("sfHover");
}

// -------------------------------------------------- header con strilli
if ($('#testataflash a').size() > 1){
	$('#testataflash').innerfade(
		{ 	animationtype: 'fade', 
			speed: 2000, 
			timeout: 6000, 
			type: 'sequence', 
			containerheight: 238,
			runningclass: 'innerfade'
		});
} else {
	$('#testataflash a').show();
	//$('#testataflash a').fadeIn('slow');
}

// -------------------------------------------------- scrollbar eventi
if ($('#scroll').size() === 1) {
	$('#scroll').jScrollPane({showArrows:true,arrowSize:15,scrollbarWidth:24});
}

// -------------------------------------------------- calendar
if ($('#caleventi').size() === 1){
	popUpCal.setDefaults(popUpCal.regional[calendar_localized]);
	$('#caleventi').calendar({
		changeMonth:false,
		changeYear:false,
		prevText:'<img border="0" alt="&lt;" src="/includes/img/freccia_sx.gif">',
		nextText:'<img border="0" alt="&gt;" src="/includes/img/freccia_dx.gif">',
		dateFormat:'YMD-',
		minDate: new Date(2006, 12 - 1, 7),
		maxDate: new Date(2008, 12 - 1, 1),
		firstDay:1,
		customDate:lascalaCalendar.eventDay,
		changeFirstDay:false,
		onSelect: lascalaCalendar.gotoEvent});
}

});

$.fn.hoverClass = function(c) {
return this.each(function(){
	$(this).hover(
		function() { $(this).addClass(c); },
		function() { $(this).removeClass(c); }
	);
});
};

var lascalaCalendar = {
	// calendario
	gotoEvent: function(d){
		location.href=url_detail+d;
	},
	eventDay: function(date) {
		if (typeof eventDays !== 'undefined'){
			if(eventDays[date.getFullYear()]){
				var mese = eventDays[date.getFullYear()][date.getMonth()+1]
				if(mese){
					for (i = 0; i < mese.length; i++) {
						if (date.getDate() == mese[i]) {
							return [true,''];
						}
					}
				}
			}
		}
		return [false,'day_no'];
	}
}

var lascalaJs = {
	toggleInnerFade: function(){
		if (lascala_flv_semaphore)
			lascala_flv_semaphore = false;
		else
			lascala_flv_semaphore = true;
	}
}

var lascala_flv_semaphore = true;


function querySt(ji) {
hu = window.location.search.substring(1);
gy = hu.split("&");
for (i=0;i<gy.length;i++) {
ft = gy[i].split("=");
if (ft[0] == ji) {
return ft[1];
}
}
}
function getEventCalendarCount(spankey)
{
	var idLang="";
	var Url=new String(window.location)
	// non si riesce a determinare la lingua
	if (Url.indexOf('/it/') >0)
	{
		idLang="it-IT"
	}
	else if (Url.indexOf('/en/') >0)
	{
	
		idLang="en-US"
	}
	
	var r=Math.random();
		
	$.get("/web/EventCalendarCount.aspx?r="+r+"&idLang="+idLang, function(data){
			//document.getElementById(spankey).innerHTML="<b> Nel tuo calendario " + data + " evento  </b>" ;
			document.getElementById(spankey).innerHTML="<b>" + data + "</b>" ;
			
		 }
		)
		
}

var _POPUP_FEATURES = 'resizable=yes,location=0,statusbar=0,menubar=0,width=800,height=500';

function raw_popup(url, target, features) {
    // pops up a window containing url optionally named target, optionally having features
    if (isUndefined(features)) features = _POPUP_FEATURES;
    if (isUndefined(target  )) target   = '_blank';
    var theWindow = window.open(url, target, features);
    theWindow.focus();
    return theWindow;
}

function link_popup(src, features) {
    // to be used in an html event handler as in: <a href="..." onclick="link_popup(this,...)" ...
    // pops up a window grabbing the url from the event source's href
    return raw_popup(src.getAttribute('href'), src.getAttribute('target') || '_blank', features);
}

function openPopUpWin(url,name,width,height){
	return raw_popup(url,name,'resizable=yes,location=0,statusbar=0,menubar=0,width='+width+',height='+height);
}

function isUndefined(v) {
    var undef;
    return v===undef;
}
