// Author: R. Pepe Lopez B.
// Date: 2.10.2009
// Version: 1.00
// Contact: js_hacks [-a-t-] freshsite.de
// License: MIT License
/*
 * Initialize:
 * var moover = new milkyMoove({
								div: "inner",
								divname2: "inner2",
								divleftarr: "leftarr",
								divrightarr: "rightarr",
								milkyMoove_move_step: 2
							});
 * 
 * 
 */
var milkyMoove = new Class({
	 Implements: [Options],
	
		//options
		  options: {
			milkyMoove_move_step: 1, //how much px in one step?
			
			div: "inner",		// id of inital DIV which contains pix
			leftLimit: 0,		// limite gauche de la zone
			rightLimit: -2200,		// limite droite de la zone
			hideArrows: "none",
			divleftarr: "leftarr",	// id of left arrow 
			divrightarr: "rightarr"	// id of right arrow
          },
		  
	  //variables - LEAVE AS IS!
		milkyMoove_move: 0,			//status - LEAVE AS IS HERE!
		milkyMoove_timer: '',
		  
	  //functions
	   initialize: function(options){
		// apply options
			this.setOptions(options);
		//styles des flèches
			if(this.options.hideArrows == 'right') {
				$('fasterRight').set('class', 'faster inactive');
				$('normalRight').set('class', 'normal inactive');
				$('slowerRight').set('class', 'slower inactive');
			} 
			if(this.options.hideArrows == 'left') {
				$('fasterLeft').set('class', 'faster inactive');
				$('normalLeft').set('class', 'normal inactive');
				$('slowerLeft').set('class', 'slower inactive');
			}
		//set events
			//if you want to "inverse" movement, switch left & right to each other!!
	  		$(this.options.divleftarr).addEvent('mouseenter', (function(){
			    this.scroll_mouse_over('left');
			}).bind(this));
			$(this.options.divrightarr).addEvent('mouseenter', (function(){
			    this.scroll_mouse_over('right');
			}).bind(this));
			$(this.options.divleftarr).addEvent('mouseleave', (function(){
			    this.scroll_mouse_out();
			}).bind(this));
			$(this.options.divrightarr).addEvent('mouseleave', (function(){
			    this.scroll_mouse_out();
			}).bind(this));
			//ajout des modificateurs de vitesse
	  		$$('.slower').addEvent('mouseenter', (function(){
			    this.scroll_mouse_over_speed = 0.5;
			}).bind(this));
	  		$$('.normal').addEvent('mouseenter', (function(){
			    this.scroll_mouse_over_speed = 1;
			}).bind(this));
	  		$$('.faster').addEvent('mouseenter', (function(){
			    this.scroll_mouse_over_speed = 5;
			}).bind(this));
		},
		//main move function
		arrow_styles: function() {
			var x_offset = $(this.options.div).getPosition();
			var parentEl = $(this.options.div).getParent('div');
			var parent = parentEl.get('id');
			var x_parent = $(parent).getPosition();
			var x = x_offset['x'] - x_parent['x'];
			//gauche
			if(x < this.options.leftLimit) {
				$('fasterLeft').set('class', 'faster');
				$('normalLeft').set('class', 'normal');
				$('slowerLeft').set('class', 'slower');
			} else {
				$('fasterLeft').set('class', 'faster inactive');
				$('normalLeft').set('class', 'normal inactive');
				$('slowerLeft').set('class', 'slower inactive');
			}
			//droite
			if(x > this.options.rightLimit) {
				$('fasterRight').set('class', 'faster');
				$('normalRight').set('class', 'normal');
				$('slowerRight').set('class', 'slower');
			} else {
				$('fasterRight').set('class', 'faster inactive');
				$('normalRight').set('class', 'normal inactive');
				$('slowerRight').set('class', 'slower inactive');
			}
		},
		
		scroll_move_it: function() {
				// getting element names...
				var el = $(this.options.div);
				
    			switch(this.milkyMoove_move)
				{
					case 1: //left arrow
						if((el.offsetLeft+(this.options.milkyMoove_move_step * this.scroll_mouse_over_speed)) <= this.options.leftLimit) {
							el.style.left = (el.offsetLeft+(this.options.milkyMoove_move_step * this.scroll_mouse_over_speed))+"px";
						} else {
							el.style.left = this.options.leftLimit+"px";
							this.milkyMoove_move = 0;
						}
						break;
					case -1:	//right arrow
						if((el.offsetLeft-(this.options.milkyMoove_move_step * this.scroll_mouse_over_speed)) >= this.options.rightLimit) {
							el.style.left = (el.offsetLeft-(this.options.milkyMoove_move_step * this.scroll_mouse_over_speed))+"px";
						} else {
							el.style.left = this.options.rightLimit+"px";
							this.milkyMoove_move = 0;
						}
						break;
				}
				
			},
			  	  
		scroll_mouse_over: function (name){
			var el = $(this.options.div);
			switch(name)
			{
				case 'right':
					this.milkyMoove_move=-1;
					break;
				case 'left':
					this.milkyMoove_move=1;
					break;
			}
			if(this.milkyMoove_move!=0)
			{
				//as long as mouseover, execute function!
				this.milkyMoove_timer = this.scroll_move_it.periodical(20, this);
			}
			this.milkyMoove_arrows = this.arrow_styles.periodical(20, this);
		}, 
  	  
		scroll_mouse_out: function(){
			var el = $(this.options.div);
			//stop movement
			this.milkyMoove_move = 0;
			$clear(this.milkyMoove_timer);
			$clear(this.milkyMoove_arrows);
		}
});