﻿// CEFF.JS
 var int_h, int_ci_h, int_cit_h;
 var hovers = new Array();
 var h,w;
 var scrollv,scrollh;
 var flashobj = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="868" height="379"><param name="movie" value="res/Header.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#FFFFFF" /><param name="wmode" value="transparent" /><embed src="res/Header.swf" quality="high" bgcolor="#FFFFFF" width="868" height="379" align="" wmode="transparent" type="application/x-shockwave-flash" pluginspace="http://www.macromedia.com/go/getflashplayer"></embed></object>';
    
    function resize()
    {
        if (typeof(window.innerHeight) == 'number')
        {
            h = window.innerHeight; w = window.innerWidth;
        }
        else
        {
            h = document.documentElement.clientHeight; w = document.documentElement.clientWidth;
        }
        
        if (int_h < h)
        {
            var adjust=h-int_h;
            // allungamento content_inner e tabella
            document.getElementById('content_inner').style.height = int_ci_h + adjust + 'px';
            document.getElementById('content_inner_table').style.height = int_cit_h + adjust + 'px';
        }
        else
        {
            document.getElementById('content_inner').style.height = int_ci_h + 'px';
            document.getElementById('content_inner_table').style.height = int_cit_h + 'px';
        }
        
        // allungamento della linea separatrice fino a fine pagina
        if (document.getElementById('content_inner_line'))
            document.getElementById('content_inner_line').style.height = document.getElementById('content_inner_table').clientHeight + 'px';
         
        // correzione altezza delle ombre 
        var c = document.getElementById('content_outer').clientHeight;
        document.getElementById('ombra_vert_sx').style.height=c + 'px';
	    document.getElementById('ombra_vert_dx').style.height=c + 'px';
	    
	    centeroverlay();
    }
    
    function updh()
    {
        document.getElementById('content_inner').style.height='auto';
        document.getElementById('content_inner_table').style.height='auto';
        int_ci_h = document.getElementById('content_inner').clientHeight;
        int_cit_h = document.getElementById('content_inner_table').clientHeight;
        int_h = document.getElementById('content_inner').clientHeight + document.getElementById('content_flash').clientHeight + document.getElementById('footer').clientHeight;
    }
    
    function scroll()
    {
        scrollv = document.documentElement.scrollTop;
        scrollh = document.documentElement.scrollLeft;
        centeroverlay();
    }
    
    function startup()
    {
        updh();
        if (typeof(init_subpage)=='function') init_subpage();
        resize();
        window.onresize = resize;
        window.onscroll = scroll;
        scroll();
        if (typeof(pngfix_startup)=='function') pngfix_startup();
    }
    
    function printflash()
    {
        document.write(flashobj);
    }
    
    function imghover(id)
    {
        var img=document.getElementById(id).src;
        hovers[id]=img;
        img=img.substring(0, img.length-4) + 'h' + img.substring(img.length-4,img.length);
        document.getElementById(id).src=img;
    }
    
    function imgout(id)
    {
        document.getElementById(id).src=hovers[id];
    }
    
    function overlay_onload()
    {
        var divload = document.getElementById('odivload');
        var divimg = document.getElementById('odivimg');
        divload.innerHTML = showoverlay.desc;
        divimg.appendChild(showoverlay.odivclose);
        centeroverlay();
        var overlay = document.getElementById('overlay');
        overlay.removeChild(divimg);
        document.body.appendChild(divimg);
        divimg.appendChild(showoverlay.img);
    }
    
    function centeroverlay()
    {
        if (!centeroverlay.w && showoverlay.img)
        {
            centeroverlay.w=showoverlay.img.width;
            centeroverlay.h=showoverlay.img.height;
        }
        var divimg = document.getElementById('odivimg');
        var overlay = document.getElementById('overlay');
        if (overlay)
        {
            if (centeroverlay.w>w)
            {
                var w_init = centeroverlay.w;
                showoverlay.img.width=w-100;
                showoverlay.img.height=centeroverlay.h*(showoverlay.img.width/w_init);
            }
            
            if (centeroverlay.h>h)
            {
                var h_init = centeroverlay.h;
                showoverlay.img.height=h-100;
                showoverlay.img.width=centeroverlay.w*(showoverlay.img.height/h_init);
            }
            divimg.style.width = showoverlay.img.width+'px';
            divimg.style.height = showoverlay.img.height+'px';
            divimg.style.left = scrollh+w/2-showoverlay.img.width/2+'px';
            divimg.style.top = scrollv+h/2-showoverlay.img.height/2+'px';
            overlay.style.top = scrollv+'px';
            overlay.style.left=scrollh+'px';
            overlay.style.height = h+'px';
        }
    }
    
    function showoverlay(image, description)
    {
        if (!showoverlay.incr) showoverlay.incr=h/8;
        showoverlay.desc = unescape(description);
        scrollv = document.documentElement.scrollTop;
        scrollh = document.documentElement.scrollLeft;
        var overlay = document.getElementById('overlay');

        if (!overlay)
        {
            var overlay = document.createElement('div');
            overlay.setAttribute('id', 'overlay');
            overlay.style.top=scrollv+'px';
            overlay.style.left=scrollh+'px';
            var odivimg = document.createElement('div');
            odivimg.setAttribute('id', 'odivimg');
            odivimg.style.top = h/2-odivimg.clientHeight/2 + 'px';
            odivimg.style.left = w/2-185 + 'px';
            showoverlay.odivclose = document.createElement('div');
            showoverlay.odivclose.setAttribute('id', 'odivclose');
            showoverlay.odivclose.appendChild(document.createTextNode('Chiudi  '));
            var ocloseimg = new Image();
            ocloseimg.src = 'img/pop_close.gif';
            var ocloselink = document.createElement('a');
            ocloselink.onclick = hideoverlay;
            ocloselink.appendChild(ocloseimg);
            showoverlay.odivclose.appendChild(ocloselink);
            var odivload = document.createElement('div');
            odivload.setAttribute('id', 'odivload');
            odivload.appendChild(document.createTextNode('caricamento'));
            odivimg.appendChild(odivload);
            overlay.appendChild(odivimg);
            document.body.appendChild(overlay);
            setTimeout("showoverlay('"+image+"','"+description+"')", 25);
            return;
        }
        else
            overlay.style.display='block';
        
        if (overlay.clientHeight+showoverlay.incr*0.9 > h)
        {
            overlay.style.height = h+'px';
            showoverlay.img = new Image();
            showoverlay.img.onload=overlay_onload;
            showoverlay.img.src=image;
            showoverlay.incr=0;
        }
        else
        {
            overlay.style.height = overlay.clientHeight+showoverlay.incr*0.9 + 'px';
            showoverlay.incr*=0.9;
            setTimeout("showoverlay('"+image+"','"+description+"')", 25);
        }
    }
    
    function hideoverlay()
    {
        var overlay = document.getElementById('overlay');
        if(overlay)
        {
            document.body.removeChild(overlay);
            document.body.removeChild(document.getElementById('odivimg'));
        }
        centeroverlay.w=null;
        centeroverlay.h=null;
    }
    
    function cambiaDiv(idnew)
    {
        var idnl;
        for(var i=0; i<menudiv.length; i++)
        {
            document.getElementById(menudiv[i]).style.display='none';
            idnl = document.getElementById(menudiv[i] + '_l')
            if(idnl != null)
                document.getElementById(menudiv[i] + '_l').className='menu';
        }
                
        document.getElementById(idnew).style.display='block';
        idnl = document.getElementById(idnew+'_l');
        if(idnl!=null)
            document.getElementById(idnew+'_l').className='selected';
        
        updh();
        resize();
    }
