﻿
$().ready(function() {
    var secenekler = $(".secenekler");
    var searchForm = $("#footer .footerRight .searchForm");
    $("#txtAra").focus(function() {
        $("#txtAra").val('');
        searchForm.css("border-top", "1px solid #3260AB");
        secenekler.addClass('opened');
        secenekler.animate({
            marginTop: "-102px",
            height: "100px"
        }, 200)
    });

    function closeSecenekler() {
        secenekler.animate({
            marginTop: "-20px",
            height: "10px"
        }, 200, null, function() {
        searchForm.css("border-top", "1px solid #3260AB");
        })
    }

    $('body').click(function(e) {
        if (secenekler.hasClass('opened') && $(e.target).attr('id') != 'txtAra') {
            secenekler.removeClass('opened');
            closeSecenekler();
            $("#txtAra").val('Ne Arıyordunuz?');
        }

    });

})

$(document).ready(function() {
    // check for what is/isn't already checked and match it on the fake ones
    $("input:checkbox").each(function() {
        (this.checked) ? $("#search-" + this.id).addClass('search-checked') : $("#search-" + this.id).removeClass('search-checked');
    });
    // function to 'check' the fake ones and their matching checkboxes
    $(".search-check").click(function() {
        ($(this).hasClass('search-checked')) ? $(this).removeClass('search-checked') : $(this).addClass('search-checked');
        $(this.hash).trigger("click");
        //console.log('se');
        return false;
    });
});

function QuickSearch() {
    var keyword = $("#txtAra").val();
    if (keyword.length >= 3 && keyword != "Ne Arıyordunuz?") {
        var type = 0;
        var checkedItems = $("a.search-checked");
        if (checkedItems.length > 0) {
            $.each(checkedItems, function(data, i) {
                switch (this.id) {
                    case "chkQuickKampanya":
                        type = type | 1;
                        break;
                    case "chkQuickMarka":
                        type = type | 2;
                        break;
                    case "chkQuickSite":
                        type = type | 4;
                        break;
                    case "":
                        break;
                }
            });
        }
        if (type < 1 || type > 7) type = 7;
        window.location.href = webRoot + '/arama/default.aspx?q=' + keyword + "&type=" + type;
    }
}