//<--
/*

	@author: SWAT (Rostovtsev Ruslan)
	@url: http://www.jsysteam.ru
	@version: 1.0.0

*/



var sGallery = new Class({
						
	initialize: function(el) {
        
		try {
			
			this.node = $(el);
			this.left = this.node.getElement('.left');
			this.right = this.node.getElement('.right');
			this.imagesNode = this.node.getElement('.images');
			this.images = this.imagesNode.getElements('img');
			this.scrollFx = new Fx.Scroll(this.imagesNode, {duration: 1000, wait: false, transition: Fx.Transitions.Quad.easeInOut});
			
			//this.step = this.images[0].getStyle('width').toInt() + 24;
			this.maxStep = this.images.length-3;//(this.images.length-5) * this.step;
			this.pos = {l: 0, t: 0};
			
			this._reset();
/*
			this.images.each(function(item, index) {
									  
									 item.addEvent('click', function(event) {
											 
											 event.stop(); 
									 }); 
							});
*/			
			
			this.left.addEvent('click', function(event) {
											 
						 event.stop(); 
						 this.sLeft();
		   }.bind(this)); 
			
			this.right.addEvent('click', function(event) {
											 
						 event.stop(); 
						 this.sRight();
			}.bind(this)); 
			
		
		} catch (E) {
			alert(E);
		}
    },
	
	start: function() {
		//this.scrollFx.start(this.pos.l, this.pos.t);
		this.scrollFx.toElement(this.images[this.pos.l]);
		this.update();
	},
	
	update: function() {
		
		if(this.pos.l >= this.maxStep) {
			
			this.right.addClass('.right_disabled');
			
		} else {
			
			if(this.right.hasClass('.right_disabled')) this.right.removeClass('.right_disabled');	
		}
		
		
		if(this.pos.l <= 0) {
			
			this.right.addClass('.left_disabled');
			
		} else {
			
			if(this.right.hasClass('.left_disabled')) this.right.removeClass('.left_disabled');	
		}
		
		
	},

	sRight: function() {
		
		if(this.pos.l < this.maxStep) {
			
			//this.pos.l += this.step;
			if((this.pos.l + 1) < this.images.length - 4) {
				this.pos.l++;
				this.start();
			}
		} 
	},
	
	sLeft: function() {
		
		if(this.pos.l > 0) {
			
			//this.pos.l -= this.step;
			this.pos.l--;
			this.start();
		} 
	},
	
	_reset: function() {
		
		this.pos.l = 0;
		this.pos.t = 0;
		this.start();
	}
	
});




window.addEvent('domready',  function() {   

    try {

		if($chk($(document.body).getElement('.listClients'))) {
			new sGallery($(document.body).getElement('.listClients'));
		}
		
	} catch(E) {
		alert(E);
	}
}); 




function selectRegion(r) {
	
	if($chk($('reg_' + r))) {
		$('reg_' + r).selected = true;
		$('sel_region').highlight('#f00');
		$('exp_form').submit();
	}
}




//-->