var dontclose = 0;
var fake_select_display = 0;

$(document).click(function () {
    if (fake_select_display) {
        $(".fake_select").hide();
        fake_select_display = 0;
    }
});
$(document).ready(function () {
    $('.detayli_arama_kapsul').css('display', 'none');
    $('.horizontal-menu li.last').mouseover(function () {
        $('.detayli_arama_kapsul').css('display', 'block');
        dontclose = 1;
    });
    $('.detayli_arama_kapsul_gel').mouseleave(function () {
        dontclose = 2;
    });
    $('.detayli_arama_kapsul').mouseleave(function () {
        if (dontclose != 0) {
            $(this).css('display', 'none');
            $(".fake_select").hide();
            dontclose = 0;
        }

    });
    $('.gununPabbucImaji').mouseover(function () {
        $('.gununSayaci').stop().animate({ height: '21px' });
    });
    $('.gununPabbucImaji').mouseleave(function () {
        $('.gununSayaci').stop().animate({ height: '0px' });
    });


    /* FAKE SELECT*/
    function selectbox_aciliyor(acilacak) {
        dontclose = 0;
        var offset = acilacak.offset();
        var x = Number(offset.left);
        var y = Number(offset.top);
        var options_obj = $("#" + acilacak.attr("id") + "_options");

        $(".fake_select").hide();
        fake_select_display = 0;

        if (options_obj.is(":hidden")) {
            options_obj.css("top", y + "px");
            options_obj.css("left", x + "px");
            options_obj.show();

            setTimeout(function () {
                fake_select_display = 1;
            }, 100);
        }
    }
    $("#select_1").click(function () {
        dontclose = 0;
        selectbox_aciliyor($(this));
    });
    /* anasayfa kategorilerinin selectboxların yüklenmesi */
    $("div.cont li:last-child").css("background", "none");
    var c1 = "";
    var c2 = "";
    var c3 = "";
    var c4 = "";
    $("#c1 li").click(function () {
    $("a.send-search-combo img").attr("src", "/main_gobek_search_button_passive.gif");

        //yeniden başla aktivate
        c1 = "";
        c2 = "";
        c3 = "";
        c4 = "";
        $("div#select_2 img.kapla").css("display", "none");
        $("div#select_2 ul.combo li a").html("Ürün grubu seçin");
        $("div#select_3 ul.combo li a").html("Renk seçin");
        $("div#select_3 img.kapla").css("display", "inline");
        $("div#select_4 ul.combo li a").html("Numara veya beden seçin");
        $("div#select_4 img.kapla").css("display", "inline");

        $("div#select_1 ul.combo li a").html($(this).find("span.text_li a").html());
        c1 = $(this).find("span.id_li").html();
        $.ajax({
            url: "/interactive/getselectoptionsforsearch.aspx?c1=" + c1,
            async: false,
            data: "",
            global: false,
            type: "GET",
            dataType: "html",
            success: function (response) {
                $("#select_2_options .cont").html("");
                $("#select_2_options .cont").append(response);

                $("div.cont li:last-child").css("background", "none");

                $("#c2 li").click(function () {
                    //ara butonactive
                    $("a.send-search-combo img").attr("src", "/localImages/main_gobek_search_button.gif");
                    c3 = "";
                    c4 = "";
                    $("div#select_3 img.kapla").css("display", "none");
                    $("div#select_4 img.kapla").css("display", "none");
                    $("div#select_3 ul.combo li a").html("Renk seçin");
                    $("div#select_4 ul.combo li a").html("Numara veya beden seçin");
                    $("div#select_2 ul.combo li a").html($(this).find("span.text_li a").html());
                    c2 = $(this).find("span.id_li").html();
                    $.ajax({
                        url: "/interactive/getselectoptionsforsearch.aspx?c1=" + c1 + "&c2=" + c2,
                        async: false,
                        data: "",
                        global: false,
                        type: "GET",
                        dataType: "html",
                        success: function (response) {
                            $("#select_3_options .cont").html("");
                            $("#select_3_options .cont").append(response);
                            $("div.cont li:last-child").css("background", "none");

                            $("#select_4_options .cont").html("");
                            $("#select_4_options .cont").append(response);

                            $("#c3 li").click(function () {
                                $("div#select_4 ul.combo li a").html("Numara veya beden seçin");
                                $("div#select_3 ul.combo li a").html($(this).find("span.text_li a").html());
                                c3 = $(this).find("span.id_li").html();
                                if (c4 == "") {
                                    gonder = "&c3=" + c3;
                                } else {
                                    gonder = "&c3=" + c3 + "&c4=" + c4;
                                }
                                $.ajax({
                                    url: "/interactive/getselectoptionsforsearch.aspx?c1=" + c1 + "&c2=" + c2 + "&c3=" + c3,
                                    async: false,
                                    data: "",
                                    global: false,
                                    type: "GET",
                                    dataType: "html",
                                    success: function (response) {
                                        $("#select_4_options .cont").html("");
                                        $("#select_4_options .cont").append(response);
                                        $("div.cont li:last-child").css("background", "none");
                                        $("#c4 li").click(function () {
                                            c4 = $(this).find("span.id_li").html();
                                            $("div#select_4 ul.combo li a").html($(this).find("span.text_li a").html());
                                            $("div.cont li:last-child").css("background", "none");
                                            /*$.ajax({
                                            url: "/interactive/getselectoptionsforsearch.aspx?c1="+c1+"&c2="+c2+"&c4="+c4,
                                            async: false,
                                            data: "",
                                            global: false,
                                            type: "GET",
                                            dataType: "html",
                                            success: function(response){												
                                            $("#select_3_options .cont").html("");
                                            $("#select_3_options .cont").append(response);														
																								
                                            }
                                            });*/

                                        });
                                    }
                                });

                            });
                            $("#c4 li").click(function () {
                                $("div#select_3 ul.combo li a").html("Renk seçin");
                                $("div#select_4 ul.combo li a").html($(this).find("span.text_li a").html());
                                c4 = $(this).find("span.id_li").html();
                                if (c3 == "") {
                                    gonder = "&c4=" + c4;
                                } else {
                                    gonder = "&c3=" + c3 + "&c4=" + c4;
                                }
                                $.ajax({
                                    url: "/interactive/getselectoptionsforsearch.aspx?c1=" + c1 + "&c2=" + c2 + "&c4=" + c4,
                                    async: false,
                                    data: "",
                                    global: false,
                                    type: "GET",
                                    dataType: "html",
                                    success: function (response) {
                                        $("#select_3_options .cont").html("");
                                        $("#select_3_options .cont").append(response);
                                        $("div.cont li:last-child").css("background", "none");
                                        $("#c3 li").click(function () {
                                            c3 = $(this).find("span.id_li").html();
                                            $("div#select_3 ul.combo li a").html($(this).find("span.text_li a").html());
                                            $("div.cont li:last-child").css("background", "none");
                                            /*$.ajax({
                                            url: "/interactive/getselectoptionsforsearch.aspx?c1="+c1+"&c2="+c2+"&c3="+c3,
                                            async: false,
                                            data: "",
                                            global: false,
                                            type: "GET",
                                            dataType: "html",
                                            success: function(response){												
                                            $("#select_4_options .cont").html("");
                                            $("#select_4_options .cont").append(response);														
																								
                                            }
                                            });	*/

                                        });
                                    }
                                });
                            });
                        }
                    });
                });
            }
        });
    });
    $("#select_2").click(function () {
        if (c1 != "") {
            //selectbox a�
            selectbox_aciliyor($(this));
        }
    });
    $("#select_3").click(function () {
        if (c2 != "") {
            //selectbox ac				
            selectbox_aciliyor($(this));
            //selectbox ac				
        }
    });
    $("#select_4").click(function () {
        if (c2 != "") {
            //selectbox aç
            selectbox_aciliyor($(this));
            //selectbox aç			
        }
    });
    $("a.send-search-combo").click(function () {
        if (c2 != "" && c1 != "") {
            if (c4 == "" && c3 != "") {
                gonder = "&c3=" + c3;
            } else if (c3 == "" && c4 != "") {
                gonder = "&c4=" + c4;
            } else if (c3 == "" && c4 == "") {
                gonder = "";
            } else if (c3 != "" && c4 != "") {
                gonder = "&c3=" + c3 + "&c4=" + c4;
            }
            window.location.href = "http://www.pabbuc.com/interactive/getcategoryfurl.aspx?c1=" + c1 + "&c2=" + c2 + gonder

        }
    });

});


