﻿var text = "Search";
var searchBox;

$(function() {
    $('IMG.hover')
        .bind('mouseover', function() {
            this.src = this.src.replace(/^(.+)(\.[a-z]+)$/, "$1_on$2");
        })
        .bind('mouseout', function() {
            this.src = this.src.replace(/^(.+)_on(\.[a-z]+)$/, "$1$2");
        })
        .each(function() {
            this.preloaded = new Image;
            this.preloaded.src = this.src.replace(/^(.+)(\.[a-z]+)$/, "$1_on$2");
        }
    );

    //find links that start with "www" and prepend "http://"
    $("a[href^='www.']").attr("href", "http://" + $(this).attr("href"));

    //find external links, and set target to "_blank"
    $("a[href^='http://']").attr("target", "_blank");

    //hide h1's when the nav primary is rolled over


    //setup search functionality
    var sBox = $("input.searchBox");
    if (sBox.size() > 0) {
        searchBox = sBox[0];
        searchBox.value = text;
        resetSearchForm();
    }

    $("input.searchBox").focus(function() {
        if (searchBox.value == text) {
            searchBox.value = "";
            searchBox.style.color = "#000000";
        }
        else if (searchBox.value == "") {
            resetSearchForm();
        }
    });

    $("input.searchBox").blur(blurSearchForm);
    $("input.searchBox").change(blurSearchForm);

    function blurSearchForm() {
        if (searchBox.value == "") {
            resetSearchForm();
        }
    }

    function resetSearchForm() {
        searchBox.value = text;
        searchBox.style.color = "#CCCCCC";
    }


    //code to display navigation link drop downs
    $("ul#navLinks li:has(ul)").hover(function() {
        var ul = $(this).children("ul");
        if (ul.is(":animated")) {
            ul.stop()
                   .css("height", "auto")
                   .slideDown("normal");
        }
        else {
            ul.css("display", "none");
            ul.slideDown("normal");
        }
        $(this)
                .bind('mouseover', function() {
                    var img = $(this).children().children("img.hover")[0];
                    if (img != undefined && img.src.indexOf("_on") == -1)
                        img.src = img.src.replace(/^(.+)(\.[a-z]+)$/, "$1_on$2");
                })
                .bind('mouseout', function() {
                    var img = $(this).children().children("img.hover")[0];
                    if (img != undefined) {
                        img.src = img.src.replace(/^(.+)_on(\.[a-z]+)$/, "$1$2");
                    }
                });
    },
            function() {
                var ul = $(this).children("ul");
                if (ul.is(":animated")) {
                    ul.stop()
                        .css("height", "auto")
                        .slideUp("fast");
                }
                else {
                    ul.slideUp("fast");
                }
            });
});