/**
 * Class Rotating
 *
 * [2009-10-01 js] created
 *
 * $Rev: 480 $ Revision of last commit
 * $Author: jan $ Author of last commit
 * $Date: 2008-09-26 08:30:09 +0200 (Fr, 26 Sep 2008) $ Date of last commit
 */

var RotatingScene = function() {
	
	var 
	  // rotating speed
		speed = 1,
		
		// count for movement
		countMove = 0,
		
		// padding disappears after removing an 
		// element, so we add it
		margin = 8;	

		rotate = function() {
		
			// left direction
			if (speed > 0) {
			
				var teaserWidth = $("#rotator li:first").width();
				var teaserLeft = $("#rotator li:first").get(0).offsetLeft;
			
				if ( (teaserLeft + teaserWidth) <= -50) {
					
					// copy and add it to the end
					$("#rotator li:first").clone().insertAfter("#rotator li:last");
				
					// delete element when it's fully hidden
					$("#rotator li:first").remove();
					
					countMove += (teaserWidth + margin);
				}							
			}
			
			// right direction ( confusing < 0 .. but its funny :)
			if (speed < 0) {
			
				var teaserWidth = $("#rotator li:last").width();
				var teaserLeft = $("#rotator li:last").get(0).offsetLeft;
				
				if (teaserLeft >= 920) {
					
					// copy and add it to the beginnging
					$("#rotator li:last").clone().insertBefore("#rotator li:first");
					
					// delete element when it's fully hidden
					$("#rotator li:last").remove();
					
					countMove -= (teaserWidth + margin);
				}										
			}
						
			// base movement from all list elements 
			$("#rotator li").each(function() { 
												
				$(this).css("left", countMove);
			});		
					
			// generell count steps based on speed
			countMove -= speed;			
		}		
		
	return {		
	
		setSpeed: function(_speed) {
			
			speed = _speed;
		},
		increaseSpeed: function() {
						
			if ( speed <= 8) {
				speed++; 
			}
		},
		decreaseSpeed: function() {
			
			if ( speed >= -8 ) {
				speed--; 
			}
		},
		start: function(interval, s) {
						
			this.setSpeed(s);			
		  setInterval("rotate()", interval);
		}
	}
};
