var OS = {
    Windows: (navigator.appVersion.indexOf("Win") != -1),
    Macintosh: (navigator.appVersion.indexOf("Mac") != -1),
    Unix: (navigator.appVersion.indexOf("X11") != -1),
    Linux: (navigator.appVersion.indexOf("Linux") != -1),
    OSName: function() {
        if (navigator.appVersion.indexOf("Win") != -1) return "win";
        else if (navigator.appVersion.indexOf("Mac") != -1) return "mac";
        else if (navigator.appVersion.indexOf("X11") != -1) return "uni";
        else if (navigator.appVersion.indexOf("Linux") != -1) return "lin";
        else return 'unknown';
    }
}
        
        

var cmptMode = {

    Quirks: document.compatMode == 'BackCompat', //quirks mode
    Standards: document.compatMode == 'CSS1Compat', //standards compliance mode
    Almost: document.compatMode != 'BackCompat' && document.compatMode != 'CSS1Compat', //Almost Standards Compliance
    ModeType: function() {
        if (document.compatMode == 'BackCompat')
            return 'quirks';
        else if (document.compatMode == 'CSS1Compat')
            return 'standards';
        else
            return 'almost';
    }
}

var IE8Mode = {
    IE8: navigator.userAgent.indexOf('Trident') > -1 && document.documentMode == "8",
    IE8Compat: navigator.userAgent.indexOf('Trident') > -1 && document.documentMode == "7",
    IE8IE7: navigator.userAgent.indexOf('Trident') == -1 && document.documentMode == "7",
    IE8ModeType: function() {
        if (navigator.userAgent.indexOf('Trident') > -1 && document.documentMode == "8")
            return 'IE8Standard';
        else if (navigator.userAgent.indexOf('Trident') > -1 && document.documentMode == "7")
            return 'IE8Compatibility';
        else if (navigator.userAgent.indexOf('Trident') == -1 && document.documentMode == "7")
            return "IE8IE7";
        else return 'unknown';
    }
}


var loca = document.location.pathname.split('/');
var pg = loca[loca.length - 1].split('.')[0];
var pgtlc = pg.toLowerCase();

$j(document).ready(function() {
    if ($j.browser.msie) {
        IEStyles();
    }
    else if ($j.browser.safari) {
        SafariStyles();
    }
    else if ($j.browser.mozilla) {
        FFStyles();
    }
    else {
    }


});

        //handles style adjustments for Safari
        function SafariStyles() {
            $j('.footerCell').each(function(i) {
                $j(this).css({ 'margin-top': '0px' });
            });
            $j('.footerHeaderCell').each(function(i) {
                $j(this).css({ 'margin-top': '5px', 'margin-left': '-1px' });
                if (i == 0)
                    $j(this).css({ 'margin-left': '-2px' });
            });
            $j("#countrySelect_").css({ 'margin-top': '-7px' });
            $j("#countryHeader").css({ 'margin-left': '-1px' });
            $j("#countryLinks").css({ 'margin-top': '5px' });

            if ($j(".fieldNotes").length > 0)
                $j(".fieldNotes").css({ 'margin-top': '68px' });
        }

        //handles style adjustments for IE
        function IEStyles() {

            if (cmptMode.Quirks) {
                $j('.footerHeaderCell').each(function(i) {
                    $j(this).css({ 'display': 'inline' })
                });
                $j('.footerCell').each(function(i) {
                    $j(this).css({ 'display': 'inline' })
                });
                
                $j('.mjFooterHeaderCell').each(function(i) {
                   // alert('');
                    $j(this).css({ 'display': 'inline' })
                });
                $j('.mjFooterCell').each(function(i) {
                    $j(this).css({ 'display': 'inline' })
                });
            }
        
            if (mainHomePage) {
                $j('.footerHeaderCell').each(function(i) {
                    $j(this).css({ 'margin-top': '5px', 'margin-left': '-1px', 'vertical-align': 'middle' })
                });
            }
            if ($j.browser.version == '7.0') {
                $j('.footerCell').each(function() {
                    $j(this).css({ 'display': 'inline', 'float': 'left', 'margin-top': '5px' });
                    if (cmptMode.Quirks)
                        $j(this).css({ 'display': 'inline' })
                });
                $j('.footerHeaderCell').each(function(i) {
                    $j(this).css({ 'display': 'inline', 'float': 'left', 'margin-top': '5px' });

                    if (i == 0)
                        $j(this).css({ 'margin-left': '-1px' });
                });
                $j("#countrySelect_").css({ 'margin-top': '-7px' });
                $j(".tools-navigation").css({ 'margin-top': '50px' });

                if ($j(".tools-navigation").length > 0)
                    $j(".tools-navigation").css({ 'top': '360px' });

                $j('.dialog').children('div.ft').children('div.c').css({ 'margin-bottom': '20px' });

                $j('#mainFooter').css({ 'margin-top': '1px' });
                $j('.pageContent').css({ 'margin-bottom': '-1px' });

                if ($j(".fieldNotes").length > 0)
                    $j(".fieldNotes").css({ 'margin-top': '78px' });

                if ($j('ul.breadcrumb li.first').length > 0) {
                    $j('ul.breadcrumb li.first').css({ 'margin-left': '0px' });
                }

                if ($j('#MyGame').length > 0) {
                    $j('#MyGame').css({ 'margin-top': '-10px' });
                }

                if (pgtlc == 'productfinder_form' && $j('div.internalContent').length > 0) {
                    $j('div.internalContent').css({ 'height': $j('div.formDialog').height() + 'px' });
                }
            }
            else if ($j.browser.version == '8.0') {
                if ($j(".fieldNotes").length > 0)
                    $j(".fieldNotes").css({ 'margin-top': '62px' });
            }
            else if ($j.browser.version == '6.0') {
            
            }
        }

        //handles style adjustments for FireFox
        function FFStyles() {
            var version = 0;
            var splitAgent = navigator.userAgent.split('/');
            version = splitAgent[splitAgent.length - 1].substring(0, 3);
            $j(".searchText").css({ 'vertical-align': 'bottom', 'padding-top': '2px' });

            if (mainHomePage) {
                $j('.footerHeaderCell').each(function(i) {
                        $j(this).css({ 'margin-top': '5px', 'margin-left': '-1px', 'vertical-align': 'middle' })
                });
            }
            
            if (OS.Macintosh) {
                $j('.footerHeaderCell').each(function(i) {
                    if (mainHomePage) {
                        $j(this).css({ 'margin-top': '0px', 'margin-left': '-1px', 'vertical-align': 'middle' })
                    } else {
                        $j(this).css({ 'margin-top': '5px', 'margin-left': '-1px', 'vertical-align': 'middle' })
                    }
                    if (i == 0)
                        $j(this).css({ 'margin-left': '-2px' });
                });
            }
            if (version == '2.0') {
                $j('.footerHeaderCell').each(function(i) {
                    $j(this).css({ 'display': 'inline','float':'left' })
                });

                var prntNode;
                var hgt = 0;
                var y = 0;
                $j('.footerCell').each(function(i) {
                    $j(this).css({ 'display': 'inline', 'float': 'left' })
                    if (y == 2) {
                        prntNode = $j(this).parent();
                        hgt = $j(this).height();
                    }
                    y++;
                });

                prntNode.css({ 'display': 'block', 'height': hgt })
            }
        }


