﻿$(document).ready(function() {

    jQuery(function($) {
        $('select.dbfForm').selectify();
    });
    $('.dbfEventKeyword').watermark('Enter Keyword');

    $(".dbfRefineClear").click(function() {
        $(this).closest(".dbfRefineSearch").find(".dbfForm").val('');
        $(this).closest(".dbfRefineSearch").find('input[type="checkbox"]').removeAttr('checked');
    });
    
    if (($(".dbfRefineSelections table input:checked").length) || ($(".cms16_events").length)) {
        $(".dbfRefineHide").html('Hide Options');
    } else {
        $(".dbfRefineHide").html('Show Options');
        $(".dbfRefineSelections table").hide();
    }
    $(".dbfRefineHide").click(function() {
        $(this).closest(".dbfRefineSearch").find(".dbfRefineSelections table").slideToggle();
        if ($(this).html() == 'Hide Options') {
            $(this).html('Show Options');
            //            $(this).closest(".dbfRefineSearch").find(".dbfRefineSelections").animate({
            //                height:100
            //            });
        } else {
            $(this).html('Hide Options');
            //            $(this).closest(".dbfRefineSearch").find(".dbfRefineSelections").animate({
            //                height: 'auto'
            //            });
        }
    });



    $(".dbfCategorySlider .carousel ul li").each(function() {
        $(this).find('h2').html('#' + ($(this).index() + 1) + " - " + $(this).find('h2').html());
    });


    $(".dbfCategorySlider .carousel").jCarouselLite({
        btnNext: ".dbfCategorySliderArrow.next",
        btnPrev: ".dbfCategorySliderArrow.prev",
        auto: 10000,
        speed: 500,
        visible: 1
    });

    $(".dbfCategorySlider").prepend("<h3>Event Types 101</h3>");

    var t1;


    var prevNum = 0;
    var sNum = 1;
    $("#dbf-hero .dbf-hero-image li:eq(0)").show();
    $("#dbf-hero .dbf-hero-callout li:eq(0)").show();
    $("#dbf-hero .dbf-hero-nav li:eq(0)").addClass('active');

    //var timerId = setInterval(heroSlideshow, 5000);
    var timeOutId;
    var fading = 0;

    function showSlide(showi) {

    }
    function heroSlideshow() {
        //var prevNum = sNum - 1;
        //if (prevNum < 0) prevNum = $("#dbf-hero .dbf-hero-image li").size() - 1;

        fading = 1;
        $("#dbf-hero .dbf-hero-nav li").removeClass('active');
        $("#dbf-hero .dbf-hero-image li:eq(" + prevNum + ")").fadeOut(2000);
        $("#dbf-hero .dbf-hero-image li:eq(" + prevNum + ")").fadeOut(2000);
        $("#dbf-hero .dbf-hero-callout li:eq(" + prevNum + ")").fadeOut(1000, function() {
            // alert(sNum);
            $("#dbf-hero .dbf-hero-nav li:eq(" + sNum + ")").addClass('active');
            $("#dbf-hero .dbf-hero-callout li:eq(" + sNum + ")").fadeIn(1000);
        });

        $("#dbf-hero .dbf-hero-image li:eq(" + sNum + ")").fadeIn(2000, function() {
            //var nextNum = (sNum + 1) % 3;
            //alert(nextNum);


            prevNum = sNum;
            sNum = (sNum + 1) % 2;
            timeOutId = setTimeout(heroSlideshow, 10000);
            fading = 0;
        });


    }

    function gotoSlide() {

    }

    $("#dbf-hero .dbf-hero-nav li a").click(function() {
        var gotoindex = $(this).parent().index();
        var timeOutId2 = setTimeout(function() {
            clearTimeout(timeOutId);

            //alert(gotoindex);
            $("#dbf-hero .dbf-hero-callout li").hide();
            $("#dbf-hero .dbf-hero-callout li:eq(" + gotoindex + ")").show();
            $("#dbf-hero .dbf-hero-image li").hide();
            $("#dbf-hero .dbf-hero-image li:eq(" + gotoindex + ")").show();
            //prevNum = sNum;
            prevNum = gotoindex;
            sNum = (prevNum + 1) % 3;
            $("#dbf-hero .dbf-hero-nav li").removeClass('active');
            $("#dbf-hero .dbf-hero-nav li:eq(" + gotoindex + ")").addClass('active');
            timeOutId = setTimeout(heroSlideshow, 10000);
        }, fading * 2000);




    });

    timeOutId = setTimeout(heroSlideshow, 10000);

});
