/*************************************************************
*METHODS ENABLE TO APPLY RULES OF PRESENTATION TO THE HEADER** 
****************AND THE MENU ABOVE****************************
************Code by EOS -- JANUARY 2010 --********************
**************************************************************/

/* The both methods below enables to apply rules of presentation to the header.
If the my disneyland si not linked, the method moveLayerWithoutLink is called , else the
method moveLayerWithLink is called by the public method moveDownLayer */

// Private

function moveLayerWithLink() {
    var menuHeader = document.getElementById("menuHeader");
    var roundFrame = document.getElementById("menuRoundFrame");
    var menuInsideHeader = document.getElementById("menuInsideHeader");
    var menuHeaderLink = document.getElementById("menuHeaderLink").offsetWidth;
    var frameWidth = roundFrame.offsetWidth;
    var menuHeaderWidth = menuHeader.offsetWidth;    
    var widthMenuInsideHeader = menuHeaderWidth- (menuHeaderLink+ frameWidth+ 30);
    var menuInsideHeaderUl = new Array()
    menuInsideHeaderUl = menuInsideHeader.getElementsByTagName("ul");
    menuInsideHeader.style.width=widthMenuInsideHeader+"px";
    var menuHeaderHeight = menuInsideHeader.offsetHeight;    
    if (menuHeaderHeight > 31) {
        for (var i=0; i<menuInsideHeaderUl.length; i++) {
            menuInsideHeaderUl[i].style.height="22px";
        }
        menuInsideHeader.style.width=(widthMenuInsideHeader-20)+"px";
        menuInsideHeader.style.marginTop="20px";
        menuInsideHeader.style.marginLeft="30px";
    }
    menuHeader.style.visibility="visible";
}
// Private

function moveLayerWithoutLink() {
    var menuHeader = document.getElementById("menuHeader");
    var menuInsideHeader = document.getElementById("menuInsideHeader");
    menuInsideHeader.style.width="600px";
    menuInsideHeader.style.height="10px";
    var menuInsideHeaderli = new Array();
    menuInsideHeaderli = menuInsideHeader.getElementsByTagName("li");
    for (var i = 0; i<menuInsideHeaderli.length; i++) {
        menuInsideHeaderli[i].style.cssFloat="left";
        menuInsideHeaderli[i].style.width="auto";
    }
    menuHeader.style.visibility="visible";
}

// Public

function moveDownLayer() {
    if (document.getElementById("menuRoundFrame") != null) {
        moveLayerWithLink();
    } else {
        moveLayerWithoutLink();
    }
}

// This method enables to make distinction between Internet Explorer Versions - Private

function msieVersion() {
    var ua = window.navigator.userAgent;
    var msie = ua.indexOf ( "MSIE " );
    if ( msie > 0 ) {
        return parseInt (ua.substring (msie+5, ua.indexOf (".", msie )));
    }
    else {
        return 0;
    }
}

// This method applies specific presentation rules to the rollover menu
// If the text of the menu is longer than the box, the menu is affected by
// a sepific styleSheet which allows to display the menu on two lines
// - Public


function displayTwoLines() {
    var menu = document.getElementById("menuContainer");
    var menuUl = menu.getElementsByTagName("ul");
    var menuUlFirstLevel = new Array();
    var j = 0;
    var z = 0;
    var navigateur = navigator.appName;
    var ie = "Microsoft Internet Explorer";
    var menuLi = menu.getElementsByTagName("li");
    var menuStyle = new Array();
    var menuLength = new Array();
    var stringData = new Array();
    var arrayString = new Array();
    var nbreEspace = new Array();
    // Test IE & OPERA
    if (msieVersion() > 6 || navigateur=="Opera" || navigator.platform=="MacPPC") {
        document.getElementById("blueLine").style.marginTop="-1px";
        document.getElementById("imageRightMenu").style.marginTop="-17px";
    }
    //alert("menuLi.length "+menuLi.length);    
    for (var i =0; i<menuUl.length; i+=2) {
        menuUlFirstLevel[j++]=menuUl[i];
    }
    
    for (var y=0; y<menuUlFirstLevel.length;y++) {      

        if (navigateur == ie ) {
            if (y==0) {
                for (var n=0; n<menuLi.length; n++) {                    
                    if (menuLi[n].childNodes[0].firstChild.length>29 && menuLi[n].firstChild.firstChild.data!=menuUlFirstLevel[y].firstChild.firstChild.data) {                        
                        menuLi[n].firstChild.style.lineHeight="18px";
                        menuLi[n].firstChild.style.height="35px";
                    }
                }
            }
            menuStyle[y] = menuUlFirstLevel[y].firstChild.firstChild.style;
            stringData = trim(menuUlFirstLevel[y].firstChild.firstChild.firstChild.data);
            menuLength[y] = (stringData.length)*6;
            arrayString = stringData.split(" ");
            nbreEspace = arrayString.length-1;

            if ((menuLength[y]>102 && menuLength[y]<109) || (menuLength[y]>105 && menuLength[y]<170 && nbreEspace>3)) {
                menuStyle[y].letterSpacing="0.05em";
            }
            if( menuLength[y]>102) {
                menuStyle[y].lineHeight="14px";
                if (msieVersion() == 6) {
                    menuStyle[y].backgroundPosition="0em -0.118em";
                    menuStyle[y].marginTop="4px";
                } else {
                    menuStyle[y].backgroundPosition="-0.45em -0.3em";
                }
            }
        }else {
            if (y==0) {
                for (var n=0; n<menuLi.length; n++) {
                    if (menuLi[n].childNodes[0].firstChild.length>29 && menuLi[n].childNodes[0].firstChild.textContent!=menuUlFirstLevel[y].childNodes[1].firstChild.firstChild.textContent) {
                         
                        menuLi[n].firstChild.style.lineHeight="18px";
                        menuLi[n].firstChild.style.height="35px";
                    }
                }
            }
            menuStyle[y] = menuUlFirstLevel[y].childNodes[1].firstChild.style;
            stringData = trim(menuUlFirstLevel[y].childNodes[1].firstChild.firstChild.textContent);
            menuLength[y] = (stringData.length)*6;
            arrayString = stringData.split(" ");
            nbreEspace = arrayString.length-1;
            var goTo = false;
            if (nbreEspace>2 && menuLength[y]==96) {
                menuStyle[y].lineHeight="14px";
                goTo = true;
            }
            else if (menuLength[y]>=108 && goTo == false) {
                menuStyle[y].lineHeight="14px";
                if (menuLength[y]<=112) {
                    menuStyle[y].letterSpacing="1pt";
                }
            }
        }
    }
}

