var Magix = Class.create();
Magix.prototype = 
{
	initialize: function(divId, url, width, height, query, inc)
	{
		this.div = $(divId);
		this.width = width;
		this.height = height;
		this.url = url;	
		this.query = query;
		this.reverse = false;
		if (inc < 0) this.reverse = true;
	},
	go: function()
	{
		this.createTempDiv();
		this.loadData();
	},
	createTempDiv: function()
	{
		this.temp = document.createElement('div');
		this.temp.style.width = this.width + 'px';
		this.temp.style.height = this.height + 'px';
		this.temp.style.position = 'absolute';
		this.temp.style.top = '0px';
		if (this.reverse) this.temp.style.left = '-' + this.width + 'px';
		else this.temp.style.left = this.width + 'px';
		this.temp.id = (new Date()).getTime();
		this.div.parentNode.appendChild(this.temp);
	},
	loadData: function()
	{
		var params = {asynchronous:true, onComplete: this.loaded.bind(this), evalScripts: true};
		if (this.query) params.parameters = this.query;
		new Ajax.Updater(this.temp.id, this.url, params);
	},
	loaded: function()
	{
		var toMove = -this.width;
		if (this.reverse) toMove = -toMove;
		new Effect.Parallel(
			[
				new Effect.MoveBy(this.temp.id, 0, toMove, { sync: true }), 
      			new Effect.MoveBy(this.div.id, 0, toMove, { sync: true })
      		],{ afterFinish: this.tidyUp.bind(this) });
	},
	tidyUp: function()
	{
		var id = this.div.id;
		Element.remove(this.div);
		this.temp.id = id;
		Element.hide('loader');
	}
}