var timeout	= 800;
var closetimer	= 0;
var ddmenuitem	= 0;


var url_array = document.URL.split("/");

var aboutUrl = (url_array[url_array.length - 1]  == "about.htm");
var aboutRestaurantUrl = (url_array[url_array.length - 1]  == "abouttherestaurant.htm");
var aboutMansionUrl = (url_array[url_array.length - 1]  == "aboutthemansion.htm");
var aboutFrederickUrl = (url_array[url_array.length - 1]  == "aboutdowntownfrederick.htm");
var aboutBiographiesUrl = (url_array[url_array.length - 1]  == "aboutbiographies.htm");
var aboutBiographiesbryanUrl = (url_array[url_array.length - 1]  == "aboutbiographiesbryan.htm");
var aboutBiographieshildaUrl = (url_array[url_array.length - 1]  == "aboutbiographieshilda.htm");
var aboutBiographiesaaronUrl = (url_array[url_array.length - 1]  == "aboutbiographiesaaron.htm");
var aboutBiographiesgraemeUrl = (url_array[url_array.length - 1]  == "aboutbiographiesgraeme.htm");
var aboutBiographiesneilUrl = (url_array[url_array.length - 1]  == "aboutbiographiesneil.htm");
var aboutBiographiesteamUrl = (url_array[url_array.length - 1]  == "aboutbiographiesteam.htm");
var aboutBiographiescollaboratorsUrl = (url_array[url_array.length - 1]  == "aboutbiographiescollaborators.htm");
var aboutNewsUrl = (url_array[url_array.length - 1]  == "aboutnews.htm");
var aboutBlog = (url_array[url_array.length - 1]  == "aboutblog.htm");


var menusUrl = (url_array[url_array.length - 1]  == "menus.htm");
var menuslunchUrl = (url_array[url_array.length - 1]  == "menuslunch.htm");
var menusbrunchUrl = (url_array[url_array.length - 1]  == "menusbrunch.htm");
var menusdinnerUrl = (url_array[url_array.length - 1]  == "menusdinner.htm");
var menusloungeUrl = (url_array[url_array.length - 1]  == "menuslounge.htm");
var menuslunchmessUrl = (url_array[url_array.length - 1]  == "menuslunch_message.htm");
var menusdinnermessUrl = (url_array[url_array.length - 1]  == "menusdinner_message.htm");






var galleryUrl = (url_array[url_array.length - 1]  == "gallery.htm");
var galleryCuisineUrl = (url_array[url_array.length - 1]  == "gallerycuisine.htm");
var galleryInteriorUrl = (url_array[url_array.length - 1]  == "galleryinterior.htm");



var reservationsUrl = (url_array[url_array.length - 1]  == "reservations.htm");
var reservationsAtaglanceUrl = (url_array[url_array.length - 1]  == "reservationsataglance.htm");
var reservationMapsdirectionsUrl = (url_array[url_array.length - 1]  == "reservationmapsdirections.htm");
var reservationsGiftcertificatesUrl = (url_array[url_array.length - 1]  == "reservationsgiftcertificates.htm");
var reservationReservationsUrl = (url_array[url_array.length - 1]  == "reservationreservations.htm");



var inquiriesUrl = (url_array[url_array.length - 1]  == "inquiries.htm");
var inquiriesEmploymentUrl = (url_array[url_array.length - 1]  == "inquiriesemployment.htm");
var inquiriesPressUrl = (url_array[url_array.length - 1]  == "inquiriespress.htm");
var inquiriesPrivateeventsUrl = (url_array[url_array.length - 1]  == "inquiriesprivateevents.htm");
var inquiriesPressreleasesUrl = (url_array[url_array.length - 1]  == "inquiriespressreleases.htm");





/**
 * Attaching functions to handle events
 * @param element Object to which event is attached
 * @param string Event name
 * @param pointer Event handling function
 */
function attachEvent(element, eventName, eventHandler) {
	if (element.attachEvent) {
		element.attachEvent("on" + eventName, eventHandler);
	}
	if(element.addEventListener) {
		element.addEventListener(eventName, eventHandler, false);
	}
	// ie hack
	if (eventName == 'load') {
		element.onload = eventHandler;
	}
}

