// CONSTANTES
MIN_HEIGHT = 568;
MAX_HEIGHT = 900; 
MENU_HEIGHT = 190;
MIN_WIDTH = 900;
BG_WIDTH = 1920;
BG_HEIGHT = 800;


function OptionOn(OptionID) {
    document.getElementById(OptionID).className=OptionID + "On";    
}

function OptionOff(OptionID) {
    document.getElementById(OptionID).className=OptionID + "Off";    
}

function FitImage() {

    if (document.getElementById('divY')) {

        if (is.ie6up && !is.ie7) {
            XBody = document.body.clientWidth;
        }
        else if (is.ffox) {
            XBody = window.innerWidth;
        } 
        else if (is.ie7) {
            XBody = document.documentElement.clientWidth; 
        }
        
        YBody = document.getElementById('divY').offsetHeight;
       
        //Ajusto Ancho
        if (XBody <= MIN_WIDTH) {
            document.getElementById('ImgFrame').style.width = MIN_WIDTH + 'px';
        }
        
        if (XBody > MIN_WIDTH) {
            document.getElementById('ImgFrame').style.width = '100%';
        }
        
        //Ajusto Alto
       
        if (YBody < MIN_HEIGHT) {
            document.getElementById('ImgFrame').style.height = MIN_HEIGHT + 'px';
        }
        
        if (YBody >= MIN_HEIGHT && YBody <= MAX_HEIGHT) {
            document.getElementById('ImgFrame').style.height = document.getElementById('divY').offsetHeight + 'px';
        }
        
        if (YBody > MAX_HEIGHT) {
            document.getElementById('ImgFrame').style.height = MAX_HEIGHT + 'px';
        } 
       
        
        //Centro en Marco
        if (XBody <=  BG_WIDTH) {
            document.getElementById('ImgContent').style.marginLeft =  (Math.round((BG_WIDTH - XBody) / 2) * -1) + 'px' ;
        }
        
        if (YBody < MIN_HEIGHT) {
            document.getElementById('ImgContent').style.marginTop = '0px';
        }
        
        if (YBody >= MIN_HEIGHT && YBody <= MAX_HEIGHT) {
            document.getElementById('ImgContent').style.marginTop = '0px';
        }
        
        if (YBody > MAX_HEIGHT) {
            document.getElementById('ImgContent').style.marginTop = (MAX_HEIGHT - BG_HEIGHT) + 'px';
        }
    }
}

function ResizeContent() {

    if (document.getElementById('divY')) {
    
        YBody = document.getElementById('divY').offsetHeight;
        
        if (YBody < MIN_HEIGHT) {
            YContent = MIN_HEIGHT;
        }
        
        if (YBody >= MIN_HEIGHT && YBody <= MAX_HEIGHT) {
            YContent = YBody;
        }
        
        if (YBody > MAX_HEIGHT) {
            YContent = MAX_HEIGHT;
        }
        
        document.getElementById("Content").style.height = YContent + 'px';
    }
}

function ShowImage() {
    document.getElementById('ImgFrame').style.visibility = 'visible';
}

function HideAllMenuImages() {

    document.getElementById('GrupoNoriega').style.visibility = 'hidden';
    document.getElementById('Areas').style.visibility = 'hidden';
    document.getElementById('Valores').style.visibility = 'hidden';
    document.getElementById('Delegaciones').style.visibility = 'hidden';
    document.getElementById('RRHH').style.visibility = 'hidden';
    document.getElementById('Noticias').style.visibility = 'hidden';
    document.getElementById('GrupoSR').style.visibility = 'hidden';
    document.getElementById('FundacionSR').style.visibility = 'hidden';
    document.getElementById('BusquedaInmuebles').style.visibility = 'hidden';
    document.getElementById('PasionDiseno').style.visibility = 'hidden';    
    //document.getElementById('ImgDestacados').style.visibility = 'hidden';    
}

