﻿// commented lines are for when full urls are used for the image source

// preload '_on' images with class of 'hover'
$(window).bind('load', function() {
    var preload = new Array();
    $(".hover, .sf-menu img").each(function() {
        s = $(this).attr("src").replace(/\.(.+)$/i, "_over.$1");
		//s = $(this).attr("src").replace(/.gif$/ig,"_over.gif");
        preload.push(s)
    });
	preload.push("images/interface/logo-whitebg.png");
    var img = document.createElement('img');
    $(img).bind('load', function() {
        if(preload[0]) {
            this.src = preload.shift();
        }
    }).trigger('load');
});

$(document).ready(function() {
	// apply mouseovers
    $(".hover").each(function() {
        if ($(this).attr("src").match(/_on\.(.+)$/i)) {
		//if ($(this).attr("src").match(/_over.gif$/ig)) {
            $(this).removeClass("hover");
        }
    });
    $(".hover").hover(function() {
        s = $(this).attr("src").replace(/\.(.+)$/i, "_over.$1");
		//s = $(this).attr("src").replace(/.gif$/ig,"_over.gif");
        $(this).attr("src", s);
    }, function() {
        s = $(this).attr("src").replace(/_over\.(.+)$/i, ".$1");
		//s = $(this).attr("src").replace(/_over.gif$/ig,".gif");
        $(this).attr("src", s);
    });
	
	$(".hovertable tbody tr").hover(function() {
		$(this).addClass("trhover");
	}, function() {
		$(this).removeClass("trhover");
	});
	
	// initialize the menu
    $("ul.sf-menu").superfish();
	// keep top-level nav menu image in hover state as long as its submenus are hovered
    $("ul.sf-menu > li").hover(function() {
        var s = $(this).children().children("img").attr("src").replace(/\.(.+)$/i, "_over.$1");
		//var s = $(this).children().children("img").attr("src").replace(/.png$/ig,"_over.png");
        $(this).children().children("img").attr("src", s);
    }, function() {
        var s = $(this).children().children("img").attr("src").replace(/_over\.(.+)$/i, ".$1");
		//var s = $(this).children().children("img").attr("src").replace(/_over.png$/ig,".png");
        $(this).children().children("img").attr("src", s);
    });
	// prink link only works with javascript enabled, so make it display
	$("#printlink").css('display','block');
});