OnlineShellMgr = new ClientMgr(	{	chatContainer		: "upChatContainer"
								,	expandChatButton	: "divExpandChat"
								,   userEndGameScore	: "yourScore"
								}
							  , "OnlineShellMgr"
							  );
					  
/**
 * The area of the portlet
 */

OnlineShellMgr.portletArea = new LayersGroup(	{	howToPlay			: "upHowToPlay"
												,	chatPreferences		: "upChatPreferences"
												,	endGameWarning		: "upWarning"
												,	rankingLegend		: "upRankingLegend"
												,	userPortlet			: "divUserPortlet"
												,	chatUserProfile		: "divPlayerProfile"
												}
											,	"portletArea"
											);

// must override this values to the actual values where using the sound/mute funcs
OnlineShellMgr.defaultSoundImageID = "";
OnlineShellMgr.defaultCheckboxID = "";
OnlineShellMgr.defaultSoundImagesNames = ["",""];



/**
* The text colors of the chat activex control
*/											
OnlineShellMgr.chatTextColors = {};
OnlineShellMgr.chatTextColors.colorItems			= 6;
OnlineShellMgr.chatTextColors.holderPrefix			= 'colorItem_';
OnlineShellMgr.chatTextColors.selectedBorderColor	= 'yellow';
OnlineShellMgr.chatTextColors.normalBorderColor		= 'black';
												
/**
 * Managed Pages
 */						
OnlineShellMgr.addManagedPage( "UserMedals", "/Orange2.0/App/MyMedals.aspx", "width=611,height=440,status=no,scrollbars=yes,toolbar=no,menubar=no,location=no,resizeable=no");  							  
OnlineShellMgr.addManagedPage( "HighScore", "/Orange2.0/App/GameHighScore.aspx", "width=611,height=440,status=no,scrollbars=yes,toolbar=no,menubar=no,location=no,resizeable=no");  							  

/* show & hide elements */
//TODO: check if the active-X can suffer a div over it.
//		if not - then when every div is shown the code
//				 must make sure the chat is not expanded.
OnlineShellMgr.classNames = {	chatContainer	: ["upChatMaximized", "upChatMinimized" ]
							,	expandChatButton: ["divChatDown", "divChatUp"]
							};
/**
 * Opens the high-score game
 */
OnlineShellMgr.openGameHighScore = function(iSku)
{
	ProfileMgr.openGameHighScore(iSku);
}
/**
 * Opens the user-games and medals page
 */
OnlineShellMgr.openMyMedals = function()
{ 
	this.openWindow("UserMedals");
}
/**
 * Makes the User-Poprtlet visible
 */
OnlineShellMgr.showUserPortlet		=	function()
{	
	this.collapseChatState();
	this.portletArea.showLayer("userPortlet");
}
/**
 * Shows the chat pereferences layer
 */
OnlineShellMgr.showChatPreferences	=	function()
{ 
	this.collapseChatState();
	this.portletArea.showLayer("chatPreferences"); 
}
/**
 * Shows the endGame layer
 */
OnlineShellMgr.showEndGameWarning	=	function()
{	
	this.collapseChatState();
	this.portletArea.showLayer("endGameWarning"	); 
}
/**
 * Shows the how to play layer
 */
OnlineShellMgr.showHowToPlay		=	function()
{
	this.collapseChatState();
	this.portletArea.showLayer("howToPlay"); 
}
/**
 * Shows the ranking/rating legend layer
 */
OnlineShellMgr.showRankingLegend	=	function()
{	
	this.collapseChatState();
	this.portletArea.showLayer("rankingLegend"); 
}
/**
 * Shows the user-profile for chat users
 */
