﻿// cruisemenu.js

// Note: this script relies on the presence of the prototype.js file in order to use
// the $ shorthand for document.getElementById().

// Iterates through elements of a given tagtype and matches on title.  
function getElementByTitle (title, tagtype) {
    var all = document.all ? document.all : document.getElementsByTagName(tagtype);
    var elements = new Array();
    for (var i = 0; i < all.length; i++)
        if (all[i].title == title)
            elements[elements.length] = all[i];
    return elements[0];
}

function ShowCruiseMenu() {
    var cruisemenu = $('travel-cruises-mega-menu');
    // Display menu by positioning it onscreen.  
    cruisemenu.writeAttribute({'style': 'left:318px'});
}

function HideCruiseMenu() {
    var cruisemenu = $('travel-cruises-mega-menu');
    // Hide menu by positioning it off screen.  
    cruisemenu.writeAttribute({'style': 'left:-9999px'});
}

// The Cruise link is generated by Reddot and can only be identified in the DOM by its Title attribute.  
var cruises = getElementByTitle('Cruises', 'a');

var cruisemenu = $('travel-cruises-mega-menu');
var browser=navigator.appName; // Find out what browser is being used.  

// If the browser is IE, attach onmouseover/out events using attachEvent() (IE proprietory code).  
if (browser=="Microsoft Internet Explorer"){
     cruises.attachEvent('onmouseover',ShowCruiseMenu);
     cruises.attachEvent('onmouseout',HideCruiseMenu);
     cruisemenu.attachEvent('onmouseover',ShowCruiseMenu);
     cruisemenu.attachEvent('onmouseout',HideCruiseMenu);
}
else{ // For all other browsers use addEventListener() (W3C standard, but not implemented by IE). 
    cruises.addEventListener('mouseover',ShowCruiseMenu, false);
    cruises.addEventListener('mouseout',HideCruiseMenu, false);
    cruisemenu.addEventListener('mouseover',ShowCruiseMenu, false);
    cruisemenu.addEventListener('mouseout',HideCruiseMenu, false);
}

cruises.target = '_self';
