﻿// Font settings
Cufon.set('fontFamily', 'Bebas Neue').replace('.product_mini_price span');
Cufon.set('fontFamily', 'Bebas Neue').replace('#content_right_small_banners ul li span.productPrice');
Cufon.set('fontFamily', 'Bebas Neue').replace('#content h2.yourCart');
Cufon.set('fontFamily', 'Bebas Neue').replace('#product_details_pricebuy span.price');
Cufon.set('fontFamily', 'Kozuka Gothic Pro L').replace('#content_right_small_banners h2');
Cufon.set('fontFamily', 'Kozuka Gothic Pro L').replace('h1.pageTitle');
Cufon.set('fontFamily', 'Kozuka Gothic Pro L').replace('.banner_big_left h1');
Cufon.set('fontFamily', 'Bebas Neue').replace('.sliderPrice');



$(document).ready(function () {

    $(".defaultText").focus(function (srcc) {
        if ($(this).val() == $(this)[0].title) {
            $(this).removeClass("defaultTextActive");
            $(this).val("");
        }
    });

    $(".defaultText").blur(function () {
        if ($(this).val() == "") {
            $(this).addClass("defaultTextActive");
            $(this).val($(this)[0].title);
        }
    });

    $(".defaultText").blur();

    $("#bannerWrapper").easySlider({
        auto: true,
        continuous: true,
        numeric: true,
        pause: 5000,
        speed: 500
    });

    $(".product_mini_image, #content_right_small_banners ul a, .update a, .remove, .textField, .a-center").hover(function () {
        tip = $(this).find('.tip');
        tip.show();
    }, function () {
        tip.hide();
    }).mousemove(function (e) {
        var mousex = e.pageX + 20;
        var mousey = e.pageY + 20;
        var tipWidth = tip.width();
        var tipHeight = tip.height();
        var tipVisX = $(window).width() - (mousex + tipWidth);
        var tipVisY = $(window).height() - (mousey + tipHeight);

        if (tipVisX < 20) {
            mousex = e.pageX - tipWidth - 20;
        } if (tipVisY < 20) {
            mousey = e.pageY - tipHeight - 20;
        }
        tip.css({ top: mousey, left: mousex });
    });

    // Add to cart listener
    $(function () {
        $('.add').live(
            'click',
            function () {

                var $link = $(this);
                $.ajax({
                    type: 'POST',
                    cache: false,
                    url: this.href,
                    //                        type: 'CREATE',
                    success: function (result) {
                        //alert($link.attr("part"));
                        // $.add2cart($link.attr("part"), 'header_cart img')
                        $('#header_cart').html(result);
                        return false;
                        //$('#header_cart').effect("highlight", {}, 3000);
                    },
                    error: function (xhr, status, ex) {
                        if (xhr.status == 302) // unauthorized
                        {
                            alert('Sorry wrong');
                        }
                    }
                });
                return false;
            });

        /*$('.page').live(
            'click',
            function () {

                var $link = $(this);
                $.ajax({
                    type: 'POST',
                    cache: false,
                    url: this.href,
                    //                        type: 'CREATE',
                    success: function (result) {
                        //alert($link.attr("part"));
                        // $.add2cart($link.attr("part"), 'header_cart img')
                        //  $('#content').html(result);
                        $('#FiltredProductList').html(result); //works
                        return false;
                        //$('#header_cart').effect("highlight", {}, 3000);
                    },
                    error: function (xhr, status, ex) {
                        if (xhr.status == 302) // unauthorized
                        {
                            alert('Sorry wrong');
                        }
                    }
                });
                return false;
            });*/

        $('.page').live(
            'click',
            function () {
                var jsonSearch = $('#frmSearch').serialize();
                var $link = $(this);
                $.ajax({
                    type: 'POST',
                    cache: false,
                    url: this.href,
                    data: jsonSearch,
                    success: function (result) {

                        $('#FiltredProductList').html(result); 
                        return false;
                    },
                    error: function (xhr, status, ex) {
                        if (xhr.status == 302) // unauthorized
                        {
                            alert('Sorry wrong');
                        }
                    }
                });
                return false;
            });

    });

    jQuery('.listInputWrapper').live('click', function (event) {

        if (event.target.type != 'checkbox') {
            //alert('Yes');
            //event.preventDefault();
            jQuery(this).toggleClass('active');
            jQuery(':checkbox', this).trigger('click');

            $.ajax({
                type: 'POST',
                cache: false,
                url: $(this).closest("form").attr('action') + "?random=" + Math.random() * 99999,
                data: $(this).closest("form").serialize(),
                dataType: "html",
                success: function (result) {
                    $('#FiltredProductList').html(result);
                    return false;
                },
                error: function (xhr, status, ex) {
                    if (xhr.status == 302) // unauthorized
                    {
                        alert('Not authorized ajax post.');
                    }
                }
            });


        }
    });



});

// Helper function to update the Cart summary
function UpdateSummary() {
    $.ajax({
        type: 'POST',
        cache: false,
        url: '/Shop/Cart/CartSummary',
        success: function (result) {
            $('#header_cart').html(result);
        }
    });
}


function execute(url) {
    alert(url);
    $.ajax({
        type: 'POST',
        cache: false,
        url: url,
        success: function (result) {
            $('#ajaxUpdate').html(result);
            return false;
        },
        error: function (xhr, status, ex) {
            if (xhr.status == 302) // unauthorized
            {
                alert('Not authorized ajax post.');
            }
        }
    });
    return false;

}
        
