(function(){
	
	var Dom = YAHOO.util.Dom;
	var Event = YAHOO.util.Event;
	var Lang = YAHOO.lang;
	var ColorAnim = YAHOO.util.ColorAnim;
	var Anim = YAHOO.util.Anim;


	function getAncestorBackgroundColor(element){
		var color = "transparent";
		var nextElement = element;

		while(nextElement.nodeName && color === "transparent"){
			var currentElement = nextElement;
			
			color = Dom.getStyle(currentElement, 'background-color');
			
			var nextElement = currentElement.parentNode;
		}

		if(color === "transparent"){
			return "#FFFFFF";
		}else{
			return color;
		}
	}

	LIGHTHOUSE.animation = {
		spotlight : function(){
			
			var LIGHT_YELLOW = "#fdffbb";
			var DURATION = .75;

			return function(element, onComplete){
				if(!onComplete){
					onComplete = function(){};
				}
				var currentBackground = getAncestorBackgroundColor(element);
				var attributes = {
					backgroundColor:{to : LIGHT_YELLOW,
									 from : currentBackground}
				};
				var spotlightAnimationInstance = new ColorAnim(element, attributes, DURATION);
				spotlightAnimationInstance.onComplete.subscribe(function(){
					
					var toColor = this.attributes.backgroundColor.to;
					this.attributes.backgroundColor.to = this.attributes.backgroundColor.from;
					this.attributes.backgroundColor.from = toColor;

					this.onComplete.unsubscribe();
					this.onComplete.subscribe(function(){
						onComplete();
					});
					this.animate();
				});
				spotlightAnimationInstance.animate();
			}
			
		}(),
		collapse : function(){
			
			var DURATION = .3;

			return function(element, onComplete){
				if(!onComplete){
					onComplete = function(){};
				}
				var attributes = { height: {to: 0},
								   opacity: {to: 0} };
				
				Dom.setStyle(element, 'overflow', 'hidden'); // blind the element
				
				var collapseAnimationInstance = new Anim(element, attributes, DURATION);
				collapseAnimationInstance.onComplete.subscribe(function(){
					
					onComplete();
					if(element){
						// A better solution would be to set overflow, height, and opacity to null... but IE dosen't like that
						// so instead, we'll use cssText
						element.style.cssText = ''; // IE hack, setting the opacity to '' does not
													// remove the inline styling, this does though
					}
					
				});
				
				collapseAnimationInstance.animate();

			}
		}()
	}
})(); 
