/*****************************************************
///// DHTML Code for Menu Items///////////////////////
*****************************************************/
var numSubMenuItems=10;
var sections=["home","news","drivers","races","kyn","wireless","travel","comm","auto","games","members_club","store","trackpass"];
var maps=["0,0,42,25","43,0,85,25","87,0,140,25","142,0,185,25","187,0,235,25","237,0,298,25","300,0,350,25","352,0,413,25","415,0,498,25","500,0,548,25","550,0,642,25","644,0,686,25","688,0,759,25"];

/*********Menu items definitions (stored in arrays)**********/
//  news dd
subMenuItems1=[["Today's News","Headlines","News Wire","Business News","Features","Opinion","Newsletter","Photo Galleries"],
               ["http://www.nascar.com/news/","http://www.nascar.com/news/headlines/","http://www.nascar.com/news/headlines/newswire/","http://www.nascar.com/news/business/","http://www.nascar.com/news/features/","http://www.nascar.com/news/opinion/","http://www.nascar.com/news/newsletter/","http://www.nascar.com/multimedia/photo_gallery/"] ];
//  drivers, teams dd
subMenuItems2=[["News and Stats","A-Z Driver History","2005 Drivers","Teams","Crew Chiefs","Manufacturers","Driver Vs. Driver","Car Number Index"],
               ["http://www.nascar.com/drivers/","http://www.nascar.com/drivers/list/cup/dps/all_drivers_A.html","http://www.nascar.com/drivers/list/cup/dps/","http://www.nascar.com/drivers/list/cup/tps/owner_team_series_index.html","http://www.nascar.com/drivers/list/cup/ccps/","http://www.nascar.com/drivers/mps/","http://www.nascar.com/drivers/dvd/","http://www.nascar.com/kyn/nbtn/cup/data/car/"] ];
//  races dd
subMenuItems3=[["This Week's Race","Results","Standings","Past Races","Tracks","Schedule","Tune In","Tickets"],
               ["http://www.nascar.com/races/","http://www.nascar.com/races/cup/2005/rr_index.html","http://www.nascar.com/races/cup/2005/data/standings_official.html","http://www.nascar.com/races/cup/","http://www.nascar.com/races/tracks/","http://www.nascar.com/races/cup/2005/data/schedule.html","http://www.nascar.com/races/tune_in/","http://www.nascar.com/races/tickets/cup/"] ];
//  know your nascar, basics dd
subMenuItems4=[["At-A-Glance","NASCAR 101","History","Car Number Index","Statistics","Tech","Families of NASCAR","Women"],
               ["http://www.nascar.com/kyn/","http://www.nascar.com/kyn/nascar_101/","http://www.nascar.com/kyn/history/","http://www.nascar.com/kyn/nbtn/cup/data/car/","http://www.nascar.com/kyn/nbtn/","http://www.nascar.com/kyn/tech/","http://www.nascar.com/kyn/families/","http://www.nascar.com/kyn/women/"] ];
//  travel connect dd
subMenuItems5=[["At-A-Glance","Chat","Message Boards","Fan Clubs","Collectibles","Screensavers"],

["http://www.nascar.com/comm/","http://www.nascar.com/comm/chat/","http://boards.nascar.com","http://www.nascar.com/comm/fan_clubs/","http://www.nascar.com/2005/comm/collectibles/archive/","http://www.nascar.com/promos/redirects/2005/screensavers/dropdown.exclude.html"] ];
//  automotive dd
subMenuItems6=[["Performance Locator","Be Car Care Aware Tips"],
               ["http://www.nascar.com/auto/","http://www.nascar.com/auto/cct/"] ];
//  games dd
subMenuItems7=[["Fantasy Games","Contests &amp; Sweepstakes","The Game Room","Games FAQ"],
               ["http://www.nascar.com/games/","http://www.nascar.com/games/contest/","http://www.nascar.com/games/room/","http://www.nascar.com/games/faq.html"] ];
