﻿
$(document).ready(function ()
{
    $('.jqtransform').jqTransform();

    $('.ProductInfoTabs .TeknikDetayTab').click(function ()
    {
        $('.TeknikDetayTab').addClass('Selected');
        $('.GenelBilgiTab').removeClass('Selected');

        $('.GenelBilgiContent').hide();
        $('.TeknikDetayContent').show();
    });

    $('.ProductInfoTabs .GenelBilgiTab').click(function ()
    {
        $('.GenelBilgiTab').addClass('Selected');
        $('.TeknikDetayTab').removeClass('Selected');

        $('.GenelBilgiContent').show();
        $('.TeknikDetayContent').hide();
    });

    $('.ProductInfoTabs .GenelBilgiTab').click();

    $('#loopedSlider').loopedSlider({
        restart: 5000,
        slidespeed: 700,
        containerClick: false,
		autoStart: 5000
    });

    $('#loopedSliderHome').loopedSlider({
        restart: 5000,
        slidespeed: 700,
        containerClick: false
    });

    $('#loopedSliderKategoriPages').loopedSlider({
        restart: 5000,
        slidespeed: 1000,
        containerClick: true,
        autoStart: 5000
    });
	/*
    $('ul#HPFadeImages').innerfade({
        speed: 1500,
        timeout: 6000,
        type: 'sequence',
        containerheight: '333px'
    });
	*/
	$('#HomeAnimation .slides').slides({
		preload: true,
		preloadImage: 'img/loading.gif',
		play: 5000,
		pause: 2500,
		fadeSpeed: 1250,
		effect: 'fade',
		crossfade: true
	});

    /* MAĞAZALAR DROPDOWN */
    $('.MagazaDropDownContainer').change(function ()
    {
        var magazaUrl = $('select', $('.MagazaDropDownContainer')).val();

        if (magazaUrl == '')
        {
            return;
        }
        //alert(magazaUrl);
        //
        document.location = magazaUrl;

    });

    /* Basak- Indirimdekiler ve Marka Sayfalarındaki tümünü göster linklerinin jquerysi*/
    /*
    $('.IndirimdekilerContainer .ImageListContainer .ImageContainer').hide();
    $('.IndirimdekilerContainer .ImageListContainer .ImageContainer:nth-child(1)').show();
    $('.IndirimdekilerContainer .ImageListContainer .ImageContainer:nth-child(2)').show();
    $('.IndirimdekilerContainer .ImageListContainer .ImageContainer:nth-child(3)').show();
    $('.IndirimdekilerContainer .ImageListContainer .ImageContainer:nth-child(4)').show();
    $('.IndirimdekilerContainer .ImageListContainer .ImageContainer:nth-child(5)').show();

    $('.IndirimdekilerContainer  .rightTitle').click(function ()
    {
    // $(this).parent().parent().find('.ImageListContainer .ImageContainer').show();
    var index = $(this).parent().attr("nodeIndex");

    $('.IndirimdekilerContainer  .ImageListContainer').each(function ()
    {
    if ($(this).attr("nodeIndex") == index + 2)
    $(this).find("..ImageContainer").show();
    });
    });
    */

    var emailGirinText = $("#hidEPostAdresiGiriniz").val();
    var alreadySubscribed = $("#hidAlreadyMember").val();
    var notAnEmailText = $("#hidGecersizEmail").val();
    var basariylaKaydoldunuzText = $("#hidBasariylaKaydoldunuz").val();
    var urunAramaText = $("#hidUrunArama").val();

    $(".TxtBoxContainer input").val(emailGirinText);

    $(".TxtBoxContainer input").focus(function ()
    {
        if ($(this).val() == emailGirinText)
        {
            $(this).val("")
        }
    });
    $(".TxtBoxContainer input").click(function ()
    {
        if ($(this).val() == emailGirinText)
        {
            $(this).val("")
        }
    });

    $(".SearchTextBox").val(urunAramaText);

    $(".SearchTextBox").click(function ()
    {
        if ($(this).val() == urunAramaText)
        {
            $(this).val("");
        }
    });

    $('body').click(function ()
    {
        if ($(".TxtBoxContainer input").val() == "")
        {
            $(".TxtBoxContainer input").val(emailGirinText);
        }
        if ($(".SearchTextBox").val() == "")
        {
            $(".SearchTextBox").val(urunAramaText);
        }
    });

    $('.TxtBoxContainer input').click(function (event) { event.stopPropagation(); });
    $(".SearchTextBox").click(function (event) { event.stopPropagation(); });

    $("#NewsletterEmail").blur(function ()
    {
        if ($(this).val() == "")
        {
            $(this).val(emailGirinText)
        }
    });


    $(".GonderBtn img").click(function ()
    {
        // Disable input
        StartSaveSubscriberProcessProgress();

        $.ajax({
            type: "POST",
            url: websiteRoot + "WebMethods/SaveEmailForNewsletter.aspx/SaveEmailForNewsletter",
            data: "{ 'email' : '" + $(".TxtBoxContainer input").val() + "' }",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg)
            {
                if (msg.d.IsSuccessful)
                {
                    alert(basariylaKaydoldunuzText);
                    $(".TxtBoxContainer input").val(emailGirinText);

                }
                else
                {
                    if (msg.d.ErrorMessage == "NotAnEmail")
                    {
                        alert(notAnEmailText);
                        //$("#NewsletterEmail").val(notAnEmailText);
                    }
                    else if (msg.d.ErrorMessage == "AlreadySubscibed")
                    {
                        //$("#NewsletterEmail").val();
                        alert(alreadySubscribed);
                    }
                    //alert(msg.d.ErrorMessage);
                }
            },
            error: function (xmlHttpRequest, textStatus, errorThrown)
            {
                //alert(textStatus + ", " + errorThrown + ", " + xmlHttpRequest);
            }
        });

        EndSaveSubscriberProcessProgress();
    });
});

