/*
*  jquery.rotator
*  Version: 0.1
*/

(function($) {
    var childWidth = 0;
    
    $.fn.rotator4 = function(options) {

        var defaults = {
            ms: 2000,
            n: 1,
            autoHeight: false
        };

        var options = $.extend(defaults, options);

        return this.each(function(index) {

            var $this = $(this);

            var initialHeight = 0;
            $this.children().filter(":lt(" + options.n + ")").each(function(index, item) {
                initialHeight += $(item).height();
            });

            $this.height(initialHeight);

            setInterval(function() {

                if ($this.context.style.zIndex != 233) {

                    var childHeight = $this.children().filter(":first-child").height();

                    if (childWidth == 0  && $this.children().filter(":first-child").width() != null)
                        childWidth = $this.children().filter(":first-child").width();
                    //window.status = childWidth ;
                    var animParams = { paddingRight: childWidth }; //var animParams = { marginTop: initialHeight }; //{ scrollTop: (childHeight) + "px" };
                    var autoHeight = 0;
                    $this.children().filter(":lt(" + (options.n + 1) + ")").each(function(index, item) {
                        if (index > 0) autoHeight += $(item).height();
                    });

                    if (options.autoHeight) animParams = $.extend({ height: (autoHeight) + "px" }, animParams);

                    $this.animate(animParams, 500, function() {
                        //$this.scrollTop(0);
                    $this.animate({ "paddingRight": 0 }, "slow"); //$this.animate({ "marginTop": 0 }, "slow"); //$this.scrollTop(0);
                        $this.append($this.children().filter(":first-child"));
                        $this.css("overflow", "hidden"); //Chrome hack
                    });
                }

            }, options.ms);


        });


    }
})(jQuery);


///*
// *  jquery.rotator
// *  Version: 0.1
// */
// 
//(function($){ $.fn.rotator4 = function(options){

//    var defaults = {
//		ms: 2000,
//		n: 1,
//		autoHeight: false
//	};
//  
//    var options = $.extend(defaults, options);
//	
//	return this.each(function(index) {
//		
//		var $this = $(this);
//		
//		var initialHeight = 0;
//		$this.children().filter(":lt("+options.n+")").each(function(index,item){
//		    initialHeight += $(item).height();
//		});
//		
//		$this.height(initialHeight);
//		
//		setInterval(function(){

//		if ($this.context.style.zIndex != 233) {		    
//		    
//			var childHeight = $this.children().filter(":first-child").height();
//			var childWidth = $this.children().filter(":first-child").width();
//			var animParams = { paddingRight: 0 }; //scrollTop : (childHeight) + "px" //width
//			var autoHeight = 0;
//		    $this.children().filter(":lt("+(options.n+1)+")").each(function(index,item){
//		        if(index>0)autoHeight += $(item).height();
//		    });
//			if(options.autoHeight)animParams = $.extend({height:(autoHeight) + "px"}, animParams);
//		
//			
//		    $this.animate(animParams, 500, function(){
//		        //$this.scrollTop(0);
//		        $this.animate({ "paddingRight": childWidth }, "slow"); //width
//			    $this.append($this.children().filter(":first-child"));
//				$this.css("overflow","hidden"); //Chrome hack
//		    });

//			}

//        }
//	    
//	    , options.ms);
//		

//	});

//  
//}})(jQuery);

