
function Random(X) {
   return Math.floor(X * (Math.random() % 1));
}

function Randum(X) {
   return X * (Math.random() % 1) | 0;
}

function RanSpan(MinV, MaxV) {
   return MinV + Random(MaxV - MinV + 1);
}


var Wind = {
		
	start: function() {

		/* Background Animations */


				if ($('cloud1')) { new Move('cloud1', { 'direction': 'right', 'speed': RanSpan(10000,50000), 'pause': RanSpan(5,50)  }); }
				if ($('cloud2')) { new Move('cloud2', { 'direction': 'left',  'speed': RanSpan(10000,30000), 'pause': RanSpan(25,45) }); }										                
				if ($('cloud3')) { new Move('cloud3', { 'direction': 'right', 'speed': RanSpan(30000,60000), 'pause': RanSpan(15,25) }); }
				if ($('rss')) 	 { new Move('rss',    { 'direction': 'left',  'speed': RanSpan(30000,60000), 'pause': RanSpan(20,65) }); }


	/* Include script */


	}
};

/* Add functions on window load */
window.addEvent('domready', Wind.start);


/* Move class */
var Move = new Class({
	
	initialize: function(element, options) {
		this.setOptions({
			direction: 'left',
			speed: 10000,
			pause: 5,
			duration: 1000,
			transition: Fx.Transitions.linear
		}, options);

		this.elm = $(element);
		this.key = 'yt-' + this.elm.getProperty('id');
		this.fx = new Fx.Styles(this.elm, this.options);
		this.timer = null;

		var val = Cookie.get(this.key);
		if (val) {
			this.elm.setStyle('left', val + 'px');
		}
		
		this.memorize.periodical(2500, this);
		this.animate();
	},

	animate: function() {
		var dir   = this.options.direction;
		var pause = this.options.pause;
		var coord = this.elm.getCoordinates();
		var dest  = (dir == 'left') ? 0 - coord.width : window.getWidth();
		var track = coord.left - dest;
		if (track < 0) { track = -track; }

		this.fx.setOptions({ 'duration': (this.options.speed * track / 1024).toInt() });
		this.fx.start({
			'left': (dir == 'left') ? 0 - coord.width : window.getWidth()
		}).chain(function() {
			this.elm.setStyles({
				'left': (dir == 'left') ? window.getWidth() : 0 - coord.width
			});
			$clear(this.timer);
			this.timer = this.animate.delay((Math.floor(Math.random() * pause) * 1000).limit(1000, (1000 * pause)), this);
		}.bind(this));
	},
	
	memorize: function() {
		var coord = this.elm.getCoordinates();
		Cookie.set(this.key, coord.left);
	}
	
});

Move.implement(new Options);