OnlineShellMgr.showProfileByNick = function( sNickname )
{
	Claim.isNumber(this.currentGameSku, "OnlineShellMgr.showProfileByNick needs OnlineShellMgr.currentGameSku to be set with the played product-sku-code for this function to work");

	this.collapseChatState();

	this.resetChatUserProfile();
	this.portletArea.showLayer("chatUserProfile");
	
	new OnlineShellMgr.ChatUserProfile(/* nickname : */	sNickname
									  ,/* sku :      */ this.currentGameSku
									  ,/* avatarSize:*/	UA.User.Avatar.Size.Size98x131)

}
//--OnlineShellMgr.OtherUser------------------------------------------------------------
//	OnlineShellMgr.ChatUserProfile = Class.create("UA.User");
//	OnlineShellMgr.ChatUserProfile.prototype.initialize = function(sNickname, iSku, enAvatarSize)
//	{
//		//TODO: claims
//		
//		this.log = new Log4Js.Logger("OnlineShellMgr.ChatUserProfile");
//		
//		this.currentGameSku = iSku;
//		
//		if(enAvatarSize == null)
//			enAvatarSize = UA.User.Avatar.Size.Size98x131
//		this.GetPersonaDataByNickname (/* nickname :	*/	sNickname
//									  ,/* enAvatarSize:	*/	enAvatarSize
//									  ,/* iSku :		*/	iSku
//									  ,/* fSuccess :	*/	this.onSuccess
//									  ,/* fFailure :	*/	this.onFailureOrTimeout
//									  ,/* fTimeout :	*/	this.onFailureOrTimeout
//									  );
//	}
//	OnlineShellMgr.ChatUserProfile.prototype.toString = function()
//	{
//		return "[UA.User] extension: ChatUserProfile";
//	}
//	/**
//	 * @private
//	 * converts the twiched structure from User-Accounts to the structure expectd 
//	 * by populateChatUserProfile.
//	 */
//	OnlineShellMgr.ChatUserProfile.prototype.onSuccess = function(dataUA)
//	{
//		this.log.info("OnlineShellMgr.ChatUserProfile.onSuccess - got data: " + Serialize(dataUA));

//		data  = { avatar	: dataUA.avatar
//				, nickname	: dataUA.nickname
//				};
//		
//		if(dataUA.highestMedal) 
//		{
//			var oGame = TC.SKUs[dataUA.highestMedal.sku];
//			if(oGame) 
//			{
//				data.userBadge	 =	{	badgeGameSku	: dataUA.highestMedal.sku
//									,	score			: dataUA.highestMedal.score
//									,	position		: dataUA.highestMedal.position
//									,	badgeImgUrl		: TC.UserMedals.getMedalByRanking(dataUA.highestMedal.ranking).img
//									,	badgeGameName	: oGame.name
//									,	badgeGameUrl	: oGame.gamePageURL
//									};
//			}
//			else
//			{	
//				data.userBadge  = "ERROR";
//				this.log.warn("Can't find game of user medal. Sku: " + dataUA.highestMedal.sku );
//			}
//		}					
//		if(dataUA.requestedGame)
//		{
//			data.currentGame =	{	score	 : dataUA.requestedGame.score
//								,	position : dataUA.requestedGame.position 
//								};
//		}
//		else
//		{
//			this.log.info("No score found for the current game. Sku: " + this.currentGameSku);
//		}
//		this.log.info("populating user chat profile with :  " + Serialize(data));
//		OnlineShellMgr.populateChatUserProfile(data);
//	}
//	/**
//	 * @private
//	 */
//	OnlineShellMgr.ChatUserProfile.prototype.onFailureOrTimeout = function(request)
//	{
//		OnlineShellMgr.setChatUserProfileErrorMsg();
//	}
//--/ProfileMgr.OtherUser------------------------------------------------------------
/**
 * Default handler for reseting the chat-user-profile pallete 
 */
OnlineShellMgr.resetChatUserProfile = function()
{
	this.log.error("OnlineShellMgr.resetChatUserProfile is expected to be overwridden in project");
}
/**
 * Default handler for reseting the chat-user-profile pallete with error messages
 */
OnlineShellMgr.setChatUserProfileErrorMsg = function()
{
	this.log.error("OnlineShellMgr.setChatUserProfileErrorMsg is expected to be overwridden in project");
}
/**
 * Default handler for asyncronious call for GetOtherUserProfile
 * 
 * The provided data is expected to contain:
 *	data.nickname
 *  data.avatar
 *  data.userBadge.skuCode
 *  data.userBadge.score
 *  data.userBadge.position
 *	data.currentGame.score
 *	data.currentGame.position
 */
OnlineShellMgr.populateChatUserProfile = function(data)
{
	alert("OnlineShellMgr.populateChatUserProfile was not overriden in project.\n\n Received data: " + Serialize(data) );
}

/**

 * Hides the chat pereferences layer
 */
OnlineShellMgr.hideChatPreferences	=	function()
{
	this.showUserPortlet();
}	
/**
 * Hides the end-game warning layer
 */
OnlineShellMgr.hideEndGameWarning	=	function()
{
	this.showUserPortlet();
}	
/**
 * Hides the ranking/rating legend layer
 */
