$(document).ready(function () {

    // FORM FIELD CLEAR/REPLACE
    $('.replace').blur(function (e) {
        var origTarget = e.originalEvent.explicitOriginalTarget;
        if ($(origTarget).is(".sfsearchSubmit")) { return false; }
        if (this.value == '') {
            this.value = $(this).attr('defaultValue');
        }
    });

    $('.replace').focus(function () {
        if (this.value == $(this).attr('defaultValue')) {
            this.value = '';
        }
    });


    // MODALS
    $(".trigger[rel]").overlay({
        effect: 'apple',
        closeOnClick: false
    });


    // DATAGRID
    // Alternating row colors
    $('table.datagrid tbody tr:even').addClass('alt');
    // First/Last-Child switch
    $('table.datagrid tr td:first-child,table.datagrid tr th:first-child').addClass('first');
    $('table.datagrid tr td:last-child,table.datagrid tr th:last-child').addClass('last');
    $('table.datagrid thead tr:last-child,').addClass('last');


    // CUSTOM SCROLLBAR
    // get handle to the scrollable DIV
    var scroll = $("#scroll");

    // initialize rangeinput

    $("input[type=range]").rangeinput({

        // slide the DIV along with the range using $'s css() method
        onSlide: function (ev, step) {
            scroll.css({ left: -step });
        },

        // display progressbar
        progress: true,

        // initial value. also sets the DIV's initial scroll position
        value: 0,

        // this is called when the slider is clicked. we animate the DIV
        change: function (e, i) {
            scroll.animate({ left: -i }, "fast");
        },

        // disable drag handle animation when when slider is clicked
        speed: 0

    });

    $("*[id*=BlogSearch]:input[type='text']").attr('defaultValue', "Search the Vasque Blog");

    /*if ($("ul.#mod_cta").length === 0) {
        $("#mod_cta").css('display', 'none');
    }*/

    if ($("#products_site_section").length > 0) {
        $("#product_nav").children().first().addClass("active");
    }
    if ($("#technology_page").length > 0) {
        $("#tech_nav").children().first().addClass("active");
    }
    if ($("#events_page").length > 0) {
        $("#event_nav").children().first().addClass("active");
    }
    if ($("#athletes_page").length > 0) {
        $("#athletes_nav").children().first().addClass("active");
    }

    $("#txt_hd_findretailer").click(function () {
        if (!$(this).val() || $(this).val() == $(this).attr("defaultValue")) {
            return false;
        }
    });
    $("#btmRetail_Search").click(function () {
        if (!$(this).val() || $(this).val() == $(this).attr("defaultValue")) {
            return false;
        }
    });
});

