$(document).ready(function () {

    /* Global Triggers */
    $(document).pngFix();
    $(".stylish input, .stylish textarea, .stylish select, .stylish button").uniform();
    var quantityDDActive = $("#content .subPageLeft .subPageNavigation .subNav .inside li.active").next().find("dl").children().size();
    if (quantityDDActive > 0)
        $("#content .subPageLeft .subPageNavigation .subNav .inside li.active").next().css("height", quantityDDActive * 22);


    /* SubPage Href */
    $('#content .subPageLeft .subPageNavigation .subNav .inside li.makeLink').click(function () {
        window.open($(this).attr('href'), '_self');
    });
    $('#content .subPageLeft .subPageNavigation .subNav .inside li.subMenu dl dd').click(function () {
        window.open($(this).attr('href'), '_self');
    });

    /* Toggle() mainContent .left ul.navigation li.subMenu */
    $('.subMenuToggle').click(function (event) {
        toggleAll($(this));
        toggleLeft($(this));
    });
    function toggleAll(el) {
        $('.subMenuToggle').each(function (ind) {
            if ($(this) == el) {
                alert("uu");
                return;
            }
            if ($(this).next().css("display") == "none")
                return;
            $(this).next().css("height", 22);
            $(this).next(".subMenu").toggle();
            $(this).toggleClass("noBorder");
        });
    }
    function toggleLeft(el) {


        var quantityDD = 22;
        quantityDD = (el.next().find("dl").children().size()) * 22;
        el.next().css("height", quantityDD);
        el.next(".subMenu").toggle("200");
        el.toggleClass("noBorder");
    }

    /* Promo Slider */
    var getQuantity = $(".triplePromo").attr("quantity")
    $('#promoSlider').bxSlider({
        displaySlideQty: getQuantity,
        moveSideQty: 1
    });

    /* Tabs */
    $(".tabContent").hide();
    $("dl.makeTab dd:first-child").addClass("active").show();
    $(".tabs").find(".tabContent:first").show();

    $("dl.makeTab dd").click(function () {
        $(this).parent().find('dd').removeClass("active");
        $(this).addClass("active");
        $(this).parents('.tabs').find(".tabContent").hide();

        var activeTab = $(this).attr("href");
        $(activeTab).show();
        return false;
    });

    /* Set up the Height of Sub Page Content Navigation  */
    var subPageHeight = $("#content .subPageContent").height();
    if (subPageHeight > 600)
        $("#content .subPageLeft .subPageNavigation .subNav").css("height", subPageHeight);

    /* SubPage Accordion */

    // If you show first accordion, change the attribute of .subPageContent as 'show'
    if ($("#content .subPageContent").attr("attrAccordionFirst") == "show") {
        $("#content .subPageContent .bigAccordion .accordionMiddle:first").addClass("active");
        $("#content .subPageContent .accordion .accordionContent:first").slideDown(300);
    }

    $("#content .subPageContent .bigAccordion .showHide").click(function () {
        

        // Eklenen ilk accordion'un açılması için comment'lendi.
        //if ($(this).parent().parent().find('.accordionContent').size() == 1)
          //  return;
        
        //If you hide accordions when you click another accordion, change the attribute of .subPageContent as 'single'
        if ($("#content .subPageContent").attr("attrAccordionType") == "single") {
            $("#content .subPageContent .accordion .accordionMiddle").removeClass("active");
            $("#content .subPageContent .accordion .accordionContent").hide(300);
        }

        $(this).parent().find('.accordionMiddle').toggleClass("active");
        $(this).parent().find('.accordionContent').slideToggle();

        var subPageHeight = $("#content .subPageContent").height() + 90;

        if ($("#content .subPageContent .accordion .accordionMiddle").hasClass("active")) {
        } else {
            $("#content .subPageLeft .subPageNavigation .subNav").css("height", "auto");
        }
    });


    /* Bireysel Slider*/
    $(".slideTrigger").click(function () {
        slideTemp = $(this);
        if ($(this)[0].className.indexOf("bireysel") >= 0) {
            $.bireyselSlider();
            $.bireyselSlider2();
            $(".bireysel .icerik").fadeIn(1250);
        }
        if ($(this)[0].className.indexOf("kurumsal") >= 0) {
            $(".kurumsal .icerik").show();
            $.kurumsalSlider();
            $.kurumsalSlider2();
            $(".kurumsal .icerik").fadeIn(1250);
        }
    });
    $.extend({
        bireyselSlider: function () {
            $('.bireysel .left').animate({ left: '-8px', opacity: 0 }, 500, function () {
                $('.bireysel .left').css('z-index', '-1')
            });
        },
        bireyselSlider2: function () {
            $('.bireysel .right').animate({
                left: '66px',
                opacity: 0
            }, 500, function () {
                $('.bireysel .right').css('z-index', '-1')
            });
        },
        kurumsalSlider: function () {
            $('.kurumsal .left').animate({ left: '-8px', opacity: 0 }, 500, function () {
                $('.kurumsal .left').css('z-index', '-1')
            });
        },
        kurumsalSlider2: function () {
            $('.kurumsal .right').animate({
                left: '66px',
                opacity: 0
            }, 500, function () {
                $('.kurumsal .right').css('z-index', '-1')
            });

            $('.kurumsal .right').animate({
                left: '66px',
                opacity: 0
            }, 500, function () {
                $('.kurumsal .right').css('z-index', '-1')
            });
        }
    });

});
