var curRolled_isOn = false;
var curDivRolled_isOn = false;
var curRolled = '';
var timerId = 0;

var curURL = location.href;
var sitePath = '/'; // default path
if (curURL.indexOf('localhost') > 0) {
    sitePath = '/chadwick/'; // local path
}

function imgRoll(imgRolled, OnOff, OnOverride) {
    curRolled = imgRolled;

    if (OnOff == 'On') {
        clearTheDeck();
        curRolled_isOn = true;
        document.getElementById('img' + curRolled).src = sitePath+'images/nav_btn_' + curRolled + '_' + OnOff + '.png';

        if (!OnOverride) {
            if (curRolled != "AboutUs")
                document.getElementById('div' + curRolled).style.display = 'block';
        }
    } else {
        curRolled_isOn = false;
        timerId = setTimeout("turnOffNav()", 250);
    }
}

function navigateFlyout(OnOff) {
    if (OnOff == 'On') {
        curDivRolled_isOn = true;
        clearTimeout(timerId);
    } else {
        curDivRolled_isOn = false;
        timerId = setTimeout("turnOffNav()", 50);
    }
}

function turnOffNav() {
    if (!curRolled_isOn && !curDivRolled_isOn) {
        document.getElementById('img' + curRolled).src = sitePath + 'images/nav_btn_' + curRolled + '_Off.png';

        if (curRolled != "AboutUs" && curRolled != "Shop")
            document.getElementById('div' + curRolled).style.display = 'none';
    }
}


function clearTheDeck() {
    var sPath = document.URL.toLowerCase();

    if (sPath.indexOf("/products/") < 0) {
        document.getElementById('imgOurBeverages').src = sitePath+'images/nav_btn_OurBeverages_Off.png';
        document.getElementById('divOurBeverages').style.display = 'none';
    }
    if (sPath.indexOf("/about/") < 0) {
        document.getElementById('imgAboutUs').src = sitePath+'images/nav_btn_AboutUs_Off.png';
    }
    if (sPath.indexOf("/share/") < 0) {
        document.getElementById('imgShare').src = sitePath+'images/nav_btn_Share_Off.png';
        document.getElementById('divShare').style.display = 'none';
    }
    if (sPath.indexOf("/shop/") < 0) {
        document.getElementById('imgShop').src = sitePath+'images/nav_btn_Shop_Off.png';
        document.getElementById('divShop').style.display = 'none';
    }
}




function addBookmark() {
    if (document.all) { window.external.AddFavorite("http://"+window.location.hostname+"/", "Chadwick Bay | Home"); }
    else if (window.sidebar) { window.sidebar.addPanel("Chadwick Bay | Home", "http://"+window.location.hostname+"/", ""); }
}





function logoRoll(OnOff) {
    document.getElementById('topnav-holder').style.backgroundImage = 'url(' + sitePath + 'images/nav_logo_' + OnOff + '.png)';
}

function featBtnRoll(theBtn, theBtnOnOff) {
    document.getElementById('btn'+theBtn).src = sitePath+'images/btn_' + theBtn + '_' + theBtnOnOff + '.png';
}




function HomeBGSwap(numBGs) {
    index = numBGs;
    numBG = 1;
    setTimeout('doHomeBGSwap()', 7500);    
}



function doHomeBGSwap() {
    document.getElementById('content-backgrounds-home-temp').style.visibility = 'hidden';
    document.getElementById('content-backgrounds-home').style.visibility = 'visible';
      
    $("#background" + numBG).fadeOut("slow");
    
    if (numBG < index) {
        setTimeout('doHomeBGSwap()', 7500);
    } else if (numBG == 6) {
        numBG = 0;
        setTimeout('doHomeBGSwap()', 7500);
    }
    
    numBG++;
    
    $("#background" + numBG).fadeIn("slow");
}
