//	inizio funzioni di debug
debug_msg = false;
function toDebug(string)
{
	if (debug_msg)
	{
		if((typeof window.console=="undefined")) {alert(string);}
		else {
			console.error();
			console.group(string);
			console.trace();
			console.groupEnd();
		}
	}
}
function toConsole(string)
{
	if((typeof window.console=="undefined")) {alert(string);}
	else console.log(string);
}
//	fine funzioni di debug
//--------------------------------------------------------------------
function mainHeight()
{
try
{
	var main = $('#main');
	var head = $('#head');
	var container = $('#container');
	var colonnaSx = $('#colonnaSx');
	var colonnaDx = $('#colonnaDx');
	var footer = $('#footer');
//	if(contenuto.height()< 10) contenuto.height(10);
	var box_height = Math.max(colonnaSx.height(),Math.max(container.height(),colonnaDx.height()));
	var page_dimensions = getPageSize();
	var total_height;
	container.css({'top':head.height()+'px'});
	container.height(box_height);
	colonnaSx.css({'top':head.height()+'px'})
	colonnaSx.height(box_height);
	colonnaDx.css({'top':head.height()+'px'})
	colonnaDx.height(box_height);
	total_height = head.height() + box_height + footer.height();
	footer.css({'top':total_height - footer.height()+'px'});
	main.height(total_height);
//	imageMargin();
//	overMenu();

}
catch(e) {toDebug(e);}
}
//--------------------------------------------------------------------
//	inizio funzioni di scroll
var moving = false;
var timer;
var top = 0;
function scrollGallery()
{
try
{
	var freccia_su = $('div.freccia-su');
	var freccia_giu = $('div.freccia-giu');
	linkImages();
	freccia_su.hover(function(){scrollUp();},function(){moving = false;clearTimeout(timer);});
	freccia_giu.hover(function(){scrollDown()},function(){moving = false;clearTimeout(timer);});
}
catch(e) {toDebug(e);}
}

function scrollUp()
{
	var gallery = $('#miniature');
	if(gallery.offset().top >= 298) return false;
	moving = true;
	top +=5;
	gallery.animate({ 
		top:top
      }, 10 );
	if(moving) timer = setTimeout(scrollUp,10);
	else return false;
}

function scrollDown()
{
	var gallery = $('#miniature');
	if(gallery.offset().top < -(gallery.height()-710)){return false;}
	moving = true;
	top -=5;
	gallery.animate({ 
		top:top
      }, 10 );
	if(moving) timer = setTimeout(scrollDown,10);
	else return false;	
}
function linkImages()
{
try
{
	var link_array = $('#miniature a');
	link_array.click(function()
	{ 
		$('#big-image').attr('src',this.href);
		return false;
	 });
}
catch(e) {toDebug(e);}
}

//	fine funzioni di scroll
//--------------------------------------------------------------------

function overMenu()
{
	var link_array = $('#menu a');
	link_array.hover(function()
	{
		$(this).animate(
		{
			paddingLeft: 42
		}, 500);
		$(this).css({'background':'url("images/background/menu-on.gif") no-repeat left top;', 'color':'#ffffff;'});
	},
	function()
	{
		if(!$(this).hasClass('active'))
		{
			$(this).animate(
			{
				paddingLeft: 31
			}, 500);
			$(this).css({'background':'url("images/background/menu-off.gif") no-repeat left top;', 'color':'#906c3e;'});
		}
	});
}
//--------------------------------------------------------------------
function imageMargin()
{
	var img_array = $('#contenuto img');
	var float;
	for(var i=0;i<img_array.length;i++)
	{
		jQuery.each(img_array, function() 
		{
			if($(this).css('float')=='left') $(this).css({'margin-right':'10px'});
			else if($(this).css('float')=='right') $(this).css({'margin-left':'10px'}); 
		});
	}
} 
//--------------------------------------------------------------------
// inizio funzioni per prendere dimensioni finetra
function getPageSize() 
{
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
};

function getPageScroll() 
{
	var xScroll, yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}
	arrayPageScroll = new Array(xScroll,yScroll) 
	return arrayPageScroll;
};
// fine funzioni per prendere dimensioni finetra
//--------------------------------------------------------------------
function showNewsletter()
{
try
{
	var overlay = $('#my_overlay');
	var box = $('#box-newsletter');
	var overlay_height  = getPageSize();
	var page_scroll  = getPageScroll();
	overlay.css({'height': overlay_height[1], 'opacity':'0'});
	box.css({'top':page_scroll[1]});
	overlay.one("click", function(){
		hideNewsletter();
	});
	overlay.show();
	overlay.fadeTo('slow',0.5,function(){box.slideToggle('slow');});
}
catch(e) {toDebug(e);}
}
function hideNewsletter()
{
try
{
	var overlay = $('#my_overlay');
	var box = $('#box-newsletter');
	box.slideToggle('fast',function(){overlay.fadeOut('fast');});
}
catch(e) {toDebug(e);}
}
//--------------------------------------------------------------------

// esecuizione delle funzioni a caricamento effettuato
$(document).ready(function()
{
	$('#loader').css({'height':getPageSize()[3],'opacity':'0.8'});
	mainHeight();
//	scrollGallery();
	
	/*inizio lightbox init*/
/*	
	$(function() 
	{
		$('a[@rel*=lightbox]').lightBox(); 
	});
*/
	/*fine lightbox init*/
	
	$('#loader').hide();
});



