/*
	For LeftNavBar AlbumShow	
*/
function albumShow(nav)
{
	var navObject;
	var index = document.getElementById('AlbumPhotoList').selectedIndex;
	if(index > -1)
	{
		switch(nav)
		{
			case '-1':
				//如果大于2,向前移一位,数字不变
				if(index + 1 > 2)
				{
					ShowAlbumPhoto(index);
				}
				else
				{
					//位置1数字 如果大于1,表明前面还有项,变数字,显示第index项
					if(Number(document.getElementById('Album_Nav_1').value) > 1)
					{
						for(var i=1;i<=5;i++)
						{
							navObject = document.getElementById('Album_Nav_' + i);
							navObject.value = '0' + (Number(navObject.value)-1);
						}
						
						ShowAlbumPhoto(index + 1);						
					}
					else
					{
						//位置1数字等于1,不变数字,显示第1项
						ShowAlbumPhoto(1);
					}
				}
				break;
			case '+1':
				//如果小于4,向后移动1位
				if(index + 1 < 4)
				{
					ShowAlbumPhoto(index + 2);
				}
				else
				{
					//位置5数字如果小于图片总数或10, 变数字,显示第index + 1项
					if(Number(document.getElementById('Album_Nav_5').value) < document.getElementById('AlbumPhotoList').options.length)
					{
						for(var i=1;i<=5;i++)
						{
							navObject = document.getElementById('Album_Nav_' + i);						
							navObject.value = Number(navObject.value) + 1;						
							if(navObject.value.length == 1)
							{
								navObject.value = '0' + navObject.value;
							}						
						}
						ShowAlbumPhoto(index + 1);
					}
					else
					{
						//等于图片总数或10, 不变数字,显示第5项
						ShowAlbumPhoto(5);
					}
				}
				break;
			default:
				ShowAlbumPhoto(Number(nav));
				break;
		}
	}
}	
function ShowAlbumPhoto(index)
{
	var list = document.getElementById('AlbumPhotoList');
	
	//用selectedIndex记录当前选中的图片
	if(list.selectedIndex != -1)
	{
		document.getElementById('Album_Nav_' + (list.selectedIndex + 1)).className = 'albumNumber';
	}
	
	//index Number的索引
	var navObject = document.getElementById('Album_Nav_' + index);
	
	//i AlbumPhotoList的索引
	var i = Number(navObject.value) - 1;
	if(list.options[i])
	{
		//显示图片
		//document.images['AlbumShow'].style.display = 'none';
		document.images['AlbumShow'].src = list.options[i].value;
		document.images['AlbumShow'].title = list.options[i].text;
		//document.getElementById('AlbumShowLink').href = list.options[i].getAttribute('url').replace('[TemplateID]',list.getAttribute('TemplateID'));	
		document.getElementById('AlbumShowLink').href="http://www.soufun.com/album/"+list.options[i].getAttribute('userid')+".htm";
		document.images['AlbumShow'].onload = 
			function()
			{
				//先删除属性
				this.removeAttribute('width');
				this.removeAttribute('height');
				
				//得到图片的原始宽高
				var w = this.width,h = this.height;
				var maxW = 160,maxH = 120;
					
				//格式化宽
				if(w > maxW)
				{
					this.width = maxW;
					this.height = maxW*h/w;
					w = this.width;
					h = this.height;
				}
				//格式化高
				if(h > maxH)
				{
					this.height = maxH;
					this.width = maxH*w/h;		
				}
			}
		document.images['AlbumShow'].doload = document.images['AlbumShow'].onload;
		document.images['AlbumShow'].doload();
				
		//选中并记录选中的索引
		navObject.className = 'albumNumberFocus';
		list.selectedIndex = index - 1;
	}
	else
	{
		//如果此位置没有图片显示"未上传图片"
		document.images['AlbumShow'].src = 'http://img2.soufun.com/blog/blogweb/ejym/wsc.jpg';
		document.images['AlbumShow'].title = '未上传图片';
		document.getElementById('AlbumShowLink').href = '';
		document.images['AlbumShow'].width = 160;
		document.images['AlbumShow'].height = 120;
		
		list.selectedIndex = -1;
	}
}
window.setTimeout('ShowAlbumPhoto(1);',2000);