function ShowAllMenuImages() {
        
    document.getElementById('GrupoNoriega').style.visibility = 'visible';
    document.getElementById('Areas').style.visibility = 'visible';
    document.getElementById('Valores').style.visibility = 'visible';
    document.getElementById('Delegaciones').style.visibility = 'visible';
    document.getElementById('RRHH').style.visibility = 'visible';
    document.getElementById('Noticias').style.visibility = 'visible';
    document.getElementById('GrupoSR').style.visibility = 'visible';
    document.getElementById('FundacionSR').style.visibility = 'visible';
    document.getElementById('BusquedaInmuebles').style.visibility = 'visible';
    document.getElementById('PasionDiseno').style.visibility = 'visible';    
    //document.getElementById('ImgDestacados').style.visibility = 'visible';   
}

function ShowMenuImages() {
    if (FirstTime == "True") {
        RunAnimation(0);    
    } else {
        ShowAllMenuImages();
    }
}

function RunAnimation(Step) {

    var StepTime = 100;
    
    switch (Step) {
        case 0:
            setTimeout("RunAnimation(1)",StepTime); 
            break;   
        case 1:
            MakeEffect('ImgGrupoNoriega');
            setTimeout("RunAnimation(2)",StepTime);    
            break;
        
        case 2:
            MakeEffect('ImgAreas');
            setTimeout("RunAnimation(3)",StepTime);    
            break;
        
        case 3:
            MakeEffect('ImgValores');
            setTimeout("RunAnimation(4)",StepTime);    
            break;

        case 4:
            MakeEffect('ImgDelegaciones');
            setTimeout("RunAnimation(5)",StepTime);    
            break;
      
        case 5:
            MakeEffect('ImgRRHH');
            setTimeout("RunAnimation(6)",StepTime);    
            break;

        case 6:
            MakeEffect('ImgNoticias');
            setTimeout("RunAnimation(7)",StepTime);    
            break;

        case 7:
            MakeEffect('ImgGrupoSR');
            setTimeout("RunAnimation(8)",StepTime);    
            break;
            
        case 8:
            MakeEffect('ImgFundacionSR');
            setTimeout("RunAnimation(9)",StepTime);
            break;    
            
        case 9:
            MakeEffect('ImgBusquedaInmuebles');
            setTimeout("RunAnimation(10)",StepTime);
            break;     
            
        case 10:
            MakeEffect('ImgPasionDiseno');
            break;             
    }   
}

function MakeEffect (Obj) {
    document.getElementById(Obj.substr(3, Obj.length-3)).style.visibility = 'visible';
    document.getElementById(Obj).style.filter = 'alpha(opacity=100)'; 
}

function MakeAlpha (obj) {
}


function PlayMenu () {
    FirstTime = document.getElementById('isFirstTime').value;
   
    if (is.ie6up) {
        Player = document.getElementById("LogoHome");
    }
    else if (is.ffox) {
        Player = document.LogoHome;
    } 
    else {
        Player = document.getElementById("LogoHome");
    }

    if (FirstTime == "True") {
        Player.Play();
    } else {
        Player.Play();
        ShowMenuImages(); 
    }
}

function ShowMenu (Path) {
    document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="675" height="19" id="LogoHome">');
    document.write('<param name="allowScriptAccess" value="sameDomain" />');
    document.write('<param name="movie" value="'+Path+'" />');
    document.write('<param name="menu" value="false" />');
    document.write('<param name="play" value="false" />');
    document.write('<param name="scale" value="default" />');
    document.write('<param name="quality" value="high" />');
    document.write('<param name="wmode" value="transparent" />');
    document.write('<embed src="'+Path+'" menu=false play="false" quality=high wmode=transparent scale=default width=675 height=19 name=LogoHome swLiveConnect=true allowScriptAccess=sameDomain type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
    document.write('</object>');
}

function onInit() {
    MaxScreen();
    ResizeContent();
    FitImage();
    ShowImage();
    HideAllMenuImages();
    ShowPage();
    PlayMenu();
}

function onResize() {
    ResizeContent();
    FitImage();
}

/************************************/

if( document.body.addEventListener ) {
    document.body.addEventListener('resize', onResize(),false);  
} else if( document.body.attachEvent ) {
    attachEvent ('onresize', onResize);   
}