﻿var PopupWindow = Class({
    
    setOptions: function(options)
    {
        this.options = {
            width: 800,
            height: 580,
            top: 25,
            left: 25,
            scrollbars: 'yes',
            resizable: 'yes',
            status: 'yes',
            toolbar: 'yes',
            location: 'yes',
            menubar: 'yes'
        }
        $extend(this.options, options)
    },
    
    initialize: function(aLink, aName, options)
    {
        this.theLink = $(aLink);
        this.theHref = this.theLink.getProperty('href');
        this.theName = aName || '_blank';
        this.setOptions(options);
        
        this.theLink.onclick = function(e){ return this.OpenWin(e) }.bind(this);
    },
    
    OpenWin: function(e)
    {
        var event = (!e) ? window.event : e;
        if (event.shiftKey || event.altKey || event.ctrlKey || event.metaKey) return true;
        
        var theOptions = '';
        for(theOption in this.options)
        {
            theOptions += ","+theOption+"="+this.options[theOption];
        }
        theOptions = theOptions.substring(1,theOptions.length);
        
        var theWin = window.open(this.theHref, this.theName, theOptions);
        if(theWin) theWin.focus();
        return false;
    }
    
})
InitTools = function()
{
    // Set popups
    $$('a.popup').each(function(anEl){
        var theRel = anEl.getProperty('rel')
        var theOptions = {};
        var theName = "_blank";
        if(theRel)
        {
            var theSplitRel = theRel.split(";");
            for(var i=0; (theEntry=theSplitRel[i]); i++)
            {
                var thePair = theEntry.split(":");
                if("name"==thePair[0])
                {
                    theName = thePair[1];
                    continue;
                }
                theOptions[thePair[0]] = thePair[1];
            }
        }
        new PopupWindow(anEl, '_blank',theOptions);
    });
    
    // Weird trick to remove flicker in Mac/Firefox2 when dealing w/ opacities and disappear/reappear content
    if (Browser.Platform.mac && Browser.Engine.gecko)
    {
        //$$('body').setStyle('opacity', 0.9999);
    }
}
window.addEvent('domready',InitTools);

var menuHover = function() {
    // Only select top level li should have rollover rules
    var sfEls = $$('#nav > ul > li').each(function(el)
    {
        var kids = el.getChildren();
        
        //Main rollovers to light up parent and keep lit while over children
        el.addEvents({
            'mouseover': function(){ this.addClass('sfhover hover'); },
            'mouseout' : function(){ this.removeClass('sfhover hover'); }
        });
        
        //Elements that have children lists
        if(kids[1] != undefined)
        {
            //If there are kids, make parent non-operational
            //(This station is non-operational)
            kids[0].addEvent('click', function(e){ new Event(e).stop(); });
        }
    });
}
window.addEvent('domready',menuHover);