//  members_club dd
subMenuItems8=[["At-A-Glance","Member Login","Enroll Now","Give A Gift"],
               ["http://www.nascar.com/members_club/","http://audience.nascar.com/services/nascar/nmc/members/","http://audience.nascar.com/services/nascar/nmc/join/","https://www.membersclub.nascar.com/MeToo.aspx"] ];
//  store dd
subMenuItems9=[[
"Shop Now","Dale Earnhardt Jr. Gear ","Jeff Gordon Gear","Die-Cast","Tees","Tailgating"],

[
"http://store.nascar.com/entry.point?target=z&source=NASCAR_DHTML:shopnow:03_02_05",
"http://store.nascar.com/entry.point?entry=715551&source=NASCAR_DHTML:dalejrgear:10_25_04",
"http://store.nascar.com/entry.point?entry=715561&source=NASCAR_DHTML:gordon:06_20_05",
"http://store.nascar.com/entry.point?entry=1252984&source=NASCAR_DHTML:diecast:06_20_05",
"http://store.nascar.com/entry.point?entry=1251497&source=NASCAR_DHTML:tees:06_20_05",
"http://store.nascar.com/entry.point?entry=1251517&source=NASCAR_DHTML:tailgating:06_20_05"] ];

//  trackpass dd
subMenuItems10=[["About TrackPass","Schedule","Race Clips","Driver Clips","Special Features","User Guide"],
               ["http://www.nascar.com/multimedia/about/","http://www.nascar.com/multimedia/live/","http://www.nascar.com/multimedia/video/","http://www.nascar.com/multimedia/drivers/","http://www.nascar.com/multimedia/feature/","http://kb.nascar.cust-serv.com/nascarKB/"] ]; 
/***************************************/
//write DHTML code for menu items
function writeMenus()
{
    var d=document;
    for (i=1;i<=numSubMenuItems;i++)
    {
        var currentItems=eval("subMenuItems"+i);
        d.write("<div id=\"menu"+i+"Container\"><div id=\"menu"+i+"Content\" class=\"submenu\"><div class=\"options\">");
        for (j=0;j<currentItems[0].length;j++) d.write("<a href=\""+currentItems[1][j]+"\">"+currentItems[0][j]+"</a>");
        d.write("</div></div></div>");
    }
}
//write image maps
function writeImageMaps(section)
{
    var d=document;
    var menuNum=1;
    d.write("<table align=\"center\" cellpadding=\"0\" cellspacing=\"0\" width=\"760\"><tr><td><div style=\"position:relative;\">");
    writeMenus();
    d.write("<img src=\"http://i.cnn.net/nascar/.element/1.0/img/nav/tn/header/2005_tn_header_"+section+".gif\" width=\"760\" height=\"26\" border=\"0\" usemap=\"#nav\">");
    if (section=="home") {d.write("</div></td></tr><tr><td class=\"navTime\">");writeDate();}
    else d.write("<br><img src=\"http://i.cnn.net/nascar/.element/1.0/img/nav/tn/subnav/2005_tn_subnav_"+section+".gif\" width=\"760\" height=\"38\" border=\"0\" usemap=\"#subnav\"></div>");
    d.write("</td></tr></table><map name=\"nav\">");
    for (i=0;i<sections.length;i++)
    {
        d.write("<area shape=\"rect\" coords=\""+maps[i]+"\"");
        d.write(" href=\""+(sections[i]=="store" ? "http://store.nascar.com\"" : sections[i]=="home" ? "http://www.nascar.com/\"" : sections[i]=="travel" ? "http://www.nascar.com/travel/\"" : sections[i]=="comm" ? "http://www.nascar.com/comm/\"" : sections[i]=="trackpass" ? "http://www.nascar.com/multimedia/\"" : ("http://www.nascar.com/"+sections[i]+"/\"")));
        d.write((sections[i]=="home" || sections[i]=="wireless" || sections[i]=="travel" || sections[i]==section) ? ">" : ("id=\"act"+(menuNum-1)+"\" onmouseover=\"ypSlideOutMenu.showMenu('menu"+menuNum+"');\" onmouseout=\"ypSlideOutMenu.hideMenu('menu"+menuNum+"');\">"));
        if (sections[i]!="home" && sections[i]!="wireless" && sections[i]!="travel") menuNum++;
    }
    d.write("</map>");
}
//writes the date
function writeDate()
{
    var months=["January","February","March","April","May","June","July","August","September","October","November","December"];
    var dateStamp = new Date();
    document.write(months[dateStamp.getMonth()]+" | "+dateStamp.getDate()+" | "+dateStamp.getFullYear());
}

