/* headerSlide - 2010 03 03 */
/* @ Wesley (NovaRage) */
var headerSlide = new Class({
	Implements: [Options],
	
	options: {
		fps: 100,
		step: 560,
		duration: 900,
		transition: 'sine:in:out'
	},
	
	el: { mainBlok: {},links: {},rechts: {},moveBlok: {} },
	
	initialize: function(mainBlok,options){
		this.setOptions(options);
		
		this.el.mainBlok = mainBlok;
		
		this.setFields();
		this.options.maxMargin = toInt('-'+($$('#imgMoveBlok img').length-1)*this.options.step);
	},
	
	keyPress: function(evt){
		switch(evt.key){
			case 'right': this.setHeaderMargin(true);break;
			case 'left':  this.setHeaderMargin(false);break;}
	},
	
	wheel: function(evt){			
		this.setHeaderMargin((evt.wheel <0));
		return false;
	},	
	
	setFields: function(){
		
		document.addEvent('keydown',this.keyPress.bind(this));
		this.el.mainBlok.addEvent('DOMMouseScroll',this.wheel.bind(this));
		this.el.mainBlok.addEvent('mousewheel',this.wheel.bind(this));
		
		this.el.moveBlok = this.el.mainBlok.getElement('#imgMoveBlok').set({
			tween: {
				fps: this.options.fps,
				link: 'ignore',
				duration: this.options.duration,
				transition: this.options.transition}
		});
		
		this.el.links = this.el.mainBlok.getElement('.links').set({
			tween: {
				fps: this.options.fps,
				link: 'cancel',
				duration: this.options.duration,
				transition: this.options.transition
			},
			events: {
				click: this.setHeaderMargin.bind(this,false)}
		});
		
		this.el.rechts = this.el.mainBlok.getElement('.rechts').set({
			events: {
				click: this.setHeaderMargin.bind(this,true)}
		});
		
		this.el.links.tween('opacity',0);
		this.el.rechts.tween('opacity',0);
		
		this.el.mainBlok.set({
			events: {
				mouseover: function(){
					this.el.rechts.tween('opacity',1);
					this.el.links.tween('opacity',1);
				}.bind(this),
				mouseout: function(){
					this.el.links.tween('opacity',0);
					this.el.rechts.tween('opacity',0);
				}.bind(this)
			}
		});
	},
	
	setHeaderMargin: function(boolGoRight){			
		var curMargin = this.el.moveBlok.getStyle('marginLeft');
		curMargin = toInt(curMargin.toString().replace(['-','px'],''));
		
		if(curMargin%this.options.step != 0)
			return;
		
		if(boolGoRight)
			nextMargin = curMargin - this.options.step;
		else
			nextMargin = curMargin + this.options.step;
		
		if(nextMargin <=0 && nextMargin>=this.options.maxMargin){
			this.chkDisabled(nextMargin);
			this.el.moveBlok.tween('marginLeft',nextMargin+'px');
		}
	},
	
	chkDisabled: function(nextMargin){
		if(nextMargin<0) {
			this.el.links.setStyle('display','block');
			
			if(nextMargin == this.options.maxMargin)
				this.el.rechts.setStyle('display','none');
			else 
				this.el.rechts.setStyle('display','block');
		} else {
			this.el.links.setStyle('display','none');
			this.el.rechts.setStyle('display','block');
		}
	}
});
