jQuery(function($) {
    var tipTimer = null;
    var toggleTipShow = function() {
        clearTimeout(tipTimer);
        $("#tip").fadeIn();
    };
    var toggleTipHide = function() {
        clearTimeout(tipTimer);
        tipTimer = setTimeout(function() {
            $("#tip").fadeOut();
        }, 500);
    };
    $(".unSelected").hover(toggleTipShow, toggleTipHide);
    $("#allControl").click(function() {
        $(this).toggleClass("closeAll").toggleClass("openAll");
        $("#withInput").toggleClass("hide");
        if ($("#withInput").is(":hidden")) {
            $.cookie("hd_rfn", 1, {
                expires: 999,
                path: "/"
            });
            $("#tip").text("Show Refine Search Options");
        }
        else {
            $.cookie("hd_rfn", null, {
                expires: 999,
                path: "/"
            });
            $("#tip").text("Hide Refine Search Options");
        }
    });
    if ($.cookie("hd_rfn")) {
        $("#allControl").click();
    }
    $("#cat").hover(function() {
        $(".selected .prop").addClass("catalogOn");
    }, function() {
        $(".selected .prop").removeClass("catalogOn");
    });
    $("span[id^=\"prop_\"] ").click(function() {
        $(this).toggleClass("openmore").toggleClass("closeless");
        if ($(this).is(".closeless")) {
            $(this).text("Less").parent().children("a,div").show();
        }
        else {
            $(this).text("More").parent().children("a:gt(3),div").hide();
        }
    });
    $("#viewMoreOrLess").click(function() {
        $(".otherPropertyBox").toggleClass("hide");
        $(this).toggleClass("viewMore").toggleClass("viewLess");
        if ($(this).is(".viewLess")) {
            $(this).text("View Less");
        }
        else {
            $(this).text("View More");
        }
    });
    //
    $(".inputBox").each(function() {
        $(this).after($(this).children("div.inputBoxCon").removeClass("show"));
    }).hover(function() {
        $(this).addClass("onInputBox");
    }, function() {
        $(this).removeClass("onInputBox");
    });
    //
    $(document).click(function(e) {
        e = e || window.event;
        el = e.target || e.srcElement;
        if ($(el).is(".inputBox")) {
            $("div.inputBoxCon.show").removeClass("show");
            var ibPos = $(el).position();
            $(el).next("div.inputBoxCon").css({
                "left": ibPos.left + "px",
                "top": (ibPos.top + $(el).height()) + "px"
            }).addClass("show").toggle();
            $("div.inputBoxCon").not(".show").hide();
        }
        else {
            $("div.inputBoxCon").removeClass("show").hide();
        }
    });
    if (!+"\v1") {
        $(".inputBoxCon").each(function() {
            if ($(this).children("a").length <= 8) {
                $(this).height("auto");
            }
        });
    }
});


