var pageReady = false;

//Medidas Generales
var botonera_Pad = 223;
var menuItem_Single = 28;
var menuItem_SingleIE6 = 30;
var menu_Top = 156;
var menu_Width = 115;

function $(id)
{
	var e = document.getElementById(id);
	return (e != null ? e : document.createElement());
}
function isFF() { return (navigator.userAgent.indexOf("Firefox")!=-1); }
function isIE() { return (navigator.appVersion.indexOf("MSIE")!=-1); }
function isIE6() { return (navigator.appVersion.indexOf("MSIE 6.0")!=-1); }
function isIE7() { return (navigator.appVersion.indexOf("MSIE 7.0")!=-1); }

function construct(isHome)
{
	lod(isHome);
	//idflash se carga desde default.aspx.cs
	
	if (isHome)
	{
		if (idflash != -1)
		{
		    PedidoGaleria.startRequest();
		    $('img_marco').style.display = 'block';
		}
	}
	
}
function lod(isHome)
{
	window.onresize = chSize;
	chSize(isHome);
	document.getElementById('ContenidoSeccion').style.display = 'block';
}

function chSize(isHome)
{
	iPadding = document.body.offsetWidth;
    iTotal = (iPadding - 1024) / 2;
	/*
     *  Botonera
     */
    o = $("Footer");
    p = $("ContenidoSeccion");
    //o.style.paddingLeft = botonera_Pad + iTotal - 174 + 'px';
    p.style.marginLeft = (iTotal + botonera_Pad) + 'px';
    
    /*
     *  Menu
     */
    i = 0;
    reg = ypSlideOutMenu.Registry;
    for (menu in reg) 
    {
        newleft = GetLeftPosition(i, true);
        $(menu + 'Container').style.left = newleft;
        i++;
    }
    /*
     *  Marco Galeria
     */
    if (isHome)
    {
        g = $('img_marco');
        if (isIE6())
        {
            g.style.left = 598 + iTotal + 'px';
        }
        else if (isIE7())
        {
		    if (iTotal > -6)
		    {
			    g.style.left = 597 + iTotal + 'px';
		    }
		    else
		    {
			    g.style.left = 590 + 'px';
		    }
        }
        else
        {
		    if (iTotal > -10)
		    {
			    g.style.left = 601 + iTotal + 'px';
		    }
		    else
		    {
			    g.style.left = 590 + 'px';
		    }
            
        }
    }
}
function GetLeftPosition(pos, px)
{
    ileft = (document.body.offsetWidth - 1024)/2 + botonera_Pad;
    value = ileft + (menu_Width * pos);
    if (px) value = value + 'px';
    return value;
}
function GetMenuHeight(positions)
{
    if (isIE6())
    {
        return (positions * menuItem_SingleIE6) + (positions/2);
    }
    else
    {
        return positions * menuItem_Single;
    }
}

var menus = new Array();
	
function preloadImage( url ) {
	var oImage = new Image();
	
	oImage.src = url;
}

function imageOnMouseOver( img ) {
	if( !pageReady )
		return;
	img = checkImage( img );
	img.src = "../images/bt_" + img.id + "_over.gif";
	document.getElementById( img.id + "Label" ).style.color = overColors[img.id];
	document.getElementById( img.id + "Cell" ).style.backgroundColor = bgOverColors[img.id];
	//ypSlideOutMenu.showMenu( img.id );
	selectedMenu = img.id;
}
function backgroundOnMouseOver1(id){
	document.getElementById(id + "Label").style.color = "#5d0d18";
	document.getElementById(id + "Label").style.backgroundImage ="url('images/header/fondo-opcionelegido.png')";
	document.getElementById(id + "Label").style.backgroundRepeat = "repeat-x";
}
function backgroundOnMouseOut1(id){
	document.getElementById(id + "Label").style.color = "#ffffff";
	document.getElementById(id + "Label").style.backgroundImage ="url('images/header/fondo-menu2.png')";
	document.getElementById(id + "Label").style.backgroundRepeat = "repeat-x";
}
function backgroundOnMouseOver2(id){
	document.getElementById(id + "Label").style.color = "#000000";
	document.getElementById(id + "Label").style.backgroundImage ="url('images/header/fondo-menuelegido.png')";
	document.getElementById(id + "Label").style.fontWeight = "bold";
	document.getElementById(id + "Label").style.backgroundRepeat = "repeat-x";
}
function backgroundOnMouseOut2(id){
	document.getElementById(id + "Label").style.color = "#ffffff";
	document.getElementById(id + "Label").style.backgroundImage ="none";
	document.getElementById(id + "Label").style.backgroundColor ="#818181";
	document.getElementById(id + "Label").style.fontWeight = "normal";
}
function imageOnMouseOut( img ) {
	if( !pageReady )
		return;

	img = checkImage( img );
	
	if( selectedMenu != img.id || menuCount[img.id] == 0 ) {
		if( window.currentSubject != getIDRubro( img.id ) ) {
			img.src = "../images/bt_" + img.id + "_off.gif";
		}
		else {
			img.src = "../images/bt_" + img.id + "_on.gif";
		}
		document.getElementById( img.id + "Label" ).style.color = "#6a6a6a";
		document.getElementById( img.id + "Cell" ).style.backgroundColor = "";
		//ypSlideOutMenu.hideMenu( img.id );
	}
}

function onMenuShow( id ) {
	imageOnMouseOver( id );
}

function onMenuHide( id ) {
	imageOnMouseOut( id );
}
	
function getWindowSize() {
	var w = 0, h = 0;
	
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		w = window.innerWidth;
		h = window.innerHeight;
	}
	else {
		if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			w = document.documentElement.clientWidth;
			h = document.documentElement.clientHeight;
		}
		else {
			if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
				//IE 4 compatible
				w = document.body.clientWidth;
				h = document.body.clientHeight;
			}
		}
	}
	
	return { "w" : w, "h" : h }
}

function openWindow( url, width, height, scrollbars, resizable ) {
	if( scrollbars ) {
		scrollbars = "1";
	}
	else {
		scrollbars = "0";
	}
	
	if( resizable ) {
		resizable = "1";
	}
	else {
		resizable = "0"
	}
	
	window.open( url, "Popup", "top=50, left=50, height=" + height + ", width=" + width + ", scrollbars=" + scrollbars + ", menubar=no, titlebar=no, resizable=" + resizable );
}