window.onload = (function(){
if(window.location.href.indexOf('test')>-1)alert('test');
var menuTable = document.getElementsByTagName('table')[0].getElementsByTagName('tr')[2].getElementsByTagName('td')[0];

function addSlideOutMenu(title, href, backgroundColor, children){
    var header = document.createElement('a');
    header.href = href;
    header.style.display = 'block';
    header.style.backgroundColor = backgroundColor;        
    header.style.padding = '4px';
    header.style.color = '#FFFFCC';
    header.style.textAlign = 'left';
    header.style.fontWeight = 'bold';
    header.style.textDecoration = 'none';
    header.style.backgroundImage = 'url("/elements/arrow_w.gif")';
    header.style.backgroundRepeat = 'no-repeat';
    header.style.backgroundPosition = '95% center';
    header.style.width = '100%';
    header.innerHTML = title;
    menuTable.appendChild(header);
    
    var floater = document.createElement('div');
    floater.style.position = 'absolute';
    floater.style.display = 'none';
    
    window.setTimeout(function(){
        floater.style.top = findPosY(header);
    },2000);
    floater.style.left = '170px';
    floater.style.width = '190px';        
    
    header.onmouseover = function(){
        floater.style.display = 'block';
        header.style.backgroundColor = '#336ca4';
    }
    
    header.onmouseout = function(e){
        if (!e) var e = window.event;
    	var relTarg = e.relatedTarget || e.toElement;        	
    	if(relTarg.className != 'menuItem'){
    	    floater.style.display = 'none';
    	    header.style.backgroundColor = backgroundColor;
    	}        	
    }   
    
    floater.onmouseout = function(e){
        if (!e) var e = window.event;
    	var relTarg = e.relatedTarget || e.toElement;
    	if(relTarg.className != 'menuItem'){
    	    floater.style.display = 'none';
    	    header.style.backgroundColor = backgroundColor;
    	}
    }                
    
    for(var x in children){        
        var menuItem = document.createElement('a');
        menuItem.style.display = 'block';
        menuItem.style.color = '#FFF';
        menuItem.style.borderBottom = '1px solid #002233';
        menuItem.className = 'menuItem';
        menuItem.style.textDecoration = 'none';
        menuItem.style.backgroundColor = '#336ca4';
        menuItem.style.fontSize = '12px';
        
        menuItem.onmouseover = (function(m){
            return function(){     
                m.style.backgroundColor = '#002233';
            };
        })(menuItem)
        
        menuItem.onmouseout = (function(m){
            return function(){
                m.style.backgroundColor = '#336ca4';
            };
        })(menuItem)
        
        if(children[x].image){
            menuItem.style.backgroundImage = 'url(\'' + children[x].image + '\')',      
            menuItem.style.backgroundRepeat = 'no-repeat';
            menuItem.style.backgroundPosition = '100px 5px';
            menuItem.style.height = '40px';
            menuItem.style.lineHeight = '40px';
        }
        else{
            menuItem.style.height = '20px';
            menuItem.style.lineHeight = '20px';
        }
        menuItem.style.verticalAlign = 'middle';
        menuItem.style.padding = '0 0 0 10px';
        
        menuItem.innerHTML = children[x].title;
        menuItem.href = children[x].href;
        floater.appendChild(menuItem);
    }

    document.getElementsByTagName('body')[0].appendChild(floater);
}

function addMenuItem(details){
    var a = document.createElement('a');
    a.innerHTML = details.title;
    a.href = details.href;
    a.style.display = 'block';
    a.style.color = '#FFF';
    a.style.backgroundColor = details.backgroundColor? details.backgroundColor : '#002233';
    a.style.padding = '4px 4px 4px 4px';
    a.style.textAlign = 'left';        
    a.style.width = '100%';
    a.style.textDecoration = 'none';
    
    a.onmouseover = function(){
        a.style.backgroundColor = '#336ca4';
    };
    
    a.onmouseout = function(){
        a.style.backgroundColor = details.backgroundColor? details.backgroundColor : '#002233';
    };
    
    menuTable.appendChild(a);
}

function addHeader(title){
    var header = document.createElement('div');
    header.innerHTML = title;
    header.style.backgroundColor = '#334c58';
    header.style.color = '#FFF';
    header.style.padding = '4px';
    header.style.textAlign = 'left';
    menuTable.appendChild(header);
}

function findPosY(obj) {
    var curleft = curtop = 0;   
    if (obj.offsetParent) {
        do {
		    curleft += obj.offsetLeft;
		    curtop += obj.offsetTop;
	    } 
	    while (obj = obj.offsetParent);
    }
    return curtop;
}


addSlideOutMenu('Chronographs', 'http://www.onthedash.com/Guide/_Chronographs//', '#666666', [
    {title:'Autavia', image:'http://www.onthedash.com/Guide/menu_c_autavia.gif', href:'http://www.onthedash.com/Guide/_Chronographs/62.Autavia/'},
    {title:'Camaro', image:'http://www.onthedash.com/Guide/menu_c_camaro.gif', href:'http://www.onthedash.com/Guide/_Chronographs/68.Camaro/'},
    {title:'Carrera', image:'http://www.onthedash.com/Guide/menu_c_carrera.gif', href:'http://www.onthedash.com/Guide/_Chronographs/63.Carrera/'},
    {title:'Daytona', image:'http://www.onthedash.com/Guide/menu_c_daytona.gif', href:'http://www.onthedash.com/Guide/_Chronographs/77.Daytona/'},
    {title:'Lemania', image:'http://www.onthedash.com/Guide/menu_c_lemania.gif', href:'http://www.onthedash.com/Guide/_Chronographs/86.1000_Series/'},
    {title:'Monaco', image:'http://www.onthedash.com/Guide/menu_c_monaco.gif', href:'http://www.onthedash.com/Guide/_Chronographs/69.Monaco/'},
    {title:'Montreal', image:'http://www.onthedash.com/Guide/menu_c_montreal.gif', href:'http://www.onthedash.com/Guide/_Chronographs/72.Montreal/'},
    {title:'All the Chronographs', image:'', href:'Guide/_Chronographs/'}        
]);

addMenuItem({title:'Price Guide',href:'http://www.onthedash.com/priceguide.shtml'});       
addMenuItem({title:'Master Reference Table',href:'http://www.onthedash.com/Guide/Master_Reference.php4'});
addMenuItem({title:'Movements',href:'http://www.onthedash.com/movements.shtml'});  
addMenuItem({title:'Comparisons',href:'http://www.onthedash.com/comparisons.shtml'});
addMenuItem({title:'Racers Only',href:'http://www.onthedash.com/racers.shtml'});
addMenuItem({title:'Logos and Specials',href:'http://www.onthedash.com/logos.shtml'});
addMenuItem({title:'Poor-Man\'s Heuers',href:'http://www.onthedash.com/poormans.shtml'});       
addMenuItem({title:'Gallery of Fakes',href:'http://www.onthedash.com/fakes.shtml'}); 

addSlideOutMenu('Dash-Mounted Timers', 'http://www.onthedash.com/Guide/_DashMounted//', '#666666',[
    {title:'Autavia', image:'http://www.onthedash.com/Guide/menu_Autavia.gif',href:'http://www.onthedash.com/Guide/_DashMounted/Autavia/'},
    {title:'Master Time', image:'http://www.onthedash.com/Guide/menu_Master_Time.gif',href:'http://www.onthedash.com/Guide/_DashMounted/Master_Time/'},
    {title:'Monte Carlo', image:'http://www.onthedash.com/Guide/menu_Monte_Carlo.gif',href:'http://www.onthedash.com/Guide/_DashMounted/Monte_Carlo/'},
    {title:'Ralley Master', image:'http://www.onthedash.com/Guide/menu_Rallye_Master.gif', href:'http://www.onthedash.com/Guide/_DashMounted/Rallye_Master/'},
    {title:'Super Autavia', image:'http://www.onthedash.com/Guide/menu_Super_Autavia.gif', href:'http://www.onthedash.com/Guide/_DashMounted/Super_Autavia/'},
    {title:'All the Dash-Mounter Timers', image:'', href:'http://www.onthedash.com/Guide/_DashMounted/'}
]);

addMenuItem({title:'Brief History',href:'http://www.onthedash.com/history.shtml'});    
addMenuItem({title:'Values',href:'http://www.onthedash.com/values.shtml'});
addMenuItem({title:'Abercrombies/Allstates',href:'http://www.onthedash.com/brands.shtml'});  
addMenuItem({title:'Mounted OnTheDash',href:'http://www.onthedash.com/Guide/_Mounted/'});
addMenuItem({title:'Accessories',href:'http://www.onthedash.com/Guide/_DashMounted/v._Accessories/'});

addSlideOutMenu('Stopwatches', 'http://www.onthedash.com/Guide/_Stopwatches//', '#334c58',[
    {title:'Pocket Chronographs', image:'',href:'http://www.onthedash.com/Guide/_Stopwatches/a.Pocket_Chronographs/'},
    {title:'Split-Second Timers', image:'',href:'http://www.onthedash.com/Guide/_Stopwatches/b.Split-Second_Timers/'},
    {title:'Game-Master', image:'',href:'http://www.onthedash.com/Guide/_Stopwatches/c.Game-Master/'},
    {title:'Ring-Master', image:'', href:'http://www.onthedash.com/Guide/_Stopwatches/d.Ring-Master_Stopwatch/'},
    {title:'All the Stopwatches', image:'', href:'http://www.onthedash.com/Guide/_Stopwatches/'},
]);

addMenuItem({title:'Catalogs',href:'http://www.onthedash.com/Guide/_Catalogs/',backgroundColor:'#666666'});    
addMenuItem({title:'Auctions',href:'http://www.onthedash.com/Guide/_Auctions/'});        
addHeader('Other Resources');

addMenuItem({title:'About OnTheDash',href:'http://www.onthedash.com/about.shtml'});
addMenuItem({title:'Blog',href:'http://www.onthedash.com/thoughts/'});
addMenuItem({title:'Articles',href:'http://www.onthedash.com/articles.shtml'});    
addMenuItem({title:'Some FAQs',href:'http://www.onthedash.com/faq.shtml'});    
addMenuItem({title:'Links',href:'http://www.onthedash.com/links.shtml'});    
addMenuItem({title:'Useful Things',href:'http://www.onthedash.com/useful.shtml'});    
addMenuItem({title:'Navigating this Site',href:'http://www.onthedash.com/navigate.shtml'});    
addMenuItem({title:'Contacts / Suggestions',href:'http://www.onthedash.com/contact.shtml'});        
addMenuItem({title:'Thanks',href:'http://www.onthedash.com/thanks.shtml'});    
addMenuItem({title:'Legal',href:'http://www.onthedash.com/legal.shtml'});
})();
