function init_inputs(idarrs){
	idarrs.each(
		function(el){
			el = $(el);
			if(!el) return;
			toggle_background.bind(el)();
			Event.observe(el, 'blur', toggle_background);
		}
	)
}

function toggle_background(event){
	el=this;
	if(el.nodeName != 'INPUT') return;
	if(el.value.empty()){
	    el.removeClassName('typed');
	}else{
	    el.addClassName('typed');
	}	
}

function show_loading(x, y){
	if(!$('loadimg')){
		img = new Element('img', {'src': '/images/loading.gif', 'style': 'position:fixed; z-index: 66', 'id': 'loadimg'});
		if(x) img.style.left = x-8+'px';
		if(y) img.style.top = y-8+'px';
		document.body.appendChild(img);
	}else{
		$('loadimg').style.display='block';
		if(x) img.style.left = x-8+'px';
		if(y) img.style.top = y-8+'px';
	}
	Event.observe(window, 'mousemove', move_img);
}

function move_img(e){
/*   	debug(e.clientX + ' ' + e.clientY); */
  	img = $('loadimg');
  	img.style.left = e.clientX - 8+'px';
  	img.style.top = e.clientY - 8 +'px';
}
function hide_loading(){
	Event.stopObserving(window, 'mousemove', move_img);
	$('loadimg').style.display='none';
}

function handle_search(){
	keywords = $F('search');
	if(keywords == '' || keywords == undefined){
		alert('please specify a search query');
		return false;
	}
	document.location = '/search/'+keywords;
	return false;
}


Event.observe(window, 'load',
	function(){
		init_inputs($A(['user', 'pass', 'search']));
	}
);
Event.observe(window, 'load',
	function(){
		setTimeout(function(){
			if($('notification')){
				new Effect.Fade('notification');
			}
		}, 8000);
	}
);