OnlineShellMgr.hideRankingLegend	=	function()
{
	this.showUserPortlet();
}	
/**
 * Hides the how-to-play layer
 */
OnlineShellMgr.hideHowToPlay		=	function()
{
	this.showUserPortlet();
}	
/**
 * Hides the chat-user profile area
 */
OnlineShellMgr.hideProfileByNick = function( sNickname )
{
	this.showUserPortlet();
}
/**
 * changes the state of the chat (expanded/collapsed)
 * 
 * @param {Element} the element with the onclick on
 */
OnlineShellMgr.changeExpandChatState = function(divButton)
{
	if( divButton.className == this.classNames.expandChatButton[0] )
	{
	//	this.collapseChatState();
	}
	else
	{
		this.expandChatState();
	}
}
/**
 * expands the chat
 */
OnlineShellMgr.expandChatState = function()
{
	if(this.elements.expandChatButton)
		this.elements.expandChatButton.className = this.classNames.expandChatButton[0];
	if(this.elements.chatContainer)			
		this.elements.chatContainer.className	 = this.classNames.chatContainer[0];
	//TODO: interact with active X 
	//alert('TODO: implement activeX height');
}
/**
 * collapses the chat
 */
OnlineShellMgr.collapseChatState = function()
{
	if(this.elements.expandChatButton)
		this.elements.expandChatButton.className = this.classNames.expandChatButton[1];
	if(this.elements.chatContainer)	
		this.elements.chatContainer.className	 = this.classNames.chatContainer[1];
	//TODO: interact with active X 
	//alert('TODO: implement activeX height');
}

OnlineShellMgr.login = function()
{
	this.loginRequest=true;
	OnlineShellMgr.showEndGameWarning();
}
OnlineShellMgr.register = function()
{
	this.registerRequest=true;
	OnlineShellMgr.showEndGameWarning();
}
OnlineShellMgr.continueProc = function(b_closeAfter)
{
//debugger
	if(b_closeAfter==null)
		b_closeAfter=true;
	if(this.loginRequest){
		ProfileMgr.sendToAdapter("login");
	}
	if(this.registerRequest){
		ProfileMgr.sendToAdapter("register");	
	}
	if(b_closeAfter){
		// for avoiding the prompt for closing the window
		window.opener=null;
		// now close the current window
		self.close();
	}
}
/*
* the flag indicates to mute or not
*/
OnlineShellMgr.changeSoundState = function(flag)
{
    if(this.sound==null)
        this.sound=true;
    if(flag!=null)
		this.sound=flag;    
    try{    
		ChatSetMuteStatus(this.sound);
		this.sound = !this.sound;
		if(this.updateControls())
			return true;
		return false;	
	}catch(ex){
		this.log.error("could not change the sound status of the game host! Exception: " + Serialize(ex));
		return false;
	}
    
}
OnlineShellMgr.updateControls = function(){
	
	if(!$(this.defaultSoundImageID)){
		this.log.error("the image id of the sound icon is not correct");
		return false;
	}
	if(!$(this.defaultCheckboxID)){
		this.log.error("the checkbox id is not correct");
		return false;
	}
	var strMute  = this.defaultSoundImagesNames[0];
	var strSound = this.defaultSoundImagesNames[1];
	if(!this.sound){
		$(this.defaultSoundImageID).src = $(this.defaultSoundImageID).src.replace(strSound,strMute); 
		
	}else{
		$(this.defaultSoundImageID).src = $(this.defaultSoundImageID).src.replace(strMute,strSound); 
	}
	$(this.defaultCheckboxID).checked = !this.sound;
	return true;
	
}

OnlineShellMgr.chooseChatTextColor = function(index,strColor)
{
	try{
		ChatSetTextColor(strColor);
		// set the border for the selected color item holder
		$(OnlineShellMgr.chatTextColors.holderPrefix+index).style.borderColor = OnlineShellMgr.chatTextColors.selectedBorderColor;
		for(var i=1;i<=OnlineShellMgr.chatTextColors.colorItems;i++){
			if(i!=index)
				$(OnlineShellMgr.chatTextColors.holderPrefix+i).style.borderColor=OnlineShellMgr.chatTextColors.normalBorderColor;
		}
	}catch(ex){
		this.log.error("could not change the text color of the chat control! Exception: " + Serialize(ex));
    }
}
