/**
 * Created by .
 * User: mikehamilton
 * Date: 4/1/11
 * Time: 2:34 PM
 * Note: This script has the following dependencies:
 *        - jquery
 *        - supersubs
 *        - superfish
 */

var SEARCH_BOX_DEFAULT       = "Search...";
var NEWSLETTER_EMAIL_DEFAULT = "E-Mail Address";

function Search() {
    var searchTerm = $('#txtSearch').val();

    if ((searchTerm != '') || (searchTerm != SEARCH_BOX_DEFAULT)) {
        window.location.href = "/Search.aspx?s=" + searchTerm;
    }
};

$(document).ready(function() {
    $.Enter('#txtSearch',Search);
    // Main Navigation Setup
    $('#mainNavigation').supersubs({
        minWidth: 12,   // minimum width of sub-menus in em units
        maxWidth: 27,   // maximum width of sub-menus in em units
        extraWidth: 1
    }).superfish({
        dropShadows: false
    });

    $('#loginNavigation').supersubs({
        minWidth: 12,   // minimum width of sub-menus in em units
        maxWidth: 27,   // maximum width of sub-menus in em units
        extraWidth: 1
    }).superfish({
        dropShadows: false
    });
    // SearchBox Setup
    $('#txtSearch').val(SEARCH_BOX_DEFAULT);

    $('#txtSearch').focus(function() {
        if ($(this).val() == SEARCH_BOX_DEFAULT) {
            $(this).val('');
        }
    });
    $('#txtSearch').blur(function() {
        if ($(this).val() == '') {
            $(this).val(SEARCH_BOX_DEFAULT);
        }
    });

    $('#btnSearch').click(Search);

    // Newsletter Form Field Defaults
    $('#txtNewsletterEmail').val(NEWSLETTER_EMAIL_DEFAULT);

    $('#txtNewsletterEmail').focus(function() {
        if ($(this).val() == NEWSLETTER_EMAIL_DEFAULT) {
            $(this).val('');
        }
    });
    $('#txtNewsletterEmail').blur(function() {
        if ($(this).val() == '') {
            $(this).val(NEWSLETTER_EMAIL_DEFAULT);
        }
    });

    /*
    // Left Nav Accordian Menu Setup
    $("#leftNavigation > li > a").click(function () {
    if (!$(this).next().is(':visible')) {
    $('#leftNavigation ul').slideUp(300);
    }

		$(this).next().slideToggle(300);
    });
    */
    // Expand the current page's menu
    //$('#leftNavigation ul').hide();
    //$('#leftNavigation ul li.selected').parent().show();
});

jQuery.Enter = function(element, callback) {
    jQuery(element).bind('keypress', function(event) {
        var code = event.charCode || event.keyCode;
        if (code && code == 13) {// if enter is pressed
            callback();
            event.preventDefault(); //prevent browser from following the actual href
        };
    });
};


