function $(id){return document.getElementById(id);};
function GetMessagesCount()
{	
	$('MessagesCount').innerHTML = this.responseXML.lastChild.firstChild.data;
}
function RefreshUserInfo()
{
	if(CurrentUserID != UserID)
	{
		Xml.Request('/Interface/IsAlbumUser.aspx?userid=' + CurrentUserID, null, GetUserInfoFinish);
	}
	else
	{
		window.location.href = window.location;
	}
}
function GetUserInfoFinish()
{
    var state = this.responseXML.lastChild.firstChild.data;
    if(state == '0')
    {
        IsAuthenticated = '2';
    }
    else
    {
        IsAuthenticated = state;
    }
	InitializeTopLinks();
}
function InitializeTopLinks()
{
	$('UserLogin_OpenButton').style.display = (IsAuthenticated == '0' ? '' : 'none');
	$('TopLink_Register').style.display = (IsAuthenticated == '0' ? '' : 'none');
	$('TopLink_OpenMyAlbum').style.display = (IsAuthenticated == '2' ? '' : 'none');
	$('TopLink_MyAlbum').style.display = (IsAuthenticated == '1' ? '' : 'none');
	$('TopLink_Logout').style.display = (IsAuthenticated != '0'?'' : 'none');
	$('s1').style.display = (IsAuthenticated == '0' ? '' : 'none');
	$('s2').style.display = (IsAuthenticated != '0' ? '' : 'none');
	$('s3').style.display = (IsAuthenticated != '0' ? '' : 'none');
	if(IsAuthenticated != '0')
	{
		Xml.Request('/Interface/GetUnreadMessagesCount.aspx?userid=' + CurrentUserID + '&username=' + escape(CurrentUserName), null, GetMessagesCount);
		$("TopLink_MessageBox").href = 'http://passport.soufun.com/message.web/messageunreadlist.aspx/userid=' + CurrentUserID;
		if(IsAuthenticated == '1')
		{
			$('TopLink_MyAlbum').href = '/Album/' + CurrentUserID + '.htm';
			$('TopLink_MyAlbum').innerHTML = $('TopLink_MyAlbum').innerHTML.replace('[UserName]', CurrentUserName);
		}
		else
		{
			$('TopLink_OpenMyAlbum').innerHTML = $('TopLink_OpenMyAlbum').innerHTML.replace('[UserName]', CurrentUserName);
		}
	}
	$('TopLink_MessageBox').style.display = (IsAuthenticated != '0' ? '' : 'none');
}
InitializeTopLinks();
document.focusViews['ForNavBar'].onoverchange = 
	function()
	{
		if (this.overItem.id == 'NavLink_Albums')
		{
			if ($('AlbumList').rows.length > 1)
			{
				$('AlbumList').style.display = '';
				$('AlbumList').style.visibility = 'visible';
			}
		}
	}
document.focusViews['ForNavBar'].onfocuschange = function(){return false;};
$('NavLink_Albums').onmouseout = 
	function()
	{		
		$('AlbumList').style.visibility = 'hidden';
		$('AlbumList').style.display = 'none';
	}
document.focusViews['ForAlbumList'].onfocuschange = 
	function()
	{
		var albumName = this.focusItem.innerHTML;
		var albumId = this.focusItem.getAttribute('AlbumID');
		$('AlbumName').innerHTML = albumName;		
		$('AlbumList').style.visibility = 'hidden';
		$('AlbumList').style.display = 'none';
		GenerateFlashCode(albumId);
	}
function PopulateAlbumList()
{
	for (var i = 0; i < $('AlbumList').rows.length; i++)
	{
		if (i < $('AlbumList').rows.length - 1) $('AlbumList').rows[i].cells[0].style.borderBottom = '1px solid #333333';		
		if ($('AlbumList').rows[i].cells[0].getAttribute('AlbumID') == AlbumID)
		{
			$('AlbumName').innerHTML = $('AlbumList').rows[i].cells[0].innerHTML;
			document.focusViews['ForAlbumList'].setFocusItem($('AlbumList').rows[i].cells[0]);
		}
	}
}
PopulateAlbumList();
function GenerateFlashCode(albumId)
{
    var localDomain=window.location.hostname;
	$('FlashPlayer').innerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="800" height="600"><param name="movie" value="/Album/include/SlideShow.swf"><param name="quality" value="high"><param name="wmode" value="transparent"><param name="FlashVars" id="FlashVars" value="inputstr=http://'+localDomain+'/Album/GetPicturesByUserAlbumForSlideShow.aspx?userid$' + UserID + '*albumid$' + albumId + '"><embed src="/Album/include/SlideShow.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="800" height="600" wmode="transparent" FlashVars="inputstr=http://'+localDomain+'/Album/GetPicturesByUserAlbumForSlideShow.aspx?userid$' + UserID + '*albumid$' + albumId + '"></embed></object>';
}