/*****************************************************
///// finish DHTML Code for Menu Items////////////////
*****************************************************/

/*****************************************************
///// DHTML Code for Top Navigation //////////////////
*****************************************************/
ypSlideOutMenu.Registry = []
ypSlideOutMenu.aniLen = 2
ypSlideOutMenu.hideDelay = 25
ypSlideOutMenu.minCPUResolution = 10
// constructor
function ypSlideOutMenu(id, dir, left, top, width, height)
{
    this.ie = document.all ? 1 : 0
    this.ns4 = document.layers ? 1 : 0
    this.dom = document.getElementById ? 1 : 0
    if (this.ie || this.ns4 || this.dom)
    {
        this.id = id
        this.dir = dir
        this.orientation = dir == "left" || dir == "right" ? "h" : "v"
        this.dirType = dir == "right" || dir == "down" ? "-" : "+"
        this.dim = this.orientation == "h" ? width : height
        this.hideTimer = false
        this.aniTimer = false
        this.open = false
        this.over = false
        this.startTime = 0
        this.gRef = "ypSlideOutMenu_"+id
        eval(this.gRef+"=this")
        ypSlideOutMenu.Registry[id] = this
        var d = document
        var strCSS = '<style type="text/css">';
        strCSS += '#' + this.id + 'Container { visibility:hidden; '
        strCSS += 'left:' + left + 'px; '
        strCSS += 'top:' + top + 'px; '
        strCSS += 'overflow:hidden; z-index:10000; }'
        strCSS += '#' + this.id + 'Container, #' + this.id + 'Content { position:absolute; '
        strCSS += 'width:' + width + 'px; '
        strCSS += 'height:' + height + 'px; '
        strCSS += 'clip:rect(0 ' + width + ' ' + height + ' 0); '
        strCSS += '}'
        strCSS += '</style>'
        d.write(strCSS)
        this.load()
    }
}

ypSlideOutMenu.prototype.load = function()
{
    var d = document
    var lyrId1 = this.id + "Container"
    var lyrId2 = this.id + "Content"
    var obj1 = this.dom ? d.getElementById(lyrId1) : this.ie ? d.all[lyrId1] : d.layers[lyrId1]
    if (obj1) var obj2 = this.ns4 ? obj1.layers[lyrId2] : this.ie ? d.all[lyrId2] : d.getElementById(lyrId2)
    var temp
    if (!obj1 || !obj2) window.setTimeout(this.gRef + ".load()", 100)
    else
    {
        this.container = obj1
        this.menu = obj2
        this.style = this.ns4 ? this.menu : this.menu.style
        this.homePos = eval("0" + this.dirType + this.dim)
        this.outPos = 0
        this.accelConst = (this.outPos - this.homePos) / ypSlideOutMenu.aniLen / ypSlideOutMenu.aniLen
// set event handlers.
        if (this.ns4) this.menu.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT);
        this.menu.onmouseover = new Function("ypSlideOutMenu.showMenu('" + this.id + "')")
        this.menu.onmouseout = new Function("ypSlideOutMenu.hideMenu('" + this.id + "')")
//set initial state
        this.endSlide()
    }
}

ypSlideOutMenu.showMenu = function(id)
{
    var reg = ypSlideOutMenu.Registry
    var obj = ypSlideOutMenu.Registry[id]
    if (obj.container)
    {
        obj.over = true
        for (menu in reg) if (id != menu) ypSlideOutMenu.hide(menu)
        if (obj.hideTimer) { reg[id].hideTimer = window.clearTimeout(reg[id].hideTimer) }
        if (!obj.open && !obj.aniTimer) reg[id].startSlide(true)
    }
}

