var wl_url = base_url + '/wishlist/wl';

$(function(){
    //Shadowbox
    Shadowbox.init();

    // Flags
    $('#lang-select-wide').click(function () {
        $('#flags').slideDown('fast');
    });

    
    $('.psm-level1').click(function () {
        $(this).next('.psm-level2').slideDown('fast').siblings('.psm-level2:visible').slideUp('fast');
    });

    // Background Slide with Cycle
    if($('#bg-slider img').length > 0){
        $('#bg-slider').cycle({
           fx: 'fade',
           speed: 1000
        });
    }

    // Background Slide with Cycle
    if($('#content-back-img img').length > 0){
        $('#content-back-img').cycle({
           fx: 'fade',
           speed: 1000
        });
    }
    
    // News Slide
    $("#news-scrollable").scrollable();

    // Design Function Slide
    $("#desfun-scrollable").scrollable();

    // Products Sub Slider
    $('#products-title-h2').hover(function(){
        $('#products-sub-wrp').show();
    },function(){
        $('#products-sub-wrp').hide();
    });

    $('#products-sub-wrp').hover(function(){
        $(this).show();
    },function(){
        $(this).hide();
    });
    
    // Products Scroller
    if ($('#products .scrollable').length > 0)
    {
        $('#products .scrollable').scrollable(
        {
            next        : '.next',
            prev        : '.prev',
            keyboard    : false,
            circular    : false
        });

        var productsScrollable = $('#products .scrollable').scrollable();
        $('.scrollablecontrols .prev').fadeOut(200);
        productsScrollable.onBeforeSeek = function()
        {
            $('ul#productsnav li').removeClass('current');
        }
        productsScrollable.onSeek = function()
        {
            $('ul#productsnav li:eq(' + productsScrollable.getIndex() + ')').addClass('current');
            if (productsScrollable.getIndex() == 0)
                $('.scrollablecontrols .prev').fadeOut(200);
            else
                $('.scrollablecontrols .prev').fadeIn(200);
            if (productsScrollable.getIndex() == productsScrollable.getSize() - 1)
                $('.scrollablecontrols .next').fadeOut(200);
            else
                $('.scrollablecontrols .next').fadeIn(200);

        }
        if (productsScrollable.getSize() == 1)
        {
            $('.scrollablecontrols').fadeOut(200);
        }
        else if (productsScrollable.getSize() > 1)
        {
            $('.scrollablecontrols').fadeIn(200);
        }

        $('ul#productsnav li a').click(function(e)
        {
            e.preventDefault();
            productsScrollable.seekTo($(this).parent().index(), 'slow');
        });
    }
    // Shortcut News Wrp
    $('#news-slide-button').click(function(){
       $('#news-slide-news-wrp').animate({
           height: 'toggle'
       });
    });

    // Superfish
   $("ul.#pt-menu").superfish({
        delay:       1000,                            // one second delay on mouseout
        animation:   {opacity:'show',height:'show'},  // fade-in and slide-down animation
        speed:       'fast',                          // faster animation speed
        autoArrows:  false,                           // disable generation of arrow mark-up
        dropShadows: false                            // disable drop shadows
    });
    
   
    // Product Accordion Menu
    $('.accordionmenu ul').hide();
    $('.accordionmenu ul.selected').show();
    $('.accordionmenu li a').click( function() {
        var checkElement = $(this).next();
        if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
        return false;
        }
        if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
            $('.accordionmenu ul:visible').slideUp('normal');
            checkElement.slideDown('normal');
            return false;
        }
    });

    $(window).load(function(){
        
        $('#bg-slider img').show();
        $('#content-back-img img').show();

        // Content ScrollPane           
				if ($('.scroll-pane').length > 0)
				{
					$('.scroll-pane').jScrollPane();
	        var pane = $('#store-l-menu-wrp').jScrollPane({animateTo:false})
	        pane.css('display', 'block');
					if (pane.length > 0)	pane[0].scrollTo('li#active');
				}
        
        
        
    });
    $(".add-wishlist").live("click", function(){
        var lang = $("#language").val();
        var post_product_title = $("#productTitle").val();
        var post_product_slug = $("#productSlug").val();
        var post_product_url = $("#productUrl").val();
        var messages = new Array();
        var buttonTitles = new Array();
        messages['tr'] = 'Ürün Başarıyla Eklenmiştir';
        messages['en'] = 'Ürün Başarıyla Eklenmiştir.(en)';
        buttonTitles['tr'] = 'Favori Listemden Çıkar';
        buttonTitles['en'] = 'Delete from Favorites';
        if (post_product_slug == '' && lang == '') {
            return false;
        }
        $.ajax({
            
            type: "POST",
            url: wl_url,
            data:   "ajaxType=addProduct"+
                    "&productTitle=" + post_product_title +
                    "&productSlug=" + post_product_slug +
                    "&productUrl="+post_product_url+
                    "&language=" + lang,
            success: function(html){
                $("#wishlist_number").html(html);
                $.jGrowl(messages[lang], {life: 10000});
                $('#wishlist').removeClass("add-wishlist").addClass("delete-wishlist");
                $('#wishlist').val( buttonTitles[lang]);
            }
        });
    });

    $(function(){

    $(".delete-wishlist").live("click", function(){
        var post_product_slug = $("#productSlug").val();
        var lang = $("#language").val();
        var messages = new Array();
        var buttonTitles = new Array();
        messages['tr'] = 'Ürün Başarıyla İstek Listenizden Kaldırılmıştır.';
        messages['en'] = 'Ürün Başarıyla İstek Listenizden Kaldırılmıştır.(en)';
        buttonTitles['tr'] = 'Favori Listeme Ekle';
        buttonTitles['en'] = 'Add My Favorites';
        $.ajax({
		type: "POST",
		url: wl_url,
                data: 	"ajaxType=delProduct"+
                        "&productSlug=" + post_product_slug,

		success: function(html){
                        $("#wishlist_number").html(html);
                        $.jGrowl(messages[lang], {life: 10000});
                        $('#wishlist').removeClass("delete-wishlist").addClass("add-wishlist");
                        $('#wishlist').val(buttonTitles[lang]);
		}
            });
    });
    });
    
    $(function(){

    $(".wishlist-page-delete").live("click", function(){
        var delvalue = $(this).attr("delvalue");
        $.ajax({
		type: "POST",
		url: wl_url,
                data: 	"ajaxType=delWishlistProduct"+
                        "&productSlug=" + delvalue,

		success: function(html){
                        $("#wishlist_wrp").html(html);
                        $.jGrowl('Ürün Başarıyla İstek Listenizden Kaldırılmıştır.', {life: 10000});
		}
            });
    });
    });

    $(function(){
    $("#wishlist_empty").live("click", function(){
        $.ajax({
		type: "POST",
		url: wl_url,
                data: 	"ajaxType=emptyWishlist",
		success: function(html){
			$("#wishlistmenu").html(html);
                        $.jGrowl('İstek Listeniz Boşaltılmıştır.', {life: 10000});
		}
            });
    });
    });
});
























