/**
 * ui.js -> http://actOral.org/
 * actOral.* user interaction
 * (cc) creative commons by 3.0
 */
 
 
 
 
function popup( elem ) {
	
	// images
	if ( elem.src!=null ) {
		window.open(
			"/php/popup.php?src="+elem.src+"&alt="+elem.alt,
			'puwin',
			'toolbar=0,location=0,directories=0,resizable=0,menubar=0,status=0,scrollbars=0'
		);
	}
	// map
	else {
		
		var w = 640;
		var h = 480;
		var l = ( screen.availWidth-w )/2;
		var t =	100;

		window.open(
			"/php/popup.php?"+elem,
			'puwin',
			'toolbar=0,location=0,directories=0,resizable=0,menubar=0,status=0,scrollbars=0,'+
			'left='+l+',top='+t+',width='+w+',height='+h
		);
	}
}



var _curnav   = null;
var _usrnav	  = null;
var _prevnav  = null;
var _navtimer = null;


// search for current nav element
window.onload = function() {

	if ( document.getElementById("navdyn") ) {
		var nodes = document.getElementById("navdyn").childNodes;
		for( var i=0; i<nodes.length; i++ ) {
			if ( nodes[i].tagName=="LI" && nodes[i].firstChild && nodes[i].firstChild.className=="navcur" ) {
				_curnav = _usrnav = nodes[i].childNodes[2];
				break;
			}
		}
	}
}


// open (and close previous opened) submenu
function navopen( id, fading ) {

	if ( _navtimer!=null ) clearTimeout( _navtimer );
	if ( !id ) return;
	if ( !fading && _curnav && _curnav.id!=id ) _curnav.style.display = "none";
	
	_curnav = typeof(id)=="string" ? document.getElementById( id ) : id;
	if ( _curnav ) {
		_curnav.style.display = "block";
		_curnav.style.opacity = 1.0;
	}
}

// hide submenu
function navclose() {
	if ( typeof(_isIE)!="undefined" ) {
		_navtimer = setTimeout(
			function() {
				if ( _usrnav ) navopen( _usrnav );
				else if ( _curnav ) _curnav.style.display = "none";
			},
			500 
		);
	}
	else _navtimer = setTimeout( "navrevert()", 100 );
}


// revert to the default menu / submenu position
function navrevert() {
	if ( _curnav==_usrnav ) return;
	
	// fader-out current submenu
	if ( _curnav ) {
		_prevnav = _curnav;
		_prevnav.style.opacity = 0;
		// wait 1 second and set current submenu hidden
		setTimeout(
			function() {
				if ( _prevnav.style.opacity==0 ) {
					_prevnav.style.display = "none";
					_prevnav.style.opacity = 1.0;
				}
			},
			1000
		);
	}
	
	
	// fade-in default submenu
	if ( _usrnav ) {
		_usrnav.style.opacity = 0;
		_usrnav.style.display = "block";
		_navtimer = setTimeout( "navopen(_usrnav,true)", 400 );
	}
}



