/**
* 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:14});
}

// -------------------------------------------------- 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(2010, 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 () {
        lascala_flv_semaphore = !(lascala_flv_semaphore);
        var action = lascala_flv_semaphore ? 'Stop' : 'Play';
        pageTracker._trackEvent('Video', action, videoname);
    },
    complete: function () {
        pageTracker._trackEvent('Video', 'Completed', videoname);
        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 r=Math.random();
	$.get("/web/EventCalendarCount.aspx?r="+r, function(data){
		if($('#'+spankey).size() === 1) 
			$('#'+spankey)[0].innerHTML="<b>" + data + "</b>" ;
		});
}

var _POPUP_FEATURES = 'resizable=yes,location=1,statusbar=0,menubar=0,toolbar=1,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;
}
function appendQs(src)
{
	var u = src.getAttribute('href');
	var c = new String(document.location);
	if (c.indexOf('?')>0 && u.indexOf('?')<0)
		u=u+c.substring(c.indexOf("?"));
	document.location.href=u;
}	

function makeAnchorLink(fragment){
	var l = String(document.location);
	if (l.indexOf('#')<0)
		document.location = l + '#' + fragment;
	else
		document.location = l.substring(0,l.indexOf('#')+1) + fragment;
}