
WordGameLobby.prototype = new GameLobby();
WordGameLobby.prototype.constructor = WordGameLobby;
function WordGameLobby()
{
	GameLobby.call( this );
	this.mChoiceNotTimedElement;
	this.mTabElements;
	this.mVariationElements;	
}

WordGameLobby.prototype.CreateBody = function( e )
{	
	if ( !e ) { return; }
	
	var html = '';	
	html +=		IsEmbededMini() ? '' : '<TABLE cellpadding=0 cellspacing=0 border=0><TR><TD style="width:150px;">&nbsp;</TD><TD>';
	html +=		'<TABLE cellpadding=0 cellspacing=0 border=0>';
	html +=			'<TR><TD style="vertical-align:top;">';
	html +=	this.GetHTML_Tabs();
	html +=			'</TD></TR>';
	
	html +=			'<TR><TD><FORM onsubmit="return false;"><TABLE cellpadding=0 cellspacing=0 border=0 id="wg_config" class="wg_tab_body">';
	html +=			(gbMultiplayer && this.mGIPDivName) ? '<TR><TD id="wgmpgip_dest"></TD></TR>' : this.GetHTML_Variations();
	html +=				(IsEmbededMini() || gbMultiplayer) ? '' : ('<TR><TD colspan=4 style="border-bottom:1px solid #000000; padding-top:12px;"><DIV style="width:1px; height:1px;"></DIV></TD></TR>');
	if ( !gbMultiplayer )
	{
		var from = Search_GetValue( 'from' );
		var bTimed = from ? GameVariation.IsVariationTimed( from ) : false;
		html +=				'<TR><TD colspan=4><TABLE>';
		if ( !IsEmbededMini() )
		{		
			html +=				'<TR><TD class="wg_text" style="font-weight:bold; border-bottom:1px solid #000000; text-align:center;">OPTIONS</TD></TR>';
			html +=				'<TR><TD>';		
			html +=					'<INPUT type=radio id="wg_choice_timed1" name="wg_choice_timed" style="vertical-align:middle;" onclick="WordGameLobby.TimedOptionOnClick();" '+ (bTimed?'':'checked') + '><LABEL for="wg_choice_timed1">' + kTxt_NotTimed + '</LABEL>&nbsp;&nbsp';
			html +=					'<INPUT type=radio id="wg_choice_timed2" name="wg_choice_timed" style="vertical-align:middle;" onclick="WordGameLobby.TimedOptionOnClick();" '+ (bTimed?'checked':'') + '><LABEL for="wg_choice_timed2">' + kTxt_Timed + ' ('+ Math.floor(kMaxTime/60000)  +' mins)' +'</LABEL>';
			html +=				'</TD></TR>';
		}
		else
		{
			html +=				'<TR class="wg_text" class="xsmall"><TD style="font-weight:bold; text-align:center;">OPTIONS:</TD>';
			html +=				'<TD>';	
			html +=					'<INPUT type=radio id="wg_choice_timed1" name="wg_choice_timed" style="vertical-align:middle;" onclick="WordGameLobby.TimedOptionOnClick();" '+ (bTimed?'':'checked') + '><LABEL for="wg_choice_timed1">' + kTxt_NotTimed + '</LABEL>&nbsp;';
			html +=					'<INPUT type=radio id="wg_choice_timed2" name="wg_choice_timed" style="vertical-align:middle;" onclick="WordGameLobby.TimedOptionOnClick();" '+ (bTimed?'checked':'') + '><LABEL for="wg_choice_timed2">' + kTxt_Timed + ' ('+ Math.floor(kMaxTime/60000)  +' mins)' +'</LABEL>';
			html +=				'</TD></TR>';
		}
		html +=				'</TABLE></TD></TR>';
	}
	html +=				(IsEmbededMini() || gbMultiplayer) ? '' : ('<TR><TD colspan=4 style="border-top:1px solid #000000; padding-bottom:12px;"><DIV style="width:1px; height:1px;"></DIV></TD></TR>');
	html +=			'</TABLE></FORM></TD></TR>';
	html +=		'</TABLE>';
	html +=		IsEmbededMini() ? '' : '</TD><TD class="small" style="padding-left:4px; padding-right:4px; width:142px; vertical-align:top;"><TABLE><TR style="height:140px;"><TD id="wg_desc_type" style="padding:4px; border:3px double #000000; visibility:hidden; vertical-align:top;"></TD></TR></TABLE></TD></TR></TABLE>';

	e.innerHTML = html;
	
	if ( gbMultiplayer && this.mGIPDivName )
	{
		var newParent = GetElement( 'wgmpgip_dest' );
		var div = GetElement( this.mGIPDivName );
		if ( newParent && div )
		{
			if ( div.parentNode )
			{
				div.parentNode.removeChild( div );
			}
			newParent.appendChild( div );
			div.style.display = 'block';
			div.style.marginTop = '8px';
			div.style.marginLeft = '8px';
			div.style.marginRight = '8px';
		}
	}
	
	this.mChoiceNotTimedElement	= GetElement( 'wg_choice_timed1' );

	this.SetupTabs();	
	this.SetupVariations();
	this.SetupLinks();

	this.mTypeDescriptionElement = GetElement( 'wg_desc_type' ); // after SetupTabs
	if ( this.mTypeDescriptionElement && this.mTypeDescription )
	{
		this.mTypeDescriptionElement.innerHTML = this.mTypeDescription;
		this.mTypeDescriptionElement.style.visibility = 'visible';
	}
	
	for ( var i=0; GameVariation.mVariations && i <= GameVariation.mVariations.length; ++i ) 
	{
		if ( !GameVariation.mVariations[i] ) { continue; }
		
		var e = GetElement( GameVariation.mVariations[i].mElementID );
		if ( e )
		{	
			if ( GameVariation.mVariations[i].mTimedID <= 0 ) // not timeable, so disable elements
			{				
				e.TimedOptionOnChange = function ( bTimed )
				{
					var obj = this;
					obj.mbDisabled = bTimed;
					
					var titleTD = GetElement( obj.id + 'title' );
					if ( titleTD )
					{
						titleTD.mbDisabled = obj.mbDisabled;
						if ( !obj.mbDisabled )
						{
							titleTD.onmouseout = titleTD.mOrigOnMouseOut;
						}
					}
							
					var inputs = obj.getElementsByTagName( 'INPUT' );
					for ( var k = 0; k < inputs.length; ++k )
					{
						if ( inputs[k].type == 'button' )
						{
							inputs[k].disabled = obj.mbDisabled;
						}
					}
			
					var divs = obj.getElementsByTagName( 'DIV' );
					for ( var j = 0; j < divs.length; ++j )
					{
						var div = divs[j];
						if ( div.mbRolloverable )
						{
							if ( bTimed )
							{
								div.mbDisabled = true;
								div.className = div.mDisabledClassName;
								//div.className = Game.kLetterClassDisabled + ' ' + div.className;
							}
							else
							{
								div.mbDisabled = false;
								//div.className = div.className.replace( Game.kLetterClassDisabled, '' );
								div.className = div.mDefaultClassName;
							}
						}
					}
				};
				
				if ( this.IsTimed() )
				{
					e.TimedOptionOnChange( true );
				}
			}
		}	
	}
};

