/* common classes/functions */

/* jquery style nav setup - set all A.navMO under #nav2 to add class 'navHighlight' onmouseover */
var syxmover = {

    plcache: new Array(),

    init: function() {
        var navBoxen = $('#nav2/div/a');
        var nonSel = navBoxen.filter( function(e) { return ! this.className.match(/\bnavSel\b/); } );

        nonSel.mouseover( function(e){ $(this).addClass('navHighlight'); });
        nonSel.mouseout( function(e){ $(this).removeClass('navHighlight'); });

        nonSel.each( function() { syxmover.preload($(this).parent()); } );

        //navBoxen.filter('.navSel').click( function(e){ return false; });

        var subnav = $('#subnav2');
        if (subnav) {
            var subnavBoxen = $('#subnav2/ul/li/a');
            var subnonSel = subnavBoxen.filter( function(e) { return ! this.className.match(/\bnavSel\b/); } );

            subnonSel.mouseover( function(e){ $(this).addClass('navHighlight'); });
            subnonSel.mouseout( function(e){ $(this).removeClass('navHighlight'); });

            subnonSel.each( function() { syxmover.preload(this); } );

            //subnavBoxen.filter('.navSel').click( function(e){ return false; });
        }

    },

    /* hack to create URLs out of background-image prop of each elem, and then
     * preloading them by creating a permanent Image() out of them, as well as
     * the mouseover version given by XXXXXXXX_on.gif */
    preload: function (elem) {
        var def = $(elem).css('background-image').replace(/url\(['"]?([^)"']+)['"]?\)/, '$1');
        if (def != 'none') {
            var onsrc = def.replace(/\.([^.]+)$/, '_on.$1');
            this.imgFactory(def);
            this.imgFactory(onsrc);
        }
    },

    imgFactory: function(src) {
        var i = new Image();
        i.src = src;
        this.plcache[this.plcache.length] = i;
    }

};



$(document).ready(function(){
    syxmover.init();

    /* open all external links in new window (class 'ext') */
    $('a.ext').attr('target', '_new');

});
