﻿//////////////////////////////////////////////////
//                                              //
// Filename: topnav.js                          //
// Purpose: highlight navigation menu - swap    //
// between on and off preloaded image states    //
// Author: James Radford BSc                    //
// Creation date: 22/11/2007                    //
//                                              //
//////////////////////////////////////////////////


// image paths

var navpath = '/img/menu/on/';
var navpathOff = '/img/menu/off/';



// bind mouse on and off events for highlighting
    
window.addEvent('domready', function() {


    // preload navigation
     
    var topnavOn = new Array();
    var topnavOff = new Array();


    // page links

    var topnav = new Array('home','history','whiskies','visit','shop','news','links','gallery','other','mbdcorporate','mcclellands','glengarioch','auchentoshan');


    for (var i=0;i<topnav.length;i++) {
        topnavOn[topnav[i]] = new Image();topnavOn[topnav[i]].src = navpath + topnav[i]+'.gif';    
        topnavOff[topnav[i]] = new Image();topnavOff[topnav[i]].src = navpathOff + topnav[i]+'.gif';    
    } 


    // events for top navigation
    
    try {
        topnav.each(function(element, index, array) {
            $(element).addEvent('mouseover', function() {
                topNavOn(this.id);
            });      
            $(element).addEvent('mouseout', function() {
                topNavOff(this.id);
            });   
        }); 
    }
    catch(err) {
         //alert(err.description);  // returns object error
    }
        
//    try {
//        if($('subnav')) {
//     
//	        var fadeout = new Fx.Style($('subnav'), 'opacity', {duration: 400}).set(0);
//         
//	        $('other').addEvent('click', function() {
//		        $('subnav').setStyle('visibility', 'visible');
//		        fadeout.start(0,1);
//	        });
//         
//	        $('subnav').addEvent('mouseleave', function() { 	
//		        (function() {
//			        fadeout.start(0);
//		        }).delay(100);
//	        });
//         
//        }
//    }    
//    catch(err) {
//        // catch error
//    }
        
        
    // highlight link

    function topNavOn(index) {    
        $(index).src = topnavOn[index].src;
    }


    // turn highlight off

    function topNavOff(index) { 
        $(index).src = topnavOff[index].src;
    }
    
});     


function setVisible() {
	if($('subnav').style.display == 'block') {
	    $('subnav').style.display = 'none';
        $('fill').style.display = 'block';
    }
    else {
        $('fill').style.display = 'none';
        $('subnav').style.display = 'block';
    }
			
}