﻿// JavaScript Document
addDOMLoadEvent = (function(){
    // create event function stack
    var load_events = [],
        load_timer,
        script,
        done,
        exec,
        old_onload,
        init = function () {
            done = true;

            // kill the timer
            clearInterval(load_timer);

            // execute each function in the stack in the order they were added
            while (exec = load_events.shift())
                exec();

            if (script) script.onreadystatechange = '';
        };

    return function (func) {
        // if the init function was already ran, just run this function now and stop
        if (done) return func();

        if (!load_events[0]) {
            // for Mozilla/Opera9
            if (document.addEventListener)
                document.addEventListener("DOMContentLoaded", init, false);

            // for Internet Explorer
            /*@cc_on @*/
            /*@if (@_win32)
                document.write("<script id=__ie_onload defer src=//0><\/scr"+"ipt>");
                script = document.getElementById("__ie_onload");
                script.onreadystatechange = function() {
                    if (this.readyState == "complete")
                        init(); // call the onload handler
                };
            /*@end @*/

            // for Safari
            if (/WebKit/i.test(navigator.userAgent)) { // sniff
                load_timer = setInterval(function() {
                    if (/loaded|complete/.test(document.readyState))
                        init(); // call the onload handler
                }, 10);
            }

            // for other browsers set the window.onload, but also execute the old window.onload
            old_onload = window.onload;
            window.onload = function() {
                init();
                if (old_onload) old_onload();
            };
        }

        load_events.push(func);
    }
})();


//
function centerpage()
	{
		
		var myWidth = 0, myHeight = 0;
		if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
			myWidth = window.innerWidth;
			myHeight = window.innerHeight;
		  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
		  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		 //IE 4 compatible
			myWidth = document.body.clientWidth;
			myHeight = document.body.clientHeight;
		  }
		  //window.alert( 'Width = ' + myWidth );
		  //window.alert( 'Height = ' + myHeight );
		
		var w, h, l, t;
		
		//var mainDiv = document.getElementById("main");
		var contDiv = document.getElementById("barebody");
		contDiv.style.paddingTop = (myHeight - 407)/2; // - contDiv.height;
		
		var oDiv = document.getElementById("overlay");
		oDiv.style.height = myHeight;
		
		var action = 0;
		// posizione immage layer
		var theURL = document.location.href;
		//alert(theURL);
		

		if(theURL.indexOf("filmati")>0 || theURL.indexOf("foto")>0 || theURL.indexOf("curiosita")>0)
		{
			var iDiv = document.getElementById("immagine");
			iDiv.style.left = (myWidth-450)/2;
			iDiv.style.top = (myHeight-450)/2;
			iDiv.style.height = 450;
			iDiv.style.width = 450;
		}
		
		if(theURL.indexOf("filmati")>0)
		{
			var iDiv = document.getElementById("immagine2");
			iDiv.style.left = (myWidth-450)/2;
			iDiv.style.top = (myHeight-450)/2;
			iDiv.style.height = 450;
			iDiv.style.width = 450;
			
			var iDiv = document.getElementById("immagine3");
			iDiv.style.left = (myWidth-450)/2;
			iDiv.style.top = (myHeight-450)/2;
			iDiv.style.height = 450;
			iDiv.style.width = 450;
			
			var iDiv = document.getElementById("immagine4");
			iDiv.style.left = (myWidth-450)/2;
			iDiv.style.top = (myHeight-450)/2;
			iDiv.style.height = 450;
			iDiv.style.width = 450;
		}

	}

	addDOMLoadEvent(centerpage);

	window.onresize = function (){
 		centerpage();
	}

function nascondi(ogg) { 
	var im = document.getElementById('immagine');
	im.style.visibility = "hidden";
	
	// solo perf video
	if(document.location.href.indexOf("filmati") > 1)
	{
		for (var i=2;i<=4;i++)
		{
			var im = document.getElementById("immagine"+i);
			im.style.visibility = "hidden";
			//alert(i);
		}
	}
	var obj = document.getElementById(ogg);
	obj.style.visibility = "hidden";
	
	
}
//function mostra(ogg) { var obj = document.getElementById(ogg);obj.style.visibility = "visible";}

function mostra(ogg)
{
	var opacity = "60";

	var o = document.getElementById(ogg);
	o.style.visibility = "visible";
	o.style.opacity = "."+opacity;
	o.style.filter = "alpha(opacity="+opacity+")";
	
	var i = document.getElementById("immagine");
		i.style.visibility = "visible";

}

function mostraVideo(ogg)
{
	var opacity = "60";

	// mostra div bg
	var o = document.getElementById("overlay");
	o.style.visibility = "visible";
	o.style.opacity = "."+opacity;
	o.style.filter = "alpha(opacity="+opacity+")";
	
	// caturare solo 6 majorVer per questo
	//o.filters.item("DXImageTransform.Microsoft.Alpha").Opacity=opacity;
	// fine
	// mostra immagine
	
	var i = document.getElementById(ogg);
	i.style.visibility = "visible";
	

}

function scuro(ogg)
{
	//var o = document.getElementById(ogg);
	//o.style.opacity = .50;
}


function chiaro(ogg) { var obj = obj.style.opacity = ".99";obj.style.filter = "alpha(opacity=99)";}
//function scuro(ogg) { var obj = document.getElementById(ogg);obj.style.opacity = ".50"; obj.filters.item("DXImageTransform.Microsoft.Alpha").Opacity=50;}
function bcolor(obj,color) {obj.style.borderColor = color;}
function swapim(obj,immagine) {document.getElementById(obj).src = immagine;}

function hidePopup(szDivID, iState) // 1 visible, 0 hidden
{
    if(document.layers)	   //NN4+
    {
       document.layers[szDivID].visibility = iState ? "show" : "hide";
    }
    else if(document.getElementById)	  //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(szDivID);
        obj.style.visibility = iState ? "visible" : "hidden";
    }
    else if(document.all)	// IE 4
    {
        document.all[szDivID].style.visibility = iState ? "visible" : "hidden";
    }
}
