var Loader = new Class({
	initialize: function(images,ltarg,width,height) {
		this.lOver = 'dLoaderOver';
		this.lProg = 'dLoaderProgress';
		this.lProgImg = 'dLoaderProgImg';
		this.lText = 'dLoaderText';
		this.lTarg = ltarg;
		this.lCount = 0;
		this.lInt = 0;
		this.lCur = 0;
		this.dImages = [];
		this.lImages = images;
		this.fx = new Fx.Tween(this.lProgImg,{duration: 500,wait: false,unit: 'px'});
		this.dfx = [];
		this.rot = '';
		$(this.lTarg).setStyles({
			'height': height+'px',
			'width': width+'px'
		});
		
		this.preload();
	},
	preload: function() {
		$(this.lOver).setStyle('display','block');
		var that = this;
		this.dImages = new Asset.images(this.lImages,{
			onProgress: function() {
				that.prog();
			},
			onComplete: function() {
				that.start();
			}
		},this).setStyles({
			'opacity':0,
			'-moz-opacity':0,
			'filter': 'alpha(opacity=0)',
			'position': 'absolute',
			'z-index': 1
		}).injectInside(this.lTarg);
	},
	prog: function() {
		this.dfx[this.lInt] = new Fx.Tween(this.dImages[this.lInt],{duration: 1500});
		this.lInt++;
		var perc = (this.lInt / this.lImages.length).toFloat(2);
		var marg = (-150 + (perc * 150));
		$(this.lText).set('html',Math.round(((perc * 100) * 100) / 100)+'%');
		this.fx.start('margin-left',marg);
	},
	start: function() {
		$(this.lOver).setStyle('display','none');
		this.dfx[this.lCur].start('opacity',[0,1]);
		this.rot = this.rotate.periodical(5000,this);
	},
	rotate: function() {
		this.dfx[this.lCur].start('opacity',[1,0]);
		this.lCur = (this.lCur < (this.dImages.length - 1)) ? (this.lCur + 1) : 0;
		this.dfx[this.lCur].start('opacity',[0,1]);
	},
	stop: function() {
		$clear(this.rot);
	}
});


//width 44px
//height 29px
var clientGall = new Class({
	initialize: function(images,ltarg,width,height) {
		this.lOver = 'dLoaderOver';
		this.lProg = 'dLoaderProgress';
		this.lProgImg = 'dLoaderProgImg';
		this.lText = 'dLoaderText';
		this.lTarg = ltarg;
		this.lCount = 0;
		this.lInt = 0;
		this.lCur = 0;
		this.dImages = [];
		this.lImages = images;
		this.fx = new Fx.Tween(this.lProgImg,{duration: 500,wait: false,unit: 'px'});
		this.dfx = [];
		this.rot = '';
		
		this.prev = new Asset.image('/img/minus.gif').injectInside('dControls');
		this.prev.setStyles({'float':'left','opacity':.5});
		this.next = new Asset.image('/img/plus.gif').injectInside('dControls');
		this.next.setStyle('float','left');
		this.stop = new Asset.image('/img/stop.gif').injectInside('dControls');
		this.stop.setStyles({'float':'right','opacity':.5});
		this.pause = new Asset.image('/img/pause.gif').injectInside('dControls');
		this.pause.setStyles({'float':'right','opacity':.5});
		this.play = new Asset.image('/img/play.gif').injectInside('dControls');
		this.play.setStyle('float','right');
		
		$(this.lTarg).setStyles({'height': height+'px','width': width+'px'});
		
		this.preload();
	},
	preload: function() {
		$(this.lOver).setStyle('display','block');
		var that = this;
		this.dImages = new Asset.images(this.lImages,{
			onProgress: function() {
				that.prog();
				that.thumb(this);
			},
			onComplete: function() {
				//that.start();
			}
		}).setStyles({
			'opacity':0,
			'-moz-opacity':0,
			'filter': 'alpha(opacity=0)',
			'position': 'absolute',
			'z-index': 1
		}).injectInside(this.lTarg);
	},
	prog: function() {
		this.dfx[this.lInt] = new Fx.Tween(this.dImages[this.lInt],{duration: 1500});
		this.lInt++;
		var perc = (this.lInt / this.lImages.length).toFloat(2);
		var marg = (-150 + (perc * 150));
		$(this.lText).set('html',Math.round(((perc * 100) * 100) / 100)+'%');
		this.fx.start('margin-left',marg);
	},
	start: function() {
		$(this.lOver).setStyle('display','none');
		this.dfx[this.lCur].start('opacity',[0,1]);
		this.rot = this.rotate.periodical(5000,this);
	},
	rotate: function() {
		this.dfx[this.lCur].start('opacity',[1,0]);
		this.lCur = (this.lCur < (this.dImages.length - 1)) ? (this.lCur + 1) : 0;
		this.dfx[this.lCur].start('opacity',[0,1]);
	},
	stop: function() {
		$clear(this.rot);
	},
	thumb: function(img) {
		new Ajax(img.src)
	}
});
