/*	remoteHover v1.0                        
	an unobtrusive remote element controller            
	by Tim Novinger | http://www.timnovinger.com/ | tim.novinger [at] gmail [dot] com    
	
	MIT style license:                                             
	http://en.wikipedia.org/wiki/MIT_License      	
			
	Special Thanks To:
	- JanK_ for helping with the Y offset issues
	
	Change Log:
	   Version 1.0 (September 4th, 2007)								  
	      - Initial build											  
																  
	Supported browsers at time of last update:					  
	  - Firefox 2.0.0.6							
	  - Safari 3.03 [win] & [osx]
	  - Opera 9.10
	  - Internet Explorer 7										  
	  - Internet Explorer 6 w/SP2								  
																  
	Planned Improvments			 	
	  - options to move elements left/right or up/down
*/
// ===================================================================================================================================
// SCRIPT CONFIGURATION
	var _EVENT_START = "mousedown"; 					//event type that triggers the start
	var _EVENT_FINISH = "mouseup"; 						//event type the triggers completion
	var _WAIT = true;									//wait for previous event to finish before starting next event?
	var _DO_TRANSITION = false;							//if value is true the following transition will be used
	var _TRANSITION = Fx.Transitions.Back.easeInOut;	    /*type of transition to do:
															linear	 displays a linear transition.
															Quad	 displays a quadratic transition.
															Cubic	 displays a cubicular transition.
															Quart	 displays a quartetic transition.
															Quint	 displays a quintic transition.
															Pow	 	 Used to generate Quad, Cubic, Quart and Quint.
															Expo	 displays a exponential transition.
															Circ	 displays a circular transition.
															Sine	 displays a sineousidal transition.
															Back	 makes the transition go back, then all forth.
															Bounce	 makes the transition bouncy.
															Elastic	 Elastic curve.
															
														 view demos of transitions here: http://demos.mootools.net/Fx.Transitions
														*/
															
	//ALL TIMES ARE IN MILLISECONDS (1000 = 1sec) LESS IS FASTER
	var _SPEED = 300; 					    			//speed of the movement effect (default = 500ms)
	
	//OFFSET DIRECTION(s) [negative EQ down, positive EQ up]
	var _X = 0; 										//left-right, measured in pixels
	var _Y = 0; 										//up-down, measured in pixels
	
	//LINK COLORS
	var _DO_LINK_COLORS = false;						//change link colors?
	var _bColor = '#666666';							//color for previously selected link
	var _hColor = '#999999';							//color for currently selected link
// ===================================================================================================================================
var remoteHover = {					 
	initialize: function(options){
		this.options = Object.extend({
			eventStart: 	_EVENT_START,
			eventFinish: 	_EVENT_FINISH,
			wait:			_WAIT,
			doTransition:   _DO_TRANSITION,
			transition:     _TRANSITION,
			speed: 			_SPEED,
			x:				_X,
			y:				_Y,
			doLinkColors:	_DO_LINK_COLORS,
			bColor:			_bColor,
			hColor:			_hColor
		}, options || {});
		
		//CHECK FOR RH_CONTENT, ELSE QUIT
		if(!$('rh_content') || !$('rh_p1') || !$('rh_links')) {return;}
		
		//DECLARE EFFECTS
		if(this.options.doTransition){
			this.scroll = new Fx.Scroll('rh_content', {
				wait: this.options.wait,
				duration: this.options.speed,
				offset: {'x': this.options.x, 'y': this.options.y},
				transition: this.options.transition
			});
		} else {
			this.scroll = new Fx.Scroll('rh_content', {
				wait: this.options.wait,
				duration: this.options.speed,
				offset: {'x': this.options.x, 'y': this.options.y}
			}); 
		}
		
		//SET & RESTORE DEFAULTS
		this.linkArray = $$("#rh_links .link");
		this.scroll.toElement('rh_p1');
		if(this.options.doLinkColors == true){
			this.linkArray.each(function(e, i){
				var curStyle = e.getStyle('color');
				if(curStyle == remoteHover.options.hColor){
					remoteHover.prev = e;	
				}
			});
		}
				
		//ADD EVENTS TO EACH LINK
		this.linkArray.each(function(e, i){
			e.addEvent(remoteHover.options.eventStart, remoteHover.start.pass([e, i], remoteHover));
			e.addEvent(remoteHover.options.eventFinish, remoteHover.finish.pass([e], remoteHover));
	    });
	},
	
	start: function(e, i){
			i++;  //forces i to count from 1 instead of 0
			this.scroll.toElement('rh_p' + i);
			
			if(this.options.doLinkColors == true){
				if(this.prev != undefined){
					$(this.prev).setStyle('color', this.options.bColor);
				}
				e.setStyle('color', this.options.hColor);
			}
	},
	
	finish: function(e){
		this.prev = e; //set previous link
	}
};
// ===================================================================================================================================
// START SCRIPT ON DOMREADY
window.addEvent('domready', remoteHover.initialize.bind(remoteHover));