﻿
var myfloor = 415;
var currentbrowser = getBrowser();
if (currentbrowser == "MSIE") {
    var v = getInternetExplorerVersion();
    switch (v) {
        case 8:
            AttachStyleSheet("/Portals/_default/Skins/TehamaEDC/hometemplate_ie8.css");
            myfloor = 417;
            break;
        case 7:
            AttachStyleSheet("/Portals/_default/Skins/TehamaEDC/hometemplate_ie7.css");
            break;
        case 6:
            AttachStyleSheet("/Portals/_default/Skins/TehamaEDC/hometemplate_ie6.css");
            break;
    }
}
if (currentbrowser == "FF") {
    AttachStyleSheet("/Portals/_default/Skins/TehamaEDC/hometemplate_FF3.css");
    myfloor = 395;
}
if (currentbrowser == "Chrome") {
    AttachStyleSheet("/Portals/_default/Skins/TehamaEDC/hometemplate_Chrome.css");
    myfloor = 377;
}
if (currentbrowser == "Safari") {
    AttachStyleSheet("/Portals/_default/Skins/TehamaEDC/hometemplate_Safari.css");
}

var el = document.getElementById('menu');
if (el)
{
var i = 0;
for (i = 0; i < el.childNodes.length; i++) {
    var j = 0;
    for (j = 0; j < el.childNodes.item(i).childNodes.length; j++) {
        var itemheight = el.childNodes.item(i).childNodes.item(j).offsetHeight;
        var itemtop = el.childNodes.item(i).childNodes.item(j).offsetTop;
        var itemfloor = itemheight + itemtop;
        if (itemfloor > myfloor) {
            el.childNodes.item(i).childNodes.item(j).style.marginTop = -(itemfloor - myfloor) + "px";
        }
    }
}
}

//This function gets the browser type
function getBrowser() {
    var b = "none";
    if (navigator.userAgent.indexOf('MSIE') !=-1)
    {
        b = "MSIE";
    }
    if (navigator.userAgent.indexOf('Firefox') != -1) {
        b = "FF";
    }
    if (navigator.userAgent.indexOf('Safari') != -1) {
        b = "Safari";
    }
    //Chrome has to come last because safari is listed in the useragent for chrome but not the other way around
    if (navigator.userAgent.indexOf('Chrome') != -1) {
        b = "Chrome";
    }

    return b;
}

//This function gets the IE version
function getInternetExplorerVersion() {

    var rv = -1; // Return value assumes failure.

    if (navigator.appName == 'Microsoft Internet Explorer') {

        var ua = navigator.userAgent;

        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");

        if (re.exec(ua) != null)

            rv = parseFloat(RegExp.$1);

    }

    return rv;

}

function AttachStyleSheet(path)
{
    var oLink = document.createElement("link")
    oLink.href = path;
    oLink.rel = "stylesheet";
    oLink.type = "text/css";
    document.body.appendChild(oLink);
}
