/*****************************************************************************
 *
 * Element Animation Methods
 *
 * @file:  js/prototype/ext/element/element_animation_methods.js
 * @lang:  JS
 * @author:  Michael Conroy (mconroy@buffalo.edu)
 * @date:  26 Jun 2009
 * 
 * @description:  Extends Prototype elements with animation methods.
 *
 * @required:  js/prototype/prototype.js (The Prototype javascript library),
 * 	js/scriptaculous/effects.js (Scriptaculous javascript libraries)
 *
 ****************************************************************************/

Element.addMethods({
    
    /**
     * One Dimensional Move, moves the element in a single direction the prescribed amount,
     * either all at once or in an animated fashion.
     *
     * @param			direction			string, 'up','down','left','right'
     * 				amount			int, the amount of to move element
     * 				animate			boolean, animate the movement or not
     * @return			element
     */
    od_move: function(element,direction,amount,animate,callback){
	element = $(element);
	
	if(animate){ // animate the move of the element from current position the desired amount
	    var xMove = yMove = 0;
	    switch(direction){
	        case 'up':
			yMove = 0 - amount;
	        	break;
	        case 'down':
			yMove = amount;
			break;
	        case 'left':
			xMove = 0 - amount;
			break;
	        case 'right':
			xMove = amount;
			break;
	    }
	    if(callback != null){
		new Effect.Parallel([new Effect.Move(element,{x: xMove,y: yMove},{transition: Effect.Transitions.linear})],{afterFinish: callback});
	    }else{
		new Effect.Move(element,{x: xMove,y: yMove},{transition: Effect.Transitions.linear});
	    }
	}else{ // no animation of the movement, just move the element the desired amount
	    if((direction == 'left') || (direction == 'right')){ // get left style property
		var x = element.getStyle('left');
		x = parseInt(x.truncate(x.length - (x.length - 2)));
	    }else{// get top style property
	        var y = element.getStyle('top');
	        y = parseInt(y.truncate(y.length = (y.length -2)));
	    }
	    
	    switch(direction){
	        case 'up':
	        	element.setStyle({top: (y - amount) + 'px'});
	        	break;
	        case 'down':
			element.setStyle({top: (y + amount) + 'px'});
			break;
	        case 'left':
			element.setStyle({left: (x - amount) + 'px'});
			break;
	        case 'right':
			element.setStyle({left: (x + amount) + 'px'});
			break;
	    }
	    if(callback != null){
		callback;
	    }
	}
	
	return element;
    } // end move
    
}); // end Element.addMethods