ypSlideOutMenu.hideMenu = function(id)
{
    var obj = ypSlideOutMenu.Registry[id]
    if (obj.container)
    {
        if (obj.hideTimer) window.clearTimeout(obj.hideTimer)
        obj.hideTimer = window.setTimeout("ypSlideOutMenu.hide('" + id + "')", ypSlideOutMenu.hideDelay);
    }
}

ypSlideOutMenu.hideAll = function()
{
    var reg = ypSlideOutMenu.Registry
    for (menu in reg)
    {
        ypSlideOutMenu.hide(menu);
        if (menu.hideTimer) window.clearTimeout(menu.hideTimer);
    }
}

ypSlideOutMenu.hide = function(id)
{
    var obj = ypSlideOutMenu.Registry[id]
    obj.over = false
    if (obj.hideTimer) window.clearTimeout(obj.hideTimer)
    obj.hideTimer = 0
    if (obj.open && !obj.aniTimer) obj.startSlide(false)
}

ypSlideOutMenu.prototype.startSlide = function(open)
{
    this[open ? "onactivate" : "ondeactivate"]()
    this.open = open
    if (open) this.setVisibility(true)
    this.startTime = (new Date()).getTime()
    this.aniTimer = window.setInterval(this.gRef + ".slide()", ypSlideOutMenu.minCPUResolution)
}

ypSlideOutMenu.prototype.slide = function()
{
    var elapsed = (new Date()).getTime() - this.startTime
    if (elapsed > ypSlideOutMenu.aniLen) this.endSlide()
    else
    {
        var d = Math.round(Math.pow(ypSlideOutMenu.aniLen-elapsed, 2) * this.accelConst)
        if (this.open && this.dirType == "-") d = -d
        else if (this.open && this.dirType == "+") d = -d
        else if (!this.open && this.dirType == "-") d = -this.dim + d
        else d = this.dim + d
        this.moveTo(d)
    }
}

ypSlideOutMenu.prototype.endSlide = function()
{
    this.aniTimer = window.clearTimeout(this.aniTimer)
    this.moveTo(this.open ? this.outPos : this.homePos)
    if (!this.open) this.setVisibility(false)
    if ((this.open && !this.over) || (!this.open && this.over))
    {
        this.startSlide(this.over)
    }
}

ypSlideOutMenu.prototype.setVisibility = function(bShow)
{
    var s = this.ns4 ? this.container : this.container.style
    s.visibility = bShow ? "visible" : "hidden"
}

ypSlideOutMenu.prototype.moveTo = function(p)
{
    this.style[this.orientation == "h" ? "left" : "top"] = this.ns4 ? p : p + "px"
}

ypSlideOutMenu.prototype.getPos = function(c)
{
    return parseInt(this.style[c])
}

ypSlideOutMenu.prototype.onactivate = function() { }
ypSlideOutMenu.prototype.ondeactivate = function() { }

/****** POSITION DIVS *******/

/* (id, dir, left, top, width, height) */
var menus = [
    new ypSlideOutMenu("menu1", "down", 45, 27, 170, 200),
    new ypSlideOutMenu("menu2", "down", 88, 27, 170, 200),
    new ypSlideOutMenu("menu3", "down", 143, 27, 170, 200),
    new ypSlideOutMenu("menu4", "down", 188, 27, 170, 200),
    new ypSlideOutMenu("menu5", "down", 353, 27, 170, 200),
    new ypSlideOutMenu("menu6", "down", 416, 27, 170, 200),
    new ypSlideOutMenu("menu7", "down", 501, 27, 170, 200),
    new ypSlideOutMenu("menu8", "down", 551, 27, 170, 200),
    new ypSlideOutMenu("menu9", "down", 517, 27, 170, 200),
    new ypSlideOutMenu("menu10", "down", 590, 27, 170, 200)
]

for (var i = 0; i < menus.length; i++)
{
    menus[i].onactivate = new Function("document.getElementById('act" + i + "').className='active';");
    menus[i].ondeactivate = new Function("document.getElementById('act" + i + "').className='';");
}
