/*!
 * seeSlideShow2 - dynamiczny pokaz
 * @author Mirosław Seehawer mireksee@gmail.com
 * to: delege
 * use: jQuery(".see-slide-show").seeSlideShow2();
 * animateStart: {'z-index':10,top:-510,opacity: 0.4,display:'block'},
 * animateEnd: {opacity: 1.0,top:0},
 * html:
 * <div class="see-slide-show">
 * </div>
 * css:
 */
(function($) {
    $.fn.seeSlideShow2 = function(options){
        // domyslne ustawienia
        var settings = $.extend({
            hoverPause : true,
            changeSpeed : 1000,
            speed : 5000,
            animateStart: {'z-index':10,top:-427,opacity: 0.3,display:'block'},
            animateEnd: {opacity: 1.0,top:0},
            height: 427
        }, options);

        return this.each(function(){

            var seeSlider = $(this).css({position:'relative'});
            var gallery = seeSlider.children('.see-image').css({display:'none'});
            var boxs = seeSlider.children('.see-box').css({display:'none'});
            var count = gallery.length-1;
            var active = 0;
            var last = null;
            var timer = null;
            var idle = 1;

            seeSlider.css({height:settings.height});
            gallery.css({position:'absolute'})
            boxs.css({position:'absolute'})
            $(gallery[active]).css({display:'block'});
            $(boxs[active]).css({display:'block'});

            seeSlider.find('.menu3 ul li a').click(function(){ if(idle == 1){play();} return false;});


            timer = setInterval( function(){ play(); }, parseInt(settings.speed));

            if(settings.hoverPause){
                seeSlider.hover(
                    function(){ clearInterval(timer); },
                    function(){ timer = setInterval( function(){ play(); }, parseInt(settings.speed)); }
                );
            }

            function play() {
                idle = 0;
                last = $(gallery[active]).css({'z-index':9});
                lastb = $(boxs[active]).css({'z-index':9});
                active = active + 1;
                if(active > count){
                    active = 0;
                }

                lastb.css({display:'none'});
                $(boxs[active]).css({display:'block'});

                $(gallery[active]).css(settings.animateStart)
                    .animate(settings.animateEnd, parseInt(settings.changeSpeed), function() {
                        last.css({display:'none'});
                        idle = 1;
                    });

                i = 240-((active)*36);
                $("#but-2").stop(true, true).animate({right: i});
            }

            return this;
        });
    }
})(jQuery);