var menusToClose = new Array();
function addTopNavBehavior(context){
	if (!context) context = document.getElementById("primaryNav");
	
	if (context && context.childNodes){
	    for(var i = 0; i < context.childNodes.length; i++){
		    var n = context.childNodes[i];
		    if (n.nodeName == "LI"){
		    
		        if(/MSIE (5|6)/.test(navigator.userAgent)){
	                    n.showSubMenu = showSubMenu;
			            n.hideSubMenu = hideSubMenu;
			            n.onmouseenter = function() { this.className = this.className.replace(new RegExp('\\s+hover', 'g'),''); this.className += " hover"; this.showSubMenu(event);};
			            n.onmouseleave = function() { this.className = this.className.replace(new RegExp('\\s+hover', 'g'),''); this.hideSubMenu(event);}; 
		        }else{
		    	        n.onmouseover = showSubMenu;
			            n.onmouseout = hideSubMenu;
			    }
    			
			
   			    var s = n.getElementsByTagName("OL")[0];
			    if (s)addTopNavBehavior(s);
		    }	
	    }
	}
}



function showSubMenu(e){
    var subMenu = this.getElementsByTagName("OL")[0];
    
    if (!subMenu){
        subMenu = this.getElementsByTagName("DIV")[0];
        //check again whether element is valid
        if(subMenu){
        var imgs = subMenu.getElementsByTagName("IMG");
            for (i=0;i<imgs.length;i++){
              if (imgs[i].className == "productFeatureImage"){
                imgs[i].src = imgs[i].longDesc;
                break;
              }
          }
        }
    }

	if (!e) var e = window.event;
	if (this.closeTimeoutID > 0) this.closeTimeoutID = 0;
	
	this.className = this.className.replace("open", "");

	
	// We don't want to show a submenu for blog, so return
	if (this.className == "blog") 
	{
	    subMenu.style.height = "0px";
	    return;
	}
	
	if (!subMenu) return;
	this.className += " open";
	
	
	subMenu.style.zIndex = 1; /* otherwise borders of sibling dropdowns cause problems */
	subMenu.style.visibility = "visible";
		
	
	if (subMenu.offsetHeight < this.parentNode.offsetHeight) 
		subMenu.style.height = this.parentNode.offsetHeight-2 + "px";

}

function hideSubMenu(e){
	//find a submenu, or leave
	var subMenu = this.getElementsByTagName("OL")[0];
	if (!subMenu) subMenu = this.getElementsByTagName("DIV")[0];
	
	
	//figure out where the mouse is going to
	var relTarg = null;
	if (!e) var e = window.event;
	if (e.relatedTarget) relTarg = e.relatedTarget;
	else if (e.toElement) relTarg = e.toElement;
	
	//if it's going to one of my child elements, don't close anything
	while (relTarg != null && relTarg != this && relTarg.nodeName != 'BODY' && relTarg.nodeName != 'HTML')
		relTarg= relTarg.parentNode
	if (relTarg == this) return;
	
	    this.className = this.className.replace("open", "");
		if (subMenu){ subMenu.style.zIndex = 0;
		            subMenu.style.visibility = "hidden";
		 }
		
	//}
}
	
	
function hideSubMenu_Internal(){	
	var li = menusToClose.shift();	
	
	if (li.closeTimeoutID > 0){	
	
		li.className = li.className.replace("open", "");		
		li.closeTimeoutID = 0;
	}
}


var topNav_oldOnload = window.onload;
window.onload = function(){	
	if (topNav_oldOnload) topNav_oldOnload(); 
	addTopNavBehavior(document.getElementById("primaryNav"));
	addTopNavBehavior(document.getElementById("featuresAndCSNavList"));
}
