
// Spacers
var theHeightSpacer;
var theWidthSpacer;
var theMinWidth;
var theTopHeight;

function hideLoading(){
    if( DEBUGJS ) alert("hideLoading");
    $('progressBar').hide();
    var myM = getStyleObject('main');
    myM.visibility = 'visible';
}

function pageOnResize(myWH){return;}

// Window resize manager
window.onresize = doResize;
function doResize() {
    if( DEBUGJS ) alert("doResize");
    var myOV = getStyleObject('vspacermenu');
    var myOH = getStyleObject('hspacermain');
    if ( !myOV && !myOH ) return;
    var myWH = Position.GetWindowSize();
    if ( myOV  ) {
        if( DEBUGJS ) alert("pageOnResize - myOV="+myOV);
        // TODO : eliminare gli alerts per l'utente. Loggare tramite ajax.
        if ( isNaN(theHeightSpacer) ) { alert("errore, contattare l 'amministratore: codice OHS");return; }
        if ( isNaN(theTopHeight) ) { alert("errore, contattare l 'amministratore: codice OHST");return; }
        var myHeight = myWH[1] - theTopHeight  - theHeightSpacer; 
        if( myHeight < 0 ) {
            myHeight = 0;
        } else {
            myHeight = myHeight/2;
        }
        //myOV.height = myHeight +"px";
        if( DEBUGJS ) alert("pageOnResize - myHeight="+myHeight);
        if( DEBUGJS ) alert("pageOnResize - myOV.height="+myOV.height);
    }
    if ( myOH  ) {
        if( DEBUGJS ) alert("pageOnResize - myOH="+myOH);
        if ( isNaN(theWidthSpacer) ) { alert("errore, contattare l 'amministratore: codice OWS");return; }
        var myWidth = 0;
        if ( theWidthSpacer > 0 ) {
            myWidth = myWH[0] - theWidthSpacer;
            if( myWidth < 0 ) myWidth = 0; 
        }
        if ( !isNaN(theMinWidth) && myWidth == 0 ) {
            var myOM = getStyleObject('main');
            myOM.width = "100%";
            myOH.width = theMinWidth + "px";
        } else {
            myOH.width = myWidth/2 + "px";
        }
    }
    pageOnResize(myWH); 
}

function getStyleObject(objectId) {
    if( DEBUGJS ) alert("getStyleObject");
    // checkW3C DOM, then MSIE 4, then NN 4.
    //
    if(document.getElementById && document.getElementById(objectId)) {
        return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
        return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
        return document.layers[objectId];
    } else {
        return false;
    }
}

Position.GetWindowSize = function(w) {
    if( DEBUGJS ) alert("Position.GetWindowSize"+w);
    w = w ? w : window;
    var width = w.innerWidth || (w.document.documentElement.clientWidth || w.document.body.clientWidth);
    var height = w.innerHeight || (w.document.documentElement.clientHeight || w.document.body.clientHeight);
    if( DEBUGJS ) alert("Position.GetWindowSize"+width+"-"+height);
    return [width, height];
}



function setProgressbar() {             
    /*var pbObj = NEW_GLASSBOX;
    pbObj.init( 'progressBar', '240px', '60px', 'hidden', 'default' );
    pbObj.apos( '100px', '60px' );
    pbObj.appear(); */
    //centerLayer('progressBar', 240, 60);
    //preloadImages();
    var myObj = NEW_GLASSBOX;
    myObj.init( 'progressBar', '185px', '60px', 'hidden' );
    //myObj.apos( '200px', '150px' );
    myObj.ipos(); 
}


Ajax.Responders.register(
    {
        onCreate: function() {
            //if($('loading') && Ajax.activeRequestCount>0)
            if(Ajax.activeRequestCount>0) {
                $('ajax-loading').visibility = 'show';
            }
        },
 
        onComplete: function() {
            if(Ajax.activeRequestCount==0) {
                //
            }
        }
    }
);

function ajax_loading(){
    alert('loading')
}

function showBrand(){document.location="/brand/";}
function showProduct(){alert("In allestimento,torna presto per conoscere a fondo il nostro prodotto");}
function showStores(){document.location="/stores/";}

function goHome(){document.location="/";}
function goBO(){document.location="/backoffice/";}