function EndSaveSubscriberProcessProgress()
{
    $(".TxtBoxContainer input").removeAttr("disabled");
    $(".GonderBtn img").removeAttr("disabled");
}

function StartSaveSubscriberProcessProgress()
{
    $(".TxtBoxContainer input").attr("disabled", "disabled");
    $(".GonderBtn img").attr("disabled", "disabled");
}

// Ürün detay sayfasındaki "KOLEKSİYONA AİT DİĞER ÜRÜNLER" slider'ının kodu
// Set container height & width after images have been loaded
$(window).load(function ()
{
    var $items = $(".CollectionWindowsContainer > .CollectionInfo");

    if ($items.length <= 4)
    {
        return false;
    }

    $(".CollectionContainerArrows").fadeIn();

    var middleItemIndex = Math.floor(($items.length + 1) / 2);
    var totalWidth = 0;

    if ($items.length > 2)
    {
        $(".CollectionWindowsContainer > .CollectionInfo:lt(" + middleItemIndex + ")").each(function ()
        {
            totalWidth += $(this).width();
            totalWidth += $(this).css('margin-right').replace("px", "") * 1;
        });

        $(".CollectionWindowsContainer").width(totalWidth);
    }

    var pageSize = 248;
    var animationDuration = 700;

    var currentPage = 0;
    var maxPage = Math.ceil($items.length / 4);

    $(".CollectionContainerArrows .previous").removeClass('Active');

    if (maxPage > 1)
    {
        $(".CollectionContainerArrows .next").addClass('Active');
    }

    $(".CollectionContainerArrows .next").click(function ()
    {
        //alert("currentPage before: " + currentPage);

        if (currentPage < maxPage - 1)
        {
            currentPage++;

            if (currentPage == maxPage - 1)
            {
                $(this).removeClass('Active');
            }
            else
            {
                $(this).addClass('Active');
            }

            $(".CollectionContainerArrows .previous").addClass('Active');

            if (currentPage == maxPage)
            {
                $(".CollectionWindowsContainer").animate({ left: -(pageSize) }, animationDuration);
            }
            else
            {
                $(".CollectionWindowsContainer").animate({ left: -currentPage * pageSize }, animationDuration);
            }
        }
        else
        {
            $(this).removeClass('Active');
        }

        //alert("currentPage after: " + currentPage);

        return false;
    });

    $(".CollectionContainerArrows .previous").click(function ()
    {
        //alert("currentPage before: " + currentPage);

        if (currentPage > 0)
        {
            currentPage--;

            if (currentPage == 0)
            {
                $(this).removeClass('Active');
            }
            else
            {
                $(this).addClass('Active');
            }
            $(".CollectionContainerArrows .next").addClass('Active');

            $(".CollectionWindowsContainer").animate({ left: -currentPage * pageSize }, animationDuration);
        }
        else
        {
            $(this).removeClass('Active');
        }

        //alert("currentPage after: " + currentPage);

        return false;
    });
});

// jqTransform events
$(document).ready(function ()
{
    $('.jqTransformSelectWrapper ul li a', $('#SubCategoriesDropDownContainer')).click(function ()
    {
        var selectedItemUrl = $('select', $('#SubCategoriesDropDownContainer')).val();

        //alert(1);

        if (selectedItemUrl == '')
        {
            //alert(2);
            return;
        }

        //alert(3);

        //alert('redirecting to: ' + selectedItemUrl);
        document.location = selectedItemUrl;
    });

    $('.jqTransformSelectWrapper ul li a', $('#MagazaDropDownContainer')).click(function ()
    {
        var selectedItemUrl = $('select', $('#MagazaDropDownContainer')).val();

        if (selectedItemUrl == '')
        {
            return;
        }

        //alert('redirecting to: ' + selectedItemUrl);
        document.location = selectedItemUrl;
    });
});

// Hide empty search results
$(document).ready(function ()
{
    $('.ImageListContainer').each(function ()
    {
        if ($('.ImageContainer', $(this)).length == 0)
        {
            $(this).parent('.SearchResultsOfCategoryContainer').hide();
        }
    });
});

// Başa Dön - Bunun yerine a tag'inin #top özelliği kullanıldı
$(document).ready(function ()
{
//    $('.BasaDon').click(function ()
//    {
//        $('html').scroll(0);
//        return false;
//    });
});

