/**
 * Pop-down menus
 */

var DROP_TIMEOUT		= 6;			// drop-down timeout in seconds
var DROP_LIST_PREFIX	= 'drop-list';	// id prefix of drop list anchor


var dropTimer			= 0;
var currentToggledMenu	= null;

function popDownMenuC( id )
{
	$( id ).style.display = 'none';
}

function popDownMenu( anchor, id )
{
	if ( currentToggledMenu != null )
		currentToggledMenu.style.display = 'none';
	var position	= Element.cumulativeOffset( $(anchor) );
	var list		= $( DROP_LIST_PREFIX + id );
	list.style.top		= position['top'] + 'px';
	list.style.left		= position['left'] + 'px';
	list.style.display	= 'block';
	currentToggledMenu	= list;
	if ( dropTimer > 0 )
	{
		dropTimer = DROP_TIMEOUT;
	} else {
		dropTimer = DROP_TIMEOUT;
		popMenuTimeout();
	}
}

function popMenuTimeout()
{
	dropTimer--;
	if ( dropTimer <= 0 )
	{
		if ( currentToggledMenu != null )
			currentToggledMenu.style.display = 'none';
		return;
	}
	setTimeout( "popMenuTimeout()", 1000 );
}


/**
 * Misc utility functions
 */
function clearEmailField( id )
{
	if ( $F(id) == 'Your Email' )
		$(id).value = '';
}

function generateYoutubeHtml( videoId, width, height )
{
	var html =	'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ' +
				'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" ' +
				'width="' + width + '" height="' + height + '" id="YoutubeVideo">' + "\n" +
				'<param name="allowScriptAccess" value="sameDomain" /> ' +
				'<param name="allowFullScreen" value="false" /> ' +
				'<param name="movie" value="http://www.youtube.com/v/' + videoId + '&hl=en&fs=1" /> ' +
				'<param name="quality" value="high" /> ' +
				'<param name="bgcolor" value="#313339" /> ' + "\n" +
				'<embed src="http://www.youtube.com/v/' + videoId + '&hl=en&fs=1" quality="high" bgcolor="#ffffff" width="' + width + '" height="' + height + '" name="YoutubeVideo" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /> ' +
				'</object>';

	return html;
}

function renderYoutubeVideo( videoId, width, height )
{
	document.write( generateYoutubeHtml( videoId, width, height ) );
}

function convertYoutubeLinks()
{
	var linkTags = document.getElementsByTagName('span');
	for ( var i = 0; i < linkTags.length; i++ )
	{
		var tag = linkTags[i];
		if ( tag.className == 'youtubeid' )
		{
			var youtubeData		= tag.innerHTML;
			var pieces			= youtubeData.split(':');
			var html			= generateYoutubeHtml( pieces[0], pieces[1], pieces[2] );
			tag.innerHTML		= '';
			tag.style.display	= 'block';
			Element.insert( tag, html );
		}
	}
}
window.onload = convertYoutubeLinks;