﻿
$(document).ready(function ()
{
    Shadowbox.init({
        continuous: 'true',
        handleOversize: 'resize',
        onClose: back_to_resize,
        onChange: back_to_resize,
        onOpen: back_to_resize
    });

    $('ul#HPFadeImages').innerfade({
        speed: 3000,
        timeout: 6000,
        type: 'sequence',
        containerheight: '932px'
    });

    $('.css-scrollbar').scrollbar();
});

// Ürün sayfasindaki slider
$(window).load(function ()
{
    /* WIDTH 940 */
    var currentPage = 0;
    var totalWidth = 0;

    $(".UrunContent > div").each(function ()
    {
        totalWidth += $(this).outerWidth(true);
    });

    $(".UrunContent").width(totalWidth);

    if (totalWidth < $(".UrunContainer").width() - 100)
    {
        $(".UrunContainer .next").hide();
        $(".UrunContainer .previous").hide();
    }

    var pageSize = 191;
    var animationDuration = 700;
    $(".UrunContainer .next").click(function ()
    {
        var containerWidth = $(".UrunContent").width();
        var visibleWidth = $(".UrunContainer").width();
        var maxPage = Math.ceil((containerWidth - visibleWidth + 64) / pageSize);
        if (currentPage < maxPage)
        {
            currentPage++;
            if (currentPage == maxPage)
                $(".UrunContent").animate({ left: -(containerWidth - visibleWidth + 64) }, animationDuration);
            else
                $(".UrunContent").animate({ left: -currentPage * pageSize }, animationDuration);

        }

        return false;
    });
    $(".UrunContainer .previous").click(function ()
    {
        if (currentPage > 0)
        {
            currentPage--;
            $(".UrunContent").animate({ left: -currentPage * pageSize }, animationDuration);
        }

        return false;
    });

    // Hide loading gif
    $('#UrunLoadingGifDetay').hide();

    // fadeIn() will not work with visibility:hidden. so first we hide it (so that fadeIn works),
    // then make contents visible and finally fadeIn(). visibility:hidden is used instead of
    // display:none because in case of the latter, child elements' widths are not calculated
    // correctly
    $('.UrunContent').hide();
    $('.UrunContent').css('visibility', 'visible');
    $('.UrunContainer > .next').css('visibility', 'visible');
    $('.UrunContainer > .previous').css('visibility', 'visible');
    $('.UrunContent').fadeIn();

});

// Kategori sayfasindaki slider
$(window).load(function ()
{
    /* WIDTH 570 */
    var currentPage = 0;
    var totalWidth = 0;

    $(".KategoriContent > div").each(function ()
    {
        totalWidth += $(this).outerWidth(true);
    });

    //alert("total: " + totalWidth);
    $(".KategoriContent").width(totalWidth);

    if (totalWidth < $(".KategoriListContainer").width() - 100)
    {
        $(".KategoriListContent .next").hide();
        $(".KategoriListContent .previous").hide();
    }

    var pageSize = 300;
    var animationDuration = 800;
    $(".KategoriListContent .next").click(function ()
    {
        var containerWidth = $(".KategoriContent").width();
        var visibleWidth = $(".KategoriListContainer").width();
        var maxPage = Math.ceil((containerWidth - visibleWidth + 44) / pageSize);
        if (currentPage < maxPage)
        {
            currentPage++;
            if (currentPage == maxPage)
                $(".KategoriContent").animate({ left: -(containerWidth - visibleWidth + 44) }, animationDuration);
            else
                $(".KategoriContent").animate({ left: -currentPage * pageSize }, animationDuration);

        }

        return false;
    });
    $(".KategoriListContent .previous").click(function ()
    {
        if (currentPage > 0)
        {
            currentPage--;
            $(".KategoriContent").animate({ left: -currentPage * pageSize }, animationDuration);
        }

        return false;
    });

    // Hide loading gif
    $('#UrunLoadingGif').hide();

    // fadeIn() will not work with visibility:hidden. so first we hide it (so that fadeIn works),
    // then make contents visible and finally fadeIn(). visibility:hidden is used instead of
    // display:none because in case of the latter, child elements' widths are not calculated
    // correctly
    $('.KategoriContent').hide();
    $('.KategoriContent').css('visibility', 'visible');
    $('.KategoriListContent > .next').css('visibility', 'visible');
    $('.KategoriListContent > .previous').css('visibility', 'visible');
    $('.KategoriContent').fadeIn();
});

// Ürün detay sayfasındaki soldaki "PAKET TÜRLERİ" menüsü
$(window).load(function ()
{
    var moreButtonText = $('#hidMoreButtonText').val();
    var lessButtonText = $('#hidLessButtonText').val();

    var $cssListMenu = $('.MenuPaketTurleri ul#menuElem');
    var $menuItems = $('.MenuPaketTurleri ul#menuElem li');  // IE7 has issues with $('li', $cssListMenu)

    var cssListMenuHeight = 0;
    var firstNItemsHeight = 0;

    $menuItems.each(function ()
    {
        cssListMenuHeight += $(this).outerHeight(true);
    });

    if ($menuItems.length > 8)
    {
        $('.MenuPaketTurleri .MoreLessButton').addClass('Visible').text(moreButtonText);

        $menuItems.slice(0, 8).each(function ()
        {
            firstNItemsHeight += $(this).outerHeight(true);
            //alert($(this).index() + ':' + $(this).outerHeight(true));
        });

        // manual adjust
        if ($('body').hasClass('IE9'))
        {
            firstNItemsHeight -= 5;
            //alert("IE9");
        }

        $cssListMenu.height(firstNItemsHeight);
    }
    else
    {
        $cssListMenu.height(cssListMenuHeight);
    }

    $('.MenuPaketTurleri .MoreLessButton').click(function ()
    {
        if ($cssListMenu.hasClass('LongMenu'))
        {
            $cssListMenu.animate({ height: firstNItemsHeight }, 400);
            $cssListMenu.removeClass('LongMenu');
            $(this).text(moreButtonText);
        }
        else
        {
            //alert("asdf: " + cssListMenuHeight);

            $cssListMenu.animate({ height: cssListMenuHeight }, 400);
            $cssListMenu.addClass('LongMenu');
            $(this).text(lessButtonText);
        }

        return false;
    });
});

$(document).ready(function ()
{
});

