// JScript File
// Luca Bezzan Fab Software
var checkIE = 10;

function funcSetFinestra(path) {
    //'img/AboutUsFlash.swf'
	obj = document.getElementById("Finestra");
    
    var detect = navigator.userAgent.toLowerCase();
    if (detect.indexOf("msie")>0) checkIE = detect.substr(detect.indexOf("msie") + 1 + "msie".length, 3);
 
	if(obj.style.display=="none") {

        var flashvars = {}; var attributes = {};
        var params = {}; params.quality = "high"; params.loop = "false"; params.scale = "true";
        swfobject.embedSWF(path, "objFlash", "100%", "100%", "9.0.0", "expressInstall.swf", flashvars, params, attributes);

	    obj.style.display = "block";
	    assettaFinestra();
        document.getElementById("Finestra").style.filter = "progid:DXImageTransform.Microsoft.Alpha(Opacity='75')"
        document.getElementById("Finestra").style.MozOpacity = 0.75;
        document.getElementById("Finestra").style.opacity = "0.75";
        //alert(swfobject.hasFlashPlayerVersion("9.0.0"));
        if (swfobject.hasFlashPlayerVersion("9.0.0")!=false) document.getElementById("objFlash").Play();
	} else {
	    if (swfobject.hasFlashPlayerVersion("9.0.0")!=false) document.getElementById("objFlash").Rewind();
        obj.style.display = "none";
	    //document.getElementById("Finestra").style.filter = "progid:DXImageTransform.Microsoft.Alpha(Opacity='100')"
	    //document.getElementById("Finestra").style.MozOpacity = 1;
        //document.getElementById("Finestra").style.opacity = "1";
	}
}

function assettaFinestra() {
	var obj = document.getElementById("Finestra");
	var arrayPageSize = getPageSize();
    var arrayPageScroll = getPageScroll();
    var widthFlash = arrayPageSize[2]-100
    var heightFlash= arrayPageSize[3]-100;

    if (widthFlash>heightFlash/0.75) { widthFlash = heightFlash/0.75 }
    document.getElementById("divFlash").style.width = widthFlash + "px";
    document.getElementById("divFlash").style.height = widthFlash * 0.75 + "px";

    var FinestraTop = arrayPageScroll[1];
	if(checkIE<7) {
	    obj.style.top = FinestraTop + "px";
        obj.style.left= (arrayPageSize[2] - widthFlash)/2 + "px";
    } 
}

// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		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
		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 = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
function getPageScroll(){
	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
}
