// JavaScript Document
$(document).ready(function () {
    var typeMousemove = false;
    var optionMousemove = false;
    //Drop List
    $('.selectSearchOption').css('display', 'none');
    $('.selectSearchType').click(function () {
        typeMousemove = true;
        $('.selectSearchOption').slideDown('fast', function () {
            $(this).css('display', 'block');
        });
    });

    $(".selectSearchType").mouseover(function () {
        typeMousemove = true;
    });
    $('.selectSearchOption').mouseleave(function () {
        var _this = $(this);
        var tid = setTimeout(function () {
            if (typeMousemove == false) {
                _this.slideUp('500', function () {
                    _this.css('display', 'none');
                });
            }
            optionMousemove = false;
            clearTimeout(tid);
        }, 10);
    });

    $(".selectSearchOption").mouseover(function () {
        optionMousemove = true;
    });

    $(".selectSearchOption").mouseleave(function () {
        optionMousemove = false;
    });

    $(".selectSearchOption li a").click(function () {
        $(".selectSearchType").html($(this).html());
        $(".selectSearchOption").fadeOut("normal");
        optionMousemove = false;
        if ($(this).html() == "Recommendation") {
            $("#searchType").val(0);
        } else if ($(this).html() == "Activities") {
            $("#searchType").val(1);
        } else {
            if ($(this).html() == "Brands") {
                $("#searchType").val(0);
            }

            $("#tagid").val($(this).attr("searchtype"));
        }

        $(this).parents("form").attr("action", $(this).attr("url"));
    });

    $(".selectSearchType").mouseleave(function () {
        typeMousemove = false;
        var id = setTimeout(function () {
            if (optionMousemove == false)
                $(".selectSearchOption").slideUp("500");
        }, 100);
    });

    $("#searchForm").submit(function () {
        if ($("#searchType").val() == "" && $("#tagid").val() == "")
            return false;

        if ($("#keyword").val() == "")
            return false;
    });

    //    $(".selectSearchType").mouseleave(function () {
    //        var id = setTimeout(function () {
    //            $(".selectSearchOption").slideUp("500");
    //            clearTimeout(id);
    //        }, 100);
    //    });
});
