/*
 MENU - Clubsational Frontend Menu
 (c) Timothy Anido 2006/2007
 version 2.1
 
this script displays and hides navigational submenus

 requires:
 - xoo.js
*/
var openjob, current;
var current_id, closing_id;
var animating;
var request = new ajax( 'receptionist/' );

request.cleanRequest = true;

function toggle( id ) {

	if( animating ) return;
	
	if( $( 'job-' + id ).open ) {
		$( 'job_body_' + id ).slide({'duration':.3, 'start':$( 'job_body_' + id ).extendedHeight, 'end': 0, 'property': 'height', 'onComplete': closed, 'easing': easing.easeIn });
		$( 'icon_' + id ).innerHTML = '<img src="img/icon_job.gif" width="16" height="22" alt="Icon: Club"/>'
		$( 'job-' + id ).className = 'job-container';
		animating = true;
	}
	
	if( ! $( 'job-' + id ).open ) {
	
		for (var i=0; i<trs.length; i++){
			if( trs[i].className == 'job-description' ){
				clid = trs[i].getAttribute( 'id' );
				if( $( 'job-' + clid ).open ){
					$( 'job_body_' + clid ).slide({'duration':.3, 'start':$( 'job_body_' + clid ).extendedHeight, 'end': 0, 'property': 'height', 'onComplete': closed, 'easing': easing.easeIn });
					$( 'icon_' + clid ).innerHTML = '<img src="img/icon_job.gif" width="16" height="22" alt="Icon: Club"/>'
					$( 'job-' + clid ).className = 'job-container';
				}
			}
		}
	
		request.sendRequest( 'recordjobhit/' + id );
		$( 'job_body_' + id ).style.display = 'block';
		$( 'job-' + id ).className = 'job-container-selected';
		$( 'job_body_' + id ).slide({'duration':.6, 'start':0, 'end': $( 'job_body_' + id ).extendedHeight, 'property': 'height', 'onComplete': function() { opened( id ); } });
		$( 'icon_'+id).innerHTML = '<img src="img/icon_job_open.png" width="16" height="22" alt="Icon: Club"/>';
		animating = true;
	}
	

}

function opened( id ) {
		$( 'job-' + id ).open = true;
		animating = false;
}

function closed( ) {
		$( 'job-' + this.el.jobid ).open = false;
		$( 'job_body_' + this.el.jobid ).style.display = 'none';
		animating = false;
}

window.addEvent( 'domready', function() {

	if (!document.getElementsByTagName){ return; }
	trs = document.getElementsByTagName('tr');
	for (var i=0; i<trs.length; i++){
		if( trs[i].className == 'job-description' ){
			id = trs[i].getAttribute( 'id' );
			trs[i].style.height = 'auto';
			$('job_body_'+id).style.height = 'auto';
			$('job_body_'+id).extendedHeight = trs[i].offsetHeight;
			$('job_body_'+id).jobid = id;
			$('job_body_'+id).style.height = '0';
			$('job_body_'+id).style.display = 'none';
		}
	}
});
