function stSlider(settings) {
     this.construct(settings);
}

stSlider.prototype = {
    construct: function(settings) {
        this.moveBlocks = settings.moveBlocks;
        this.startBlock = settings.startBlock;

        this.widthBlock = settings.widthBlock;
        this.parentBlock = settings.parentBlock;
        this.elementType = settings.elementType;
        this.elementClass = settings.elementClass;
        this.blocksLength = this.moveBlocks.length;
        this.selfHeight = $((this.moveBlocks).get(this.startBlock)).height();

        this.parentBlock.css({
            "height": this.selfHeight + "px"
        });

        $((this.moveBlocks).get(this.startBlock)).css({
            "left": 0,
            "top": 0
        });

        for (i = this.startBlock - 1; i >= 0; i--) {
            $((this.moveBlocks).get(i)).css({
                "left": this.widthBlock * (i - this.startBlock) + "px",
                "top": 0
            });
        }

        for (i = this.startBlock + 1; i < this.blocksLength; i++) {
            $((this.moveBlocks).get(i)).css({
                "left": this.widthBlock * (i - this.startBlock) + "px",
                "top": 0
            });
        }
    },

    nextSlide: function() {
        var parentPageBlock = this.parentBlock;
        var blocksLength = this.blocksLength;
        var moveBlocks = this.moveBlocks;
        var widthBlock = this.widthBlock;
        var startBlock = this.startBlock;
        var selfHeight = this.selfHeight;
        var elementType = this.elementType;
        var elementClass = this.elementClass;

        var nextHeight;
 
        if ( (parseInt(moveBlocks.filter(":animated").length) == 0) &&
             (parseInt(parentPageBlock.filter(":animated").length) == 0) ) {
            
            selfHeight = $((moveBlocks).get(startBlock)).height();
            $(elementType + "[rel='new']").remove();
            if (startBlock + 1 < blocksLength) {
                startBlock = startBlock + 1;
                nextHeight = $((moveBlocks).get(startBlock)).height();
              
                if ( nextHeight > selfHeight ) {
                    
                    parentPageBlock.stop(true).animate({
                        "height": nextHeight + "px"
                    }, function() {
                
                        for (i = 0; i < blocksLength; i++) {
                            $((moveBlocks).get(i)).animate({
                                "left": widthBlock * (i - startBlock) + "px"
                            });
                        }
                    });
                }
                else {

                    for (i = 0; i < blocksLength; i++) {

                        $((moveBlocks).get(i)).animate({
                            "left": widthBlock * (i - startBlock) + "px"
                        }, function() {
                            parentPageBlock.stop(true).animate({
                                "height": nextHeight + "px"
                            });
                        });
                    }
                }

            }
            else {
                var copy = $((moveBlocks).get(blocksLength - 1)).html();
                startBlock = 0;
                nextHeight = $((moveBlocks).get(0)).height();

                if ( nextHeight > selfHeight ) {
                    parentPageBlock.stop(true).animate({
                        "height": nextHeight + "px"
                    }, function() {
                        parentPageBlock.append("<" + elementType + " class=\"" + elementClass +"\" rel=\"new\">" + copy + "</" + elementType + ">");
                        for (i = 0; i < blocksLength; i++) {
                            $((moveBlocks).get(i)).css({
                                "left": widthBlock * (i + 1)  + "px"
                            });

                            $((moveBlocks).get(i)).animate({
                                "left": widthBlock * (i) + "px"
                            });
                        }
                        $(elementType + "[rel='new']").animate({
                            "left": widthBlock * (-1) + "px"
                        });
                    });
                }
                else {
                    parentPageBlock.append("<" + elementType + " class=\"" + elementClass +"\" rel=\"new\">" + copy + "</" + elementType + ">");
                    for (i = 0; i < blocksLength; i++) {
                        $((moveBlocks).get(i)).css({
                            "left": widthBlock * (i + 1)  + "px"
                        });

                        $((moveBlocks).get(i)).animate({
                            "left": widthBlock * (i) + "px"
                        }, function() {
                            parentPageBlock.stop(true).animate({
                                "height": nextHeight + "px"
                            });
                        });
                    }
                    $(elementType + "[rel='new']").animate({
                        "left": widthBlock * (-1) + "px"
                    });
                }
            }
        }
     /*   parentPageBlock.css({"top": 0, "margin-top": 0, "padding-top": 0});
        moveBlocks.each(function (i) { 
          $(this).css({"top": 0});
          $(this).css({"margin-top": 0});
          $(this).css({"padding-top": 0});
        });*/

        this.parentBlock = parentPageBlock;
        this.blocksLength = blocksLength;
        this.moveBlocks = moveBlocks;
        this.widthBlock = widthBlock;
        this.startBlock = startBlock;
        this.selfHeight = selfHeight;
    },

    prevSlide: function() {
        var parentPageBlock = this.parentBlock;
        var blocksLength = this.blocksLength;
        var moveBlocks = this.moveBlocks;
        var widthBlock = this.widthBlock;
        var startBlock = this.startBlock;
        var selfHeight = this.selfHeight;
        var elementType = this.elementType;
        var elementClass = this.elementClass;

        var prevHeight;

        if ( (parseInt(moveBlocks.filter(":animated").length) == 0) &&
             (parseInt(parentPageBlock.filter(":animated").length) == 0) ) {

            selfHeight = $((moveBlocks).get(startBlock)).height();
            $(elementType + "[rel='new']").remove();

            if (startBlock > 0) {
                startBlock = startBlock - 1;

                prevHeight = $((moveBlocks).get(startBlock)).height();

                if ( prevHeight > selfHeight ) {

                    parentPageBlock.stop(true).animate({
                        "height": prevHeight + "px"
                    }, function(){
                        for (i = 0; i < blocksLength; i++) {
                            $((moveBlocks).get(i)).animate({
                                "left": widthBlock * (i - startBlock) + "px"
                            });
                        }
                    });
                }
                else {

                    for (i = 0; i < blocksLength; i++) {

                        $((moveBlocks).get(i)).animate({
                            "left": widthBlock * (i - startBlock) + "px"
                        }, function(){
                            parentPageBlock.stop(true).animate({
                                "height": prevHeight + "px"
                            });
                        });
                    }
                }
            }
            else {
                var copy = $((moveBlocks).get(0)).html();
                startBlock = blocksLength - 1;
                prevHeight = $((moveBlocks).get(startBlock)).height();

                if ( prevHeight > selfHeight ) {
                    parentPageBlock.stop(true).animate({
                        "height": prevHeight + "px"
                    }, function() {
                        parentPageBlock.prepend("<" + elementType + " class=\"" + elementClass +"\" rel=\"new\">" + copy + "</" + elementType + ">");
                        for (i = 0; i < blocksLength; i++) {
                            $((moveBlocks).get(i)).css({
                                "left": widthBlock * (i - startBlock - 1) + "px"
                            });

                            $((moveBlocks).get(i)).animate({
                                "left": widthBlock * (i - startBlock) + "px"
                            });
                        }
                        $(elementType + "[rel='new']").animate({
                            "left": widthBlock * (1) + "px"
                        });
                    });
                }
                else {
                    parentPageBlock.prepend("<" + elementType + " class=\"" + elementClass +"\" rel=\"new\">" + copy + "</" + elementType + ">");
                    for (i = 0; i < blocksLength; i++) {
                        $((moveBlocks).get(i)).css({
                            "left": widthBlock * (i - startBlock - 1) + "px"
                        });

                        $((moveBlocks).get(i)).animate({
                            "left": widthBlock * (i - startBlock) + "px"
                        }, function() {
                            parentPageBlock.stop(true).animate({
                                "height": prevHeight + "px"
                            });
                        });
                    }
                    $(elementType + "[rel='new']").animate({
                        "left": widthBlock * (1) + "px"
                    });
                }
            }
  
        }
      /*  parentPageBlock.css({"top": 0, "margin-top": 0, "padding-top": 0});
        parentPageBlock.parent().css({"top": 0, "margin-top": 0, "padding-top": 0});
        moveBlocks.each(function (i) { 
          $(this).css({"top": 0});
          $(this).css({"margin-top": 0});
          $(this).css({"padding-top": 0});
        });        */
        
        this.parentBlock = parentPageBlock;
        this.blocksLength = blocksLength;
        this.moveBlocks = moveBlocks;
        this.widthBlock = widthBlock;
        this.startBlock = startBlock;
        this.selfHeight = selfHeight;
    },

    slideTo: function( newNumber ) {
        var parentPageBlock = this.parentBlock;
        var blocksLength = this.blocksLength;
        var moveBlocks = this.moveBlocks;
        var widthBlock = this.widthBlock;
        var startBlock = this.startBlock;
        var selfHeight = this.selfHeight;
        var elementType = this.elementType;

        if ( (parseInt(moveBlocks.filter(":animated").length) == 0) &&
             (parseInt(parentPageBlock.filter(":animated").length) == 0) ) {

            $(elementType + "[rel='new']").remove();

            if (newNumber != startBlock) {

                startBlock = newNumber;
                selfHeight = $((moveBlocks).get(startBlock)).height();
                var maxHeight = $((moveBlocks).get(0)).height();
                var sHeight;

                for (i = 1; i < blocksLength; i++) {
                    sHeight = $((moveBlocks).get(i)).height();
                    if ( sHeight > maxHeight ) {
                        maxHeight = sHeight;
                    }
                }

                parentPageBlock.stop(true).animate({
                    "height": maxHeight + "px"
                    }, function() {
                    for (i = 0; i < blocksLength; i++) {
                        $((moveBlocks).get(i)).animate({
                            "left": widthBlock * (i - startBlock) + "px"
                            }, function() {
                            parentPageBlock.stop(true).animate({
                                "height": selfHeight + "px"
                                });
                        });
                    }
                });
            }
        }

        this.parentBlock = parentPageBlock;
        this.blocksLength = blocksLength;
        this.moveBlocks = moveBlocks;
        this.widthBlock = widthBlock;
        this.startBlock = startBlock;
        this.selfHeight = selfHeight;
    }
}
