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();
function InitializeNavigation()
{	
	$('NavigationLink_Icon').href = '/Album/' + UserID + '.htm';
	$('AlbumTitle').href = '/Album/' + UserID + '.htm';
	var size = GetStringLength($('AlbumTitle').innerHTML);
	if(size < 0) size = 20;
	$('AlbumTitle').size = size;
	$('NavigationLink_DomainName').href = '/Album/' + UserID + '.htm';
	if($('ForAlbumTitle') != null && $('ForAlbumTitle') != undefined)
	{
	    $('ForAlbumTitle').setAttribute('Action', '/Interface/UpdateUserAlbumTitle.aspx?userid=' + UserID + '&albumtitle=');
	    $('ForAlbumTitle').setAttribute('OnBind', 'return UserID != "0" && UserID == CurrentUserID;');
	    $('ForAlbumTitle').setAttribute('OnUpdate', 'if(this.textBox.value == "") this.textBox.value = this.element.innerHTML;');
	    $('ForAlbumTitle').setAttribute('OnFinish', 'if(this.returnValue != "100"){window.alert("Error Code:" + this.returnValue);return false;}');
	}
	InitializeSwapButtons();
}
function InitializeSwapButtons()
{
	for (var i=1; i<=5; i++)
	{
		document.images['SwapButton_' + i].onmouseover = 
			function()
			{
				this.src = this.src.replace('we_','ew_');
				this.className = 'colorButton';
			}
		document.images['SwapButton_' + i].onmouseout = 
			function()
			{
				this.src = this.src.replace('ew_','we_');
				this.className = 'grayButton';
			}
	}
	$('SwapButton_Album').href = '/Album/AlbumList_' + UserID + '.htm';
	$('SwapButton_Favorite').href = 'javascript:;';
	$('SwapButton_Favorite').onclick =
		function()
		{
			if (window.sidebar)			
			{
				window.sidebar.addPanel(document.title, 'http://photo.soufun.com/Album/' + UserID + '.htm', UserName + '的相册');
			}
			else if(navigator.appName == 'Microsoft Internet Explorer')
			{
				window.external.AddFavorite('http://photo.soufun.com/Album/' + UserID + '.htm', document.title);
			}
			else
			{
				window.alert('你需要手工将此页面添加到你的收藏夹!');
			}
		}
	$('SwapButton_GuestBook').href = '/Album/LeaveWord_' + UserID + '.htm';
	$('SwapButton_Blog').href = 'http://blog.soufun.com/blog_' + UserID + '.htm';
	$('SwapButton_RSS').href = '/Album/RSS_' + UserID + '.xml';
}
if($('Navigation') != null)
{
	InitializeNavigation();
}