// set up shortcuts for YAHOO utils
var $Y = YAHOO.util;
var $E = $Y.Event;
var $D = $Y.Dom;
var $ = $D.get;
//var $$ = cssQuery;
YAHOO.namespace('ap');
var ap = YAHOO.ap;
			
ap.doTools = function(){
	if(parseInt($D.getStyle(this,'height'))<=1){
		var attributes = { 
			height : {from: 0, to: this.defaultHeight}
		   };
		var me = this;
		anim = new $Y.Anim(me, attributes,0.2,$Y.Easing.easeOut);	
		anim.onStart.subscribe(function(){me.style.visibility = 'visible';});
		anim.onComplete.subscribe(function(){
			$('q').focus();
			var myAnim = new $Y.ColorAnim($('q'), { backgroundColor: { from: '#ffffff', to: '#380d0d' } }, 1, $Y.Easing.easeOut);
			myAnim.animate();
			});
		anim.animate();
	} else {
		var attributes = { 
			height : {from: this.defaultHeight, to: 0}
		   };
		var me = this;
		anim = new $Y.Anim(this, attributes,0.4,$Y.Easing.easeIn);
		anim.onComplete.subscribe(function(){me.style.visibility = 'hidden';});
		anim.animate();
	}
}

ap.init = function(){
	// start set up tools
	/* 
	To avoid an unwanted 'jump' when we load the page we start with the 'tools'
	<div> at the bottom of the page	and then move it (by cloning and deleting) 
	to the top of the page. Also, note that we are setting display:block 
	before we measure the initial height (used to animate the <div> into 
	its 'open' position). This is necessary since a <div> with 
	display:none has no height.
	*/
	$('tools').style.visibility = 'hidden';
	$('tools').style.display = 'block';	
	$('tools').defaultHeight = $('tools').offsetHeight;	
	var tmp = $('tools').cloneNode(true);
	tmp.defaultHeight = $('tools').defaultHeight;
	var p = $('tools').parentNode;
	p.removeChild($('tools'));
	p.insertBefore(tmp,p.firstChild);
	$D.setStyle(p.firstChild,'height','0');
	$E.on($('nav-tools'),'click',ap.doTools,p.firstChild,true);	
	// end set up tools
	var txts = $D.getElementsByClassName('txt');
	$E.on(txts,'focus',function(e){var targ = $E.getTarget(e);$D.addClass(targ,'glow');});
	$E.on(txts,'blur',function(e){var targ = $E.getTarget(e);$D.removeClass(targ,'glow');});
}
$E.on(window,'load',ap.init);
