/*
	Web Portal Now
	Theme: terre
	Script: head.js
	Author: Danilo Cicognani
	Version: 2.01
	Date: 22/06/2011
	Use: JavaScript animation functions
	Copyright (c) 2009-2011 Danilo Cicognani
*/
var headPath = strAdminUrl + '/../themes/terre/img/';
var headNum = 1;
var headTot = 15;
var headLoaded = false;
var headTime = false;
$('document').ready(function() {
	headLoad();
	tmrHeadAnim = setTimeout('headTimer()', 3000);
	$('a.slb').lightBox({imageLoading: strAdminUrl + "/../themes/terre/img/lightbox-ico-carica.gif", imageBtnPrev: strAdminUrl + "/../themes/terre/img/lightbox-btn-prec.gif", imageBtnNext: strAdminUrl + "/../themes/terre/img/lightbox-btn-succ.gif", imageBtnClose: strAdminUrl + "/../themes/terre/img/lightbox-btn-chiudi.gif", imageBlank: strAdminUrl + "/../themes/terre/img/lightbox-blank.gif", txtImage: "Immagine", txtOf: "di", keyToNext: "s"});
	window.setTimeout("startScroll('div#banner ul')", 1000);
});
function headTimer() {
	headTime = true;
	if (headLoaded)
		headAnim();
}
function headLoad() {
	var headImage = new Image();
	if (++headNum > headTot) headNum = 1;
	headImage.onload = function() {
		headLoaded = true;
		if (headTime)
			headAnim();
		headImage.onload = function(){};
	};
	headImage.src = headPath + 'head' + headNum + '.jpg';
}
function headAnim() {
	headLoaded = false;
	headTime = false;
	$('#headbg img').fadeOut('slow', function() {
		$('#headbg img').attr('src', headPath + 'head' + headNum + '.jpg');
		$('#headbg img').fadeIn('slow', function() {
			headLoad();
			tmrHeadAnim = setTimeout('headTimer()', 4000);
		});
	});
}
function newsScroll(strScrollSelector) {
	var $objScroll = $(strScrollSelector);
	var intHeight = $objScroll.height();
	var intTop = parseInt($objScroll.css("top"));
	if (isNaN(intTop))
		intTop = 0;
	//if (intTop % 90 == 0) {
	//	window.clearInterval($objScroll.attr("interval"));
	//	window.setTimeout("startScroll('" + strScrollSelector + "')", 1000);
	//}
	if (intTop == -intHeight)
		intTop = 600;
	else
		intTop--;
	$objScroll.css("top", intTop + 'px');
}
function startScroll(strScrollSelector) {
	if ($(strScrollSelector + ' li').size() > 1) {
		var $objScroll = $(strScrollSelector);
		$objScroll.attr("interval", window.setInterval("newsScroll('" + strScrollSelector + "')", 50));
		$objScroll.mouseover(function() {
			window.clearInterval($(this).attr("interval"));
		});
		$objScroll.mouseout(function() {
			$(this).attr("interval", window.setInterval("newsScroll('" + strScrollSelector + "')", 50));
		});
	}
}