/**
 *  When document is loaded:
 *   - hide all dropdown menus
 *   - attach event handlers
 */
function documentOnLoad() {
	hideMenus();
	hideShowedMenu();
	// about menu event handlers
	e = document.getElementById('about');
	
	if (e) { 
		attachEvent(e, 'mouseover', displayAboutMenu);
		attachEvent(e, 'mouseout', closeTime);
	}
	
	e = document.getElementById('aboutmenuImage');
	if (e) { 
		attachEvent(e, 'mouseover', cancelCloseTime);
		attachEvent(e, 'mouseout', closeTime);
	}
	
	
	// menus menu event handlers
	e = document.getElementById('menus');
	
	if (e) { 
		attachEvent(e, 'mouseover', displayMenusMenu); 
		attachEvent(e, 'mouseout', closeTime);
	}
	
	e = document.getElementById('menusmenuImage');
	if (e) { 
		attachEvent(e, 'mouseover', cancelCloseTime); 
		attachEvent(e, 'mouseout', closeTime);
	}
	
	
	// gallery menu event handlers
	e = document.getElementById('gallery');
	
	if (e) { 
		attachEvent(e, 'mouseover', displayGalleryMenu); 
		attachEvent(e, 'mouseout', closeTime);
	}
	
	e = document.getElementById('gallerymenuImage');
	if (e) { 
		attachEvent(e, 'mouseover', cancelCloseTime); 
		attachEvent(e, 'mouseout', closeTime);
	}
	
	// reservations menu event handlers
	e = document.getElementById('reservations');
	
	if (e) { 
		attachEvent(e, 'mouseover', displayReservationsMenu); 
		attachEvent(e, 'mouseout', closeTime);
	}
	
	e = document.getElementById('reservationsmenuImage');
	if (e) { 
		attachEvent(e, 'mouseover', cancelCloseTime); 
		attachEvent(e, 'mouseout', closeTime);
	}
	
	// inquiries menu event handlers
	e = document.getElementById('inquiries');
	
	if (e) { 
		attachEvent(e, 'mouseover', displaInquiriesMenu); 
		attachEvent(e, 'mouseout', closeTime);
	}
	
	e = document.getElementById('inquiriesmenuImage');
	if (e) { 
		attachEvent(e, 'mouseover', cancelCloseTime); 
		attachEvent(e, 'mouseout', closeTime);
	}
	
	// other dropdown menu event handlers go here
	
}

/**
* Hides all dropdown menus
*/
function hideMenus() {

	if(!aboutUrl && !aboutRestaurantUrl && !aboutMansionUrl && !aboutFrederickUrl && !aboutBiographiesUrl && !aboutBiographiesteamUrl && !aboutBiographiescollaboratorsUrl && !aboutBiographiesbryanUrl && !aboutBiographieshildaUrl && !aboutBiographiesaaronUrl && !aboutBiographiesgraemeUrl && aboutBiographiesneilUrl && !aboutNewsUrl) {
		document.getElementById('aboutmenuImage').style.visibility = "hidden"; 
	}
	if(!menusUrl && menuslunchUrl && menusbrunchUrl  &&  menusdinnerUrl && menusloungeUrl && menuslunchmessUrl && menusdinnermessUrl) document.getElementById('menusmenuImage').style.visibility = "hidden";
	
	if(!galleryUrl && !galleryCuisineUrl && !galleryInteriorUrl) {
		document.getElementById('gallerymenuImage').style.visibility = "hidden";
	}
	if(!reservationsUrl && !reservationsAtaglanceUrl && !reservationMapsdirectionsUrl && !reservationsGiftcertificatesUrl && !reservationReservationsUrl) {
		document.getElementById('reservationsmenuImage').style.visibility = "hidden";
	}
	if(!inquiriesUrl && !inquiriesEmploymentUrl && !inquiriesPressUrl && !inquiriesPrivateeventsUrl && inquiriesPressreleasesUrl) document.getElementById('inquiriesmenuImage').style.visibility = "hidden";	
}