WordGameLobby.prototype.IsTimed = function()
{
	return this.mChoiceNotTimedElement && !this.mChoiceNotTimedElement.checked;
};

WordGameLobby.prototype.GoToRoom = function( index )
{
	GameLobby.prototype.GoToRoom.call( this, index, this.IsTimed() );
};

WordGameLobby.TimedOptionOnClick = function()
{
	if ( !Game.mSingleton ) { return; }
	
	var bTimed = Game.mSingleton.IsTimed();
	for ( var i = 0; i <= GameVariation.mVariations.length; ++i ) 
	{
		var v = GameVariation.mVariations[i];
		if ( v )
		{
			e = GetElement( v.mElementID );
			if ( e && e.TimedOptionOnChange )
			{
				e.TimedOptionOnChange( bTimed );
			}
		}
	}	
};

function ZE_LobbySetup( type, tabPrefix, variationPrefix )
{
	var lobby = new WordGameLobby();
	lobby.mType = type;

	lobby.mTabElements = GetElements( tabPrefix, 1 );
	lobby.mVariationElements = GetElements( variationPrefix, 1 );
}

function ZE_WriteLobby( parent, bLoggedIn, gameInProgressDivName )
{	
	if ( !Game.mSingleton ) { return; }

	Game.mSingleton.mbLoggedIn = bLoggedIn == 1 ? true : false;
	Game.mSingleton.mGIPDivName = gameInProgressDivName;
	Game.mSingleton.SetupPage( parent );	
}
