(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery);

jQuery.preLoadImages("public/gfx/schowek-szczegoly2.jpg", "public/gfx/schowek-szczegoly.jpg", "public/gfx/schowek-szczegoly2.jpg", "public/gfx/schowek-szczegoly.jpg");

$(function(){


    $('input[type=submit]').addClass('przycisk2');
    $('input.przycisk').removeClass('przycisk2');

    var schowekButtonPosition = $('#ProductParams').height() + $('#ProductAttribs').height() + $('.ProductHeader').height() + 88;
    $('#schowekButtonDiv').css('top',schowekButtonPosition);

    var top = parseInt(schowekButtonPosition-18);




    $('#schowekAdd').bind('click', function(){

        $('.Blank').css('background','url(public/gfx/schowek-szczegoly.jpg) no-repeat');
        var id = $(this).find('#schowekPrzycisk').attr('alt');
        $.ajax({
           type: "POST",
           url: "index.php?module=Schowek&Action=AjaxAdd&DressID="+id,
           success: function(msg){
                if(msg=='success')
                {
                     $('#schowekAdd').fadeOut('fast', function(){
                        $('.fadeOutThis').fadeOut('slow');
                        $(this).find('#schowekPrzycisk').hide();
                        $(this).css('border','2px solid #d1bd98').fadeIn('fast', function(){
                            $(this).animate({
                                'left': '286',
                                'top': '-'+top,
                                'width': '150',
                                'height': '60'
                            }, 500, function(){
                                $(this).css({'border':0, 'display':'block'});
                                $(this).show().find('.SchowekDetailsAjax').show();
                                $(this).unbind('click');
                                $('.SchowekDetails2').hide();
                                $('.SchowekDetails.one').show().find('.fadeOutThis').hide();
                                $('.SchowekDetails.two').show().css('background','url(public/gfx/schowek-szczegoly2.jpg) no-repeat');
                                    var count = 0;
                                    $('.Blank2_2').each(function(){
                                        count = count + 1;
                                    });

                                    if(count==1)
                                    {
                                        $('.Blank2_2').hide();
                                    }

                                    var iloscSukien = parseInt($('#IloscSukien').text())+1;
                                    $('#IloscSukien').text(iloscSukien);
                            });
                        });
                    });
                }
           }
         });
    });

});
