﻿
$(document).ready(function () {
    SetupSearchForm();

    SetupHomepage();
});

function SetupHomepage() {
    $('.bigHome .divPhotoBanner').cycle({ fx: 'fade', speed: 1000, timeout: 4000 });

    $('.bigHome #divVideos').cycle({ fx: 'fade', speed: 'fast', timeout: 0, next: '#videoNext', prev: '#videoPrev', before: LoadVideo });
}

function LoadVideo() {
    var videoId = this.getAttribute("videoId");
    var playerMarkup = "<iframe width='246' height='208' src='http://www.youtube.com/embed/EXTERNAL_ID' frameborder='0' allowfullscreen></iframe>";
    //var playerMarkup = "<iframe width='246' height='208' src='http://www.youtube.com/embed/EXTERNAL_ID' frameborder='0' allowfullscreen></iframe>";
    $('#homeVideo').html(playerMarkup.replace(/EXTERNAL_ID/g, videoId));
 }

function SetupSearchForm() {
    SetupWatermark($('#txtSearch'), "Search");

    //Setup enterkey detection in header search
    $('#txtSearch').keypress(function (e) {
        if (e.which == 13 || e.keyCode == 13) {
            Search();
            return false;
        }
    });
}


function Search() {
    var terms = document.getElementById("txtSearch").value;
    if (terms.length > 0 && terms != "Search") {
        window.open('search.aspx?q=' + terms, '_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);

    });
}