/**
* Displays About menu
*/
function displayAboutMenu() {	
	cancelCloseTime();

	// close old layer
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
	// get new layer and show it
	ddmenuitem = document.getElementById('aboutmenuImage');
	ddmenuitem.style.visibility = 'visible';
}

// Menus menu
function displayMenusMenu() {	
	cancelCloseTime();

	// close old layer
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
	// get new layer and show it
	ddmenuitem = document.getElementById('menusmenuImage');
	ddmenuitem.style.visibility = 'visible';

}

//Galleries menu

function displayGalleryMenu() {	
	cancelCloseTime();

	// close old layer
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
	// get new layer and show it
	ddmenuitem = document.getElementById('gallerymenuImage');
	ddmenuitem.style.visibility = 'visible';

}


//Reservations menu

function displayReservationsMenu() {	
	cancelCloseTime();

	// close old layer
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
	// get new layer and show it
	ddmenuitem = document.getElementById('reservationsmenuImage');
	ddmenuitem.style.visibility = 'visible';

}


//Inquiries menu

function displaInquiriesMenu() {	
	cancelCloseTime();

	// close old layer
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
	// get new layer and show it
	ddmenuitem = document.getElementById('inquiriesmenuImage');
	ddmenuitem.style.visibility = 'visible';

}


/**
* Hides showed menu
*/

//all about pages
function hideShowedMenu() {
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
	
	if(aboutUrl || aboutRestaurantUrl || aboutMansionUrl || aboutFrederickUrl || aboutBiographiesUrl || aboutBiographiesteamUrl || aboutBiographiesbryanUrl || aboutBiographieshildaUrl || aboutBiographiesaaronUrl || aboutBiographiescollaboratorsUrl || aboutBiographiesgraemeUrl || aboutBiographiesneilUrl || aboutNewsUrl) {
		ddmenuitem = document.getElementById('aboutmenuImage');
		ddmenuitem.style.visibility = 'visible';
	}
	
	//all menu pages
	if(menusUrl || menuslunchUrl || menusbrunchUrl || menusdinnerUrl || menusloungeUrl || menuslunchmessUrl || menusdinnermessUrl) {
		ddmenuitem = document.getElementById('menusmenuImage');
		ddmenuitem.style.visibility = 'visible';
	}
	
	//all gallery pages
	
	if(galleryUrl || galleryCuisineUrl || galleryInteriorUrl) {
		ddmenuitem = document.getElementById('gallerymenuImage');
		ddmenuitem.style.visibility = 'visible';
	}
	
	//all reservations pages
	
	if(reservationsUrl || reservationsAtaglanceUrl || reservationMapsdirectionsUrl || reservationsGiftcertificatesUrl || reservationReservationsUrl) {
		ddmenuitem = document.getElementById('reservationsmenuImage');
		ddmenuitem.style.visibility = 'visible';
	}
	
	//all inquiries pages
	if(inquiriesUrl || inquiriesEmploymentUrl || inquiriesPressUrl || inquiriesPrivateeventsUrl || inquiriesPressreleasesUrl) {
		ddmenuitem = document.getElementById('inquiriesmenuImage');
		ddmenuitem.style.visibility = 'visible';
	}
	
	
}

/** 
* Close timer
*/
function closeTime() {
	closetimer = window.setTimeout(hideShowedMenu, timeout);
	
}

/**
* cancel close timer
*/
function cancelCloseTime() {
	if(closetimer) {
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

// attach events when the document is loaded
attachEvent(window, 'load', documentOnLoad);
attachEvent(window, 'click', hideShowedMenu);


// Google Analytics

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-9590015-1']);
_gaq.push(['_setDomainName', '.voltrestaurant.com']);
_gaq.push(['_trackPageview']);

(function() {
    var ga = document.createElement('script');
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 
        'http://www') + '.google-analytics.com/ga.js';
    ga.setAttribute('async', 'true');
    document.documentElement.firstChild.appendChild(ga);
})();
