/* ON LOAD */
$(document).ready(function(){
	// Applico il drop down menu al div NAV
	$(function() {
	    $('#nav').droppy();
	  });
	// Setta l'altezza giusta per la colonna news
	setDivHeight();
	// Sistema l'altezza delle preview delle news nel lato destro
	// Lo provo a mettere in fondo alla pagina
	// setNewsHeight();
	
	// Gestione delle immagini PNG per IE 5.5 6
	$(document).pngFix();
	
});

/* RESIZE */
$(window).resize(function(){
	// Setta l'altezza giusta per la colonna news
	// 	setDivHeight();
});

function setDivHeight()
{
	// Altezza div right (news)
	var rightDivHeight = $("div#right").height();
	
	// Altezza div left (contenuto principale)
	var leftDivHeight = $("div#left").height();
	
	// Se il div left è più alto del div right devo intervenire
	if(leftDivHeight > rightDivHeight) {
		// Bottom della Pagina Int. Subito sotto ci sta il footer. Im margine top del footer batte sul bottom di Pagina Int
		var mainMenuBottom = $("div#main_menu").height() + $("div#main_menu").offset().top;

		// Altezza del documento
		var documentHeight = $(document).height();
		
		// Altezza del footer
		var footerHeight = $("div#footer").height();

		// Calcolo il valore dell'altezza che dovrà avere il right div
		var rightDivHeight = documentHeight - (mainMenuBottom + footerHeight);
		$("div#right").height(rightDivHeight);
	}

	/*
	// Imposto l'altezza globale di html e body (per avere lo sfondo del body che va fino in fondo)
	$("div#right").css("height", rightDivHeight + "px");
	*/
}

function setNewsHeight() {
	/*
	$('.news_block_header').each(function(i){
		// alert("i: " + i);
		// alert("A. . " + $(this).height() );
		// alert("B. . " + this.height() );
		// alert("$(this): " + $(this) + ", this: " + this);
		altezza = $($('.news_block_header')[i]).height();
		altezze += "  " + i + ":"+altezza;
        if( altezza < 48) {
       		$(this).height(48)
       } 
    });
    */
    
    for( i=0; i < $('.news_block_header').length; i++) {
    	altezza = $($('.news_block_header')[i]).height();
    	if( altezza < 48) {
       		$($('.news_block_header')[i]).height(48);
       }
    }
}


/* SLIDE SHOW */
/*
thanks to:
http://jonraasch.com/blog/a-simple-jquery-slideshow
*/
function slideSwitch() {
    var $active = $('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch()", 2500 );
});



// Set the horizontal and vertical position for the popup
PositionX = 100;
PositionY = 100;
// Set these value approximately 20 pixels greater than the
// size of the largest image to be used (needed for Netscape)
defaultWidth  = 500;
defaultHeight = 500;
// Set autoclose true to have the window close automatically
// Set autoclose false to allow multiple popup windows
var AutoClose = true;
// Do not edit below this line...
// ================================
if (parseInt(navigator.appVersion.charAt(0))>=4){
var isNN=(navigator.appName=="Netscape")?1:0;
var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
var optIE='scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY;

function popImage(imageURL,imageTitle){
	if (isNN){imgWin=window.open('about:blank','',optNN);}
	if (isIE){imgWin=window.open('about:blank','',optIE);}
	with (imgWin.document){
	writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
	writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
	writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
	writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(300,300);');
	writeln('width=300-(document.body.clientWidth-document.images[0].width);');
	writeln('height=300-(document.body.clientHeight-document.images[0].height);');
	writeln('window.resizeTo(width,height);}');writeln('if (isNN){');       
	writeln('window.innerWidth=document.images["George"].width;');writeln('window.innerHeight=document.images["George"].height;}}');
	writeln('function doTitle(){document.title="'+imageTitle+'";}');writeln('</sc'+'ript>');
	if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
	else writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
	writeln('<img name="George" src='+imageURL+' style="display:block"></body></html>');
	close();		
}}

