﻿
$(document).ready(function () {
    //Wireup the search box enter key press
    $('#txtSearch').keypress(function (e) {
        if (e.keyCode == 13) {
            return Search();
        }
    });

    //Wireup search button click
    $('#btnSearch').click(function () { return Search(); });

    //Wireup the search box watermark
    SetupWatermark($('#txtSearch'), "Enter keyword or phrase");

    //Setup the rotator if this is this is the homepage and the rotator block was found
    var cyclePluginExists = $.fn.cycle;
    if (cyclePluginExists) {
        $('.divRotator').cycle({timeout:6000});
    }
});

function Search() {
    var val = $('#txtSearch').val();
    if (val.length > 0 && val != "Enter keyword or phrase") {
        window.open('search.aspx?q=' + val, '_self', '');
    }
    return false;
}


function SetupWatermark(jqueryElementObject, waterMarkText) {
    // Define what happens when the textbox comes under focus
    // Remove the watermark class and clear the box
    jqueryElementObject.focus(function () {

        $(this).filter(function () {

            // We only want this to apply if there's not 
            // something actually entered
            return $(this).val() == "" || $(this).val() == waterMarkText

        }).removeClass("watermarkOn").val("");

    });

    // Define what happens when the textbox loses focus
    // Add the watermark class and default text
    jqueryElementObject.blur(function () {

        $(this).filter(function () {

            // We only want this to apply if there's not
            // something actually entered
            return $(this).val() == ""

        }).addClass("watermarkOn").val(waterMarkText);

    });
}
