﻿var naviLookup = [];
naviLookup["Rider"] = "f5853a";
naviLookup["New Rider"] = "15ac5b";
naviLookup["Business"] = "9753a0";
naviLookup["Community Connections"] = "f5c63a";

function fixStyle(menuID) {
    var menu = document.getElementById(menuID);
    if (menu != null) {
        items = menu.getElementsByTagName("li");
        if (items.length > 0) {
            items[items.length - 1].style.border = "none";
        }
    }
}

function highlightMenuItem(menuID) {
    var menu = document.getElementById(menuID);
    if (menu == null) { return; }
    adjustColor(menu);
    var links = menu.getElementsByTagName("a");

    var currentLocation = getLeaf(document.location.href);
    for (i = 0; i < links.length; i++) {
        var currentHref = links[i].getAttribute("href");
        var currentLeafName = getLeaf(currentHref);
        if (currentLeafName == currentLocation) {
            //// Setting class is needed for Mozilla compatibility - className appears to be correct 
            //// according to the DOM spec
            links[i].setAttribute("class", "current");
            links[i].setAttribute("className", "current");
        }
    }
    if ($(menu).attr("class") == "hdemo" && links.length > 0) {
        links[links.length - 1].innerHTML = "<img src='/images/community_connections.gif' alt='Community Connections'>";
    }
}

function getLeaf(url) {
    //alert(url);
    var first = url.indexOf("/");
    var last = url.lastIndexOf("/");
    if (first == 0) {
        if (last == url.length - 1) {
            return url;
        }
        else {
            return url.substring(last);
        }
    }
    if (last == url.length - 1) {
        first = url.indexOf("/", 10);
        return url.substring(first);
    }
    else {
        return url.substring(last);
    }
}

function adjustColor(menu) {
    var items = menu.getElementsByTagName("li");
    if (items != null && items.length > 0) {
        var title = items[0].innerHTML;
        //alert(title);
        if (naviLookup[title] != null) {
            $(menu).css("background-color", "#" + naviLookup[title]);
            $(".navi").css("background-color", "#" + naviLookup[title]);
            $("#subNavi > *").css("background-color", "#" + naviLookup[title]);
            $(".SubNavi td.NaviLf").css("background-image", "url(/images/" + naviLookup[title] + "_SNLf.png)");
            $(".SubNavi td.NaviRt").css("background-image", "url(/images/" + naviLookup[title] + "_SNRt.png)");
            //alert("url(/images/" + naviLookup[title] + "_SNRt.png)");
            $(".SubNavi div.right").css("border-top-color", "#" + naviLookup[title]);
        }
    }
}

function getFooterText(parent, child) {
    $("#MsgCd").text(child);
    //if ($("#MsgCd").text() != $("#menuTitle").val())
    if (parent == "") {
        if ($("#menuTitle").val() == null) {
            $("#MsgTt").text(child);
        }
        else {
            $("#MsgTt").text($("#menuTitle").val());
        }
    }
    else {
        $("#MsgTt").text(parent);
    }
}


function setUpCarousel(id, next, prev, vertical, visible, scroll, circular) {
    $(id).jCarouselLite({
        btnNext: next,
        btnPrev: prev,
        vertical: vertical,
        visible: visible,
        scroll: scroll,
        circular: circular
    });
}


var index = 1;
function paging(control, next) {
    lastImg = currentImg = $(control).parent().find("div").eq(index).find("img:first");
    lastImg.attr("src", lastImg.attr("src").replace("selected.gif", ".gif"));
    if (next) {
        if (index == 5) index = 1;
        else index++;
    }
    else {
        if (index == 1) index = 5;
        else index--;
    }
    currentImg = $(control).parent().find("div").eq(index).find("img:first");
    currentImg.attr("src", currentImg.attr("src").replace(".gif", "selected.gif"));
}


jQuery.preloadImages = function() {
    for (var i = 0; i < arguments.length; i++) {
        //alert("/images/" + arguments[i]);
        jQuery("<img>").attr("src", "/images/" + arguments[i]);
    }
}


//function getQuerystring(key, default_) {
//    if (default_ == null) default_ = "";
//    key = key.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
//    var regex = new RegExp("[\\?&]" + key + "=([^&#]*)");
//    var qs = regex.exec(window.location.href);
//    if (qs == null)
//        return default_;
//    else
//        return qs[1];
//}


$(document).ready(function() {
    var ecmCookie = $.cookie("ecm");
    var index = ecmCookie.indexOf("SiteLanguage");
    var offset = ("SiteLanguage=").length;
    var siteLang = ecmCookie.substring(index + offset, ecmCookie.length);
    //alert(siteLang);

    if (siteLang == "1034") {
        $(".toolbarBoxBefore").css('background-image', 'url(/Images_Spanish/toolbarBg.gif)');
        $("#iframeGoogleTransit").attr("src", "/HTML/GoogleTransit_Spanish.htm");
        $("#iframeTripPlanner").attr("src", "/HTML/TripPlanner_Spanish.htm");
    }

    $("ul.introMenu li a img").mouseover(function() {
        var imgSrc = $(this).attr("src");
        imgSrc = imgSrc.replace("off", "on");
        $(this).attr("src", imgSrc);
    }).mouseout(function() {
        var imgSrc = $(this).attr("src");
        imgSrc = imgSrc.replace("on", "off");
        $(this).attr("src", imgSrc);
    });
});