// JavaScript Document

function enhance(){ 
	/*Chance Navigation*/
	handleNavigation(nav_dont_colapse);
	handleNiceInputs();
}

function handleNavigation(nav_dont_colapse){
	var control = $('nav_footer').getElementsByTagName('span')[0];
	control.style.display = 'block';
	control.setAttribute('height_orig',$('nav').style.height);
	if (!nav_dont_colapse){
		$('nav').style.height = '23px';
		control.className='more';
		control.childNodes[0].data = 'more';
	}
	control.onclick = function(){
			if ($('nav').style.height == this.getAttribute('height_orig')){
				$('nav').style.height = '23px';
				this.className='more';
				this.childNodes[0].data = 'more';
			}else{
				$('nav').style.height = this.getAttribute('height_orig');
				this.className='less';
				this.childNodes[0].data = 'less';
			}
		};
}

function handleNiceInputs(){
	/* 
		Mike changed a bit. the elements now must have an extra attribute "prevalue" set to the desired text.
		Then, only if the field is blank does the prevalue text get set. Allows the search box to be prefilled with query
	*/
	
	var inputs = document.getElementsByTagName('input');
	for (n = 0; n <= (inputs.length -1); n++){
		if (Element.hasClassName(inputs[n],'handle_prevalue')){
			var prevalue = inputs[n].getAttribute('prevalue');
			
			if(inputs[n].value == ''){
				inputs[n].value = prevalue;
				inputs[n].addClassName('prevalue');
			}
			inputs[n].removeClassName('handle_prevalue');
			inputs[n].setAttribute('title',prevalue);
			
			if (inputs[n].getAttribute('type') == 'password'){
				var newinput = document.createElement('input');
				newinput.name = inputs[n].name;
				newinput.className = inputs[n].className;
				newinput.value = prevalue;
				newinput.title = inputs[n].title;
				newinput.oldnode = inputs[n].parentNode.replaceChild(newinput,inputs[n]);
				inputs[n].onclick = function(){
					if (this.value == this.getAttribute('title')){
						this.oldnode.removeClassName('prevalue');
						this.oldnode.value = '';
						var newnode = this.parentNode.replaceChild(this.oldnode,this);
						setTimeout(function(){newnode.oldnode.focus();},1);
					}
				};
				inputs[n].onfocus = inputs[n].onclick;
			}else{
				inputs[n].onclick = function(){
					if(this.value == this.getAttribute('title')){
						this.value = '';
						this.removeClassName('prevalue');
					}
				};
				inputs[n].onfocus = inputs[n].onclick;
				inputs[n].onblur = function(){
						if (this.value == ''){
							this.value = this.title;
							this.addClassName('prevalue');
						}
					};
			}
		}
	}
	
}

enhance();
