// sws js
function $I(el){
	if(document.getElementById) {
		this.obj = document.getElementById(el);
	} else if(document.all) {
		this.obj = document.all[el];
	} else if(document.layers) {
		this.obj = document.layers[el];
	}
	return this.obj;
}
function $X(el,url) {
	var ajaxRequest;
	var ajaxResponse;
	var loader;
	
	ajaxResponse = new $I(el);
	
	loader = setTimeout(function(){ajaxResponse.innerHTML = "<div class=\"loader\"></div>";},200)
	
	try{
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				alert("Impossibile effettuare la richiesta");
				return false;
			}
		}
	}
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4) {
			clearTimeout(loader);
			ajaxResponse.innerHTML = ajaxRequest.responseText;
		} else {
		}
	}
	ajaxRequest.open("GET", url);
	ajaxRequest.send(null);
}
function getWindowHeight() {
	var winH = 460;
	if(document.body && document.body.offsetWidth) {
		winH = document.body.offsetHeight;
	}
	if (document.compatMode=='CSS1Compat' && document.documentElement && document.documentElement.offsetWidth) {
		winH = document.documentElement.offsetHeight;
	}
	if(window.innerHeight) {
		winH = window.innerHeight;
	}
	return winH;
}
function getWindowWidth() {
	var winW = 640;
	if(document.body && document.body.offsetWidth) {
		winW = document.body.offsetWidth;
	}
	if (document.compatMode=='CSS1Compat' && document.documentElement && document.documentElement.offsetWidth) {
		winW = document.documentElement.offsetWidth;
	}
	if(window.innerWidth) {
		winW = window.innerWidth;
	}
	return winW;
}	
function blanket_size() {
	if(typeof window.innerWidth != 'undefined') {
		viewportheight = window.innerHeight;
	} else {
		viewportheight = document.documentElement.clientHeight;
	}
	if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
		blanket_height = viewportheight;
	} else {
		if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
			blanket_height = document.body.parentNode.clientHeight;
		} else {
			blanket_height = document.body.parentNode.scrollHeight;
		}
	}
	var blanket = document.getElementById('blanket');
	blanket.style.height = blanket_height + 'px';
}
function blanket() {
	blanket_size();
	$I('blanket').style.display = 'block';
}
var curHeight;
var curWidth;

function getImgSize(imgSrc) {
	var newImg = new Image();
	newImg.src = imgSrc;
	curHeight = newImg.height;
	curWidth = newImg.width;
}
// fade animation home
var fadeStarted = false;
var fadeTimer;
var fadeInTimer;
var fadeOutTimer;
var fadeImg = 0;
var next = 0;

function fadeStart() {
	fadeStarted = true;
	fadeTimer = setInterval("fader()", 5000);
}
function fader() {
	if(fadeImg == (img-1)) {
		next = 0;
	} else {
		next = fadeImg + 1;
	}
	fadeIn('home_'+next);
	fadeOut('home_'+fadeImg);
}
function fadeIn(layer) {
	el = $I(layer);
	if(el.style.display == 'none') el.style.display = 'block';
	fadeInTimer = setInterval(function(){fadeInAnimation("home_"+next);}, 100);
}
function fadeInAnimation(layer) {
	el = $I(layer);
	var val = parseFloat(el.style.opacity);
	if(val == 'undefined') {
		val = parseFloat(0);
	}
	if(val < 1) {
		el.style.opacity =  val + parseFloat(0.1);
		el.style.filter = 'alpha(opacity = ' + ((val*100) + 10) + ')';
	} else {
		el.style.opacity = 1;
		el.style.filter = 'alpha(opacity = 100)';
		clearInterval(fadeInTimer);
		clearInterval(fadeOutTimer);
		fadeImg = next;
	}	
}
function fadeOut() {
	//if(el.style.display == 'none') el.style.display = 'block';
	fadeOutTimer = setInterval(function(){fadeOutAnimation("home_"+fadeImg);}, 100);
}
function fadeOutAnimation(layer) {
	el = $I(layer);
	var val = parseFloat(el.style.opacity);
	if(val == 'undefined') {
		val = parseFloat(1);
	}
	if(val > 0) {
		el.style.opacity = val - parseFloat(0.1);
		el.style.filter = 'alpha(opacity = ' + ((val*100) - 10) + ')';
	} else {
		el.style.opacity = 0;
		el.style.filter = 'alpha(opacity = 0)';
		clearInterval(fadeOutTimer);
		el.style.display = 'none';
	}
}

selected_cell = 0;
function checkCal(url, click, cell) {
	$I('cell_'+cell).style.backgroundColor = '#FFD82F';
	if(selected_cell > 0) $I('cell_'+selected_cell).style.backgroundColor = '#A9A4CD';
	selected_cell = cell;
	if($I('eventi_holder').style.display=='none') {
		$I('eventi_holder').style.display='block';
		if(!click) $X('eventi_holder',url);
	}
	if(click) $X('eventi_holder',url);
}

