package net.fdms.Database 
{
	import net.fdms.Function.Convert.XMLtoOBJECT;
	/**
	 * ...
	 * @author Dawnboy
	 */
	public class PhotoData 
	{
		/**
		 * 获取相册列表及相关数据信息
		 */
		
		private static var _photoData:Array = [];
		public function PhotoData() 
		{
			/*_photoData = [
				[
					{id:"", title:"结婚纪念", cover:"1.jpg" },
					[
						{id:"", title:"相片名称", cover:"缩略图", src:"相片路径", width:"", height:"" },
						{id:"", title:"相片名称", cover:"缩略图", src:"相片路径", width:"", height:"" }
					]
				],
				[
					{id:"", title:"结婚纪念", cover:"1.jpg" },
					[
						{id:"", title:"相片名称", cover:"缩略图", src:"相片路径", width:"", height:"" },
						{id:"", title:"相片名称", cover:"缩略图", src:"相片路径", width:"", height:"" }
					]
				]
			]*/
		}
		
		/**
		 * 初始化相册数据
		 * @param	photoSets
		 */
		public static function init(photoSets:XMLList):void {
			var n:int = photoSets.children().length();
			if (n) {
				for (var a:int = 0; a < n; a++) {
					_photoData.push([]);
					_photoData[a].push(XMLtoOBJECT.convert(photoSets.album[a]));
					_photoData[a].push([]);
					var sn:int = photoSets.album[a].children().length();
					if (sn) {
						for (var b:int = 0; b < sn; b++) {
							_photoData[a][1].push(XMLtoOBJECT.convert(photoSets.album[a].item[b]));
						}
					}
				}
				
			}	
			
			debug();
		}
		
		/**
		 * 获取所有相册、照片信息
		 * @return
		 */
		public static function getAllPhotoData():Array {
			return _photoData;
		}
		
		/**
		 * 获取相册/信息/列表
		 * @param	AlbumID
		 * @return
		 */
		public static function getAlbums():Array {
			var n:int = _photoData.length;
			var foo:Array = [];
			for (var a:int = 0; a < n; a++) {
				foo.push(_photoData[a][0]);
			}
			
			return foo;
		}
		
		/**
		 * 获取相册内图片列表
		 * @param	AlbumID	默认返回所有相册中的所有相片列表
		 * @return
		 */
		public static function getPhoto(AlbumID:int = NaN):Array {
			var n:int = _photoData.length;
			var foo:Array = [];
			var a:int = 0;
			if (AlbumID && AlbumID != 0) {
				for (a; a < n; a++) {
					if (_photoData[a][0].id == AlbumID) {
						foo = _photoData[a][1];
						break;
					}
				}
				
			}else {
				for (a; a < n; a++) {
					var tmp:int = _photoData[a][1].length;
					for (var b:int = 0; b < tmp; b++) {
						foo.push(_photoData[a][1][b]);
					}
				}
			}
			return foo;
		}
		
		private static function debug():void {
			var n:int = _photoData.length;
			for (var a:int = 0; a < n; a++) {
				//trace("[" + _photoData[a][0].title + "] ID:" + _photoData[a][0].id + " 共 " + _photoData[a][1].length + " 张图片");
				}
			//trace("---------------------------------")
			
		}
		
	}

}