//—Copyright (c) 2007 wollzelle GmbH, (http://www.wollzelle.com). All Rights Reserved.

var Spinner = Class.create();
Spinner.prototype = {
	initialize: function(element, frames) {
		this.spinner 		= $(element).down();
		this.step 			= $(element).getWidth();
		this.spinning   = false;
		this.frames     = frames-1;
		
		if(Prototype.Browser.IE) {
		  //this.spinner.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+this.spinner.src+"',sizingMethod='scale')";
		  //this.spinner.src = '/images/empty.gif';
		}
		this.start();
	},
	start: function() {
	  if(this.spinning) return;
		var i = this.frames, nextPosition;
		this.pe = new PeriodicalExecuter(function() {
			i = (i==this.frames ? 0 : ++i);
			nextPosition = -this.step*i;	
			this.spinner.setStyle({marginLeft: nextPosition+'px'});
		}.bind(this), 0.1);
		this.spinning = true;
	},
	stop: function() {
		this.pe.stop();
		this.spinning = false;
	}
}