function toggleSearchClass(state)
{
	if ((state == 'blur') && (document.getElementById('searchField').value == ''))
	{
		document.getElementById('searchField').className='';
		document.getElementById('searchField').value='  search';
	}
	
	else
	{
		if (document.getElementById('searchField').value == '  search')
		{
			document.getElementById('searchField').className='focused';
			document.getElementById('searchField').value='';
		}
	}
}

var gallery_current = null;
var gallery_nav_current = null;
var gallery_animating = false;

function wire_patient_gallery() {
	document.observe("dom:loaded", do_wire_patient_gallery);
}
function do_wire_patient_gallery() {
	var nav = $('patient_gallery_nav');
	var isfirst = true;
	$$('#patient_gallery div.item').each(function(elt, idx) {
		var li = new Element('li');
		var navlink = new Element('a').update(idx+1);
		Event.observe(navlink, 'click', function(clickelt) {
			if (switchTo(elt, clickelt)) {
				gallery_nav_current.removeClassName('current');
				clickelt.target.addClassName('current');
				gallery_nav_current = clickelt.target;
			}
		})
		li.appendChild(navlink);
		elt.setOpacity(0);
		elt.setStyle({'display':'block'});
		$('patient_gallery_nav').appendChild(li);
		
		if (isfirst) {
			navlink.addClassName('current');
			gallery_nav_current = navlink;
		}
		
		isfirst = false;
	});
	
	switchTo($$('#patient_gallery div.item').first());
}
function switchTo(elt, clickelt) {
	if (elt==gallery_current) {
		return false;
	}
	if (gallery_animating) {
		return false;
	}
	gallery_animating = true;
	
	if (gallery_current!=null) {
		gallery_current.fade();
	}
	
	new Effect.Appear(elt, {
		afterFinish : function() {
			gallery_animating = false;
		}
	})
	gallery_current = elt;
	return true;
}