function trim (myString) {
    return myString.replace(/^\s+/g,'').replace(/\s+$/g,'');
}


/* This method enables to display the login/logout system depending
of the identification mode of the guest - Public */

function displayLoginLogout(){
    var menuInsideHeaderRight = document.getElementById("menuInsideHeaderRight");
    var navBarLi = menuInsideHeaderRight.getElementsByTagName("li");
    if (Get_Cookie( 'LOGIN' )) {
        navBarLi[2].style.display="block";
        navBarLi[1].style.display="none";
    }
    else {
        navBarLi[1].style.display="block";
        navBarLi[2].style.display="none";
    }
}

// This method enables to highlight rollover menu depending where the guest is
// connected - Public

function highLightLink(menuHeaderSelected) {

    if(menuHeaderSelected == '8')
    {
		var MenuImageRightSrc = document.MenuImageRight.src;
		MenuImageRightSrc = MenuImageRightSrc.replace(".jpg", "Select.jpg");
		document.MenuImageRight.src = MenuImageRightSrc;
    }
    else
    {
		var menu = document.getElementById("menuContainer");
		var menuUl = new Array();
		menuUl = menu.getElementsByTagName("ul");
		var menuUlFirstLevel = new Array();
		var j = 0;
		var ApplyToMenu = "";
		var navigateur = navigator.appName;
		var ie = "Microsoft Internet Explorer";
		for (var i =0; i<menuUl.length; i+=2) {
			menuUlFirstLevel[j++]=menuUl[i];
		}
		if (navigateur == ie) {
			ApplyToMenu =  menuUlFirstLevel[menuHeaderSelected].firstChild.firstChild;
			with(ApplyToMenu.style) {
				background="url(http://www.disneylandparis.co.uk/UK/EN/Neutral/Images/107x28-backBlueMenu.jpg)";
				backgroundRepeat="no-repeat";
				backgroundPosition="center";
				color="#fff";
				if (msieVersion() > 6) {
					width="106px";
					marginLeft="-1px";
					marginTop="-1px";
				}
				}
			if (ApplyToMenu.style.lineHeight == "14px"){

				ApplyToMenu.style.marginTop="2px";
				if (msieVersion() > 6) {
					ApplyToMenu.style.marginTop="0px";
				} else {
					ApplyToMenu.style.marginTop="2px";
				}
			}
		}
		else {
			ApplyToMenu =  menuUlFirstLevel[menuHeaderSelected].childNodes[1].firstChild;
			with(ApplyToMenu.style) {
				background="url(http://www.disneylandparis.co.uk/UK/EN/Neutral/Images/107x28-backBlueMenu.jpg)";
				backgroundRepeat="no-repeat";
				backgroundPosition="center";
				width="106px";
				marginLeft="0px";
				color="#fff";
				if (ApplyToMenu.style.lineHeight == "14px"){
					marginTop="1px";
				}
				}
			if (navigateur == "Opera") {
				ApplyToMenu.style.backgroundPosition="50% -0.03em";
			}
		}
	}
}
// this function gets the cookie, if it exists
function Get_Cookie( name ) {
	
var start = document.cookie.indexOf( name + "=" );
if (start!=1){start = document.cookie.indexOf(" "+ name + "=" );}

var len = start + name.length + 1;
if ( ( !start ) &&
(name != document.cookie.substring( 0, name.length ) ) )
{
return null;
}
if ( start == -1 ) return null;
var end = document.cookie.indexOf( ";", len );
if ( end == -1 ) end = document.cookie.length;
return unescape( document.cookie.substring( len, end ) );
}

// put the menu selected to the last tab...
var menuHeaderSelected = '8';
