/**
 *  jQuery Rotator Plugin
 *  @requires jQuery v1.2.6 or greater
 *  http://hernan.amiune.com/labs
 *
 *  Copyright (c)  Hernan Amiune (hernan.amiune.com)
 *  Licensed under MIT license:
 *  http://www.opensource.org/licenses/mit-license.php
 * 
 *  Version: 1.0
 */
 
(function ($) {
    $.fn.rotator = function (options) {

        var defaults = {
            ms: 7000
    };

    var options = $.extend(defaults, options);

    return this.each(function (index) {

        var $this = $(this);
        $this.width("2000px");
        $this.children(".bannerItem").height("248px");
        $this.children(".bannerItem").height("948px");
        function beginRotation() {
            $this.data("timer", setInterval(function () {

                $this.children().css("position", "absolute");
                var firstChild = $this.children().filter(":first-child");
                var nextChild = $this.children().filter(":nth-child(2)");
                var childwidth = firstChild.width();
                firstChild.show();
                nextChild.show();

                $this.children().not('::first-child').not(':nth-child(2)').hide();
                $this.children().filter(":nth-child(2)").css("left", (childwidth) + "px");
                var animParams = { "left": "-=" + childwidth + "px" };

                firstChild.animate(
                        animParams, { duration: 2000, specialEasing: { width: 'linear', height: 'easeOutBounce'} }).appendTo($this);

                nextChild.animate(
                        animParams, { duration: 2000, specialEasing: { width: 'linear', height: 'easeOutBounce'} });

            }, options.ms));

        }

        $this.mouseover(function () {
            clearTimeout($this.data("timer"));
        });

        $this.mouseout(function () {
            if ($this.children(".bannerItem").length > 1) {
                beginRotation();
            }
        });

        if ($this.children(".bannerItem").length > 1) {
            beginRotation();
        }



    });


}
})(jQuery);
