﻿$(document).ready(function(){
    
    
    // Empties text imputs when a user click/focusses them.
    // Replaces prompt text when user blurs if the input value is blank
    // Inputs must have clearOnFocus class to participate.
    $("input.clearOnFocus").focus(function(){
        if($(this).val() == this.defaultValue)
            $(this).val("");
    });
    $("input.clearOnFocus").blur(function(){
        if($(this).val() == "")
            $(this).val(this.defaultValue);
    });
    
    // does image replacements on Main nav items
    $("#mainNav>ul>li>a").each(function(){
        var altText = $(this).html();
        // preload the rollover image
        $.preloadImages($(this).attr("rel").replace(".gif","_red.gif"));
        $(this).html('<img src="' + $(this).attr("rel") + '" alt="' + altText + '" />');
    });
    // these links were set to display:none as the page loaded, show them again now we've inserted images
    //$("#mainNav>ul>li>a").css("display","inline");
    //$("#mainNav>ul").css("top","0");
    // text version needed margin, images have space built in
    //$("#mainNav>ul>li").css("margin","0");
    // setup image rollovers
    $("#mainNav>ul>li>a>img").hover(
    function(){
        $(this).attr("src",$(this).attr("src").replace(".gif","_red.gif"));
    },
    function(){
        $(this).attr("src",$(this).attr("src").replace("_red.gif",".gif"));
    });
});

jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}

