$(
	function()
	{
		strLen = window.location.href.length;
		intV = parseInt(window.location.href.substr(strLen-1,1));
		
		if (intV > 0 )
			intStartI = intV-1;
		else
			intStartI = 0;
		
		aryPathA = [ 
			['images/photo/HK/thumbnails' ,'images/photo/HK/large'],
			['images/photo/SH/thumbnails' , 'images/photo/SH/large' ],
			['images/photo/FF/thumbnails' , 'images/photo/FF/large' ],
			];
		
		aryImg = [
			['01','02','03','04','05','06','07','08','09','10','11','12','13'],
			['01','02','03','04','05','06','07','08','09','10','11'],
			['01','02','03','04','05','06','07','08','09','10']
		]
		
		$("div.cssPhoto div.cssLeftPanel div.cssItemTitle img").css('display','none');
		$("div.cssPhoto div.cssLeftPanel div.cssItemTitle img:eq("+(intStartI)+")").css('display','block');
		
		intCurPos = 1;
		intPos = 1;
		intNumRow = 18;
		//intStartI = 0;
		
		intTotalPage = Math.ceil(aryImg[intStartI].length / intNumRow);				
		intJJ = 0;
		
		$("div.cssPhoto div.cssLeftPanel div.cssItemThum").html("");
		for (var j=0;j<aryImg[intStartI].length && j < intPos * intNumRow ;j++)
		{
			$("div.cssPhoto div.cssLeftPanel div.cssItemThum").append("<div id='zz"+(j+1)+"'></div>");
			
			var objImg = new Image();
			$(objImg).attr('z',"zz"+(j+1));
			$(objImg).load(
				function()
				{
					strII = ($(this).attr('z'));
					$("#"+strII).append(this);
					
					intCH = ($(this).height());
					$(this).css('margin-top', (40 - intCH) / 2);
				}
			).attr('src',aryPathA[intStartI][0]+'/'+aryImg[intStartI][j]+".jpg");
			
			$("#zz"+(j+1)).mouseover(
				function()
				{
					$(this).css('cursor','pointer');
				}
			);
			
			$("#zz"+(j+1)).attr('qi',j);
			$("#zz"+(j+1)).click(
				function()
				{
					funShowImg($(this).attr('qi'));
				}
			);
		}
		$("div.cssPhoto div.cssLeftPanel div.cssItemThum").append("<div class='cssClear'></div>");
		
		$("div.cssPhoto div.cssLeftPanel div.cssCtl div").each(
			function(i)
			{
				$(this).mouseover(
					function()
					{
						$(this).css("cursor","pointer");
					}
				);
				
				$(this).click(
					function()
					{
						jsNextImage(i);
					}
				);
			}
		);
				
		$("div.cssPhoto div.cssLeftPanel div.cssItemThumCtl div.cssCtl").each(
			function(i)
			{
				intCH = $(this).children("img:eq(0)").height();
				$(this).children("img:eq(0)").css('margin-top', (40 - intCH) / 2);
				
				if (i == 0)
				{
					$(this).attr('pp' , intPos - 1 );
					$(this).css('display',((intPos - 1 <= 0)? 'none' : 'block')); 
					
					$(this).click(
						function ()
						{
							jsSwapPage(-1);
						}
					);
				}
				else
				{
					$(this).click(
						function ()
						{
							jsSwapPage(1);
						}
					);
				
					$(this).attr('pp' , intPos + 1 );
					$(this).css('display',((intPos + 1 > intTotalPage)? 'none' : 'block')); 
				}
				
				
					
				$(this).mouseover(
					function ()
					{
						$(this).css('cursor','pointer');
					}
				);		
			}
		);
		
		var objImg = new Image();
			$(objImg).attr('id',"mzz0");
			$(objImg).load( 
				function()
				{
					//strII = ($(this).attr('z'));
					$("div.cssPhoto div.cssRightPanel div.cssItemImage").append(this);
					
					//02px;height:335px;
					intCW = $(this).width();
					intCH = $(this).height();
					$(this).css("height" , 432);
					intCW = intCW / intCH * 432;
					$(this).css("width" , intCW);
					$(this).css("margin-left",(646 - intCW ) / 2 );
					//$(this).css("margin-top",(335 - intCH ) / 2 );
					
					
				}
			).attr('src',aryPathA[intStartI][1]+'/'+aryImg[intStartI][0]+".jpg");
		
		//$("div.cssPhoto div.cssLeftPanel div.cssItemHeader img:eq("+(1-intStartI)+")").css('display','none');
		//$("div.cssPhoto div.cssLeftPanel div.cssItemHeader img:eq("+intStartI+")").css('display','block');
		
		
		/* ************************************** */
		/*
		if (intV > 0 )
		{
			if (intV == 1)
			{
				funMakeNewLayer($("div.cssPanel"));
				$("div.cssPanel").show('slow');
				$("#overlayercontent").load('parts/photogallary1.html',funloadedItem);
			}
			else
			{
				funMakeNewLayer($("div.cssPanel"));
				$("div.cssPanel").show('slow');
				$("#overlayercontent").load('parts/photogallary2.html',funloadedItem1);
			}
		}
	
		$("div.cssOverLayer div.cssTab ul li").each(
				function(i)
				{
					if (i == 0 )
					{
						$(this).click(
							function()
							{
								//$("div.cssPanel").show('slow');
								funMakeNewLayer($(this).parent().parent().parent().children("div.cssPanel"));
								$("div.cssPanel").show('slow');
								$("#overlayercontent").load('parts/photogallary1.html',funloadedItem);
							}
						);
					
					}
					else
					{
						$(this).click(
							function()
							{
								funMakeNewLayer($(this).parent().parent().parent().children("div.cssPanel"));
								$("div.cssPanel").show('slow');
								$("#overlayercontent").load('parts/photogallary2.html',funloadedItem1);
							}
						);
					}
				}
			);
		*/
	}
)

function jsChangeVideo()
{
	intStartI = 3;
	intTotalPage = 0;
	intPos = 0;
	intCurPos = 1;
	
	$("div.cssPhoto div.cssLeftPanel div.cssItemTitle img").css('display','none');
	$("div.cssPhoto div.cssLeftPanel div.cssItemTitle img:eq("+(intStartI)+")").css('display','block');
	$("div.cssPhoto div.cssRightPanel div.cssItemImage img").remove();
	$("#vtpreview").remove();
	
	$("div.cssPhoto div.cssRightPanel div.cssItemImage").html("<div id='vtpreview'></div>");
	$("div.cssPhoto div.cssLeftPanel div.cssItemThum").html("");
	
	obj = new Object();
	obj.wmode = "transparent";
	swfobject.embedSWF('videoplayer.swf',"vtpreview","650","430", '9.0.0.0', 'js/swfobject/expressInstall.swf', obj, obj, obj);
	
	$("div.cssPhoto div.cssLeftPanel div.cssItemThum").append("<div id='zz1'></div>");
			
	var objImg = new Image();
	$(objImg).attr('z',"zz1");
	$(objImg).load(
		function()
		{
			strII = ($(this).attr('z'));
			$("#"+strII).append(this);
					
			intCH = ($(this).height());
			$(this).css('margin-top', (40 - intCH) / 2);
		}
	).attr('src',"images/photo/video/01.jpg");
			
	$("#zz1").mouseover(
		function()
		{
			$(this).css('cursor','pointer');
		}
	);
			
	$("#zz1").click(
		function()
		{
			obj = new Object();
			obj.wmode = "transparent";
			swfobject.embedSWF('videoplayer.swf',"vtpreview","650","430", '9.0.0.0', 'js/swfobject/expressInstall.swf', obj, obj, obj);
		}
	);
	
}

function jsChangeV(i)
{
	if (i > 0 )
		intStartI = i-1;
	else
		intStartI = 0;
	intTotalPage = Math.ceil(aryImg[intStartI].length / intNumRow);	
	intPos = 0;
	intCurPos = 1;
	
	jsSwapPage(1);
	$("div.cssPhoto div.cssLeftPanel div.cssItemTitle img").css('display','none');
	$("div.cssPhoto div.cssLeftPanel div.cssItemTitle img:eq("+(intStartI)+")").css('display','block');
	
	//$("div.cssPhoto div.cssLeftPanel div.cssItemHeader img:eq("+(1-intStartI)+")").css('display','none');
	//$("div.cssPhoto div.cssLeftPanel div.cssItemHeader img:eq("+intStartI+")").css('display','block');
		
	$("div.cssPhoto div.cssRightPanel div.cssItemImage img").remove();
	$("#vtpreview").remove();
	var objImg = new Image();
	
	//alert(intPos);
	$(objImg).attr('id',"mzz0");
	$(objImg).load( 
		function()
		{
			//strII = ($(this).attr('z'));
			$("div.cssPhoto div.cssRightPanel div.cssItemImage").append(this);
					
			//02px;height:335px;
			intCW = $(this).width();
			intCH = $(this).height();
			$(this).css("height" , 432);
			intCW = intCW / intCH * 432;
			$(this).css("width" , intCW);
			//alert(intCW);
			$(this).css("margin-left",(646 - intCW ) / 2 );
			//$(this).css("margin-top",(335 - intCH ) / 2 );
					
					
		}
	).attr('src',aryPathA[intStartI][1]+'/'+aryImg[intStartI][0]+".jpg");
}

function jsNextImage(i)
{
	intStep = (i == 1 )? 1 : -1 ;
	intNewStep = intStep + intCurPos;
	
	if (intNewStep > 0 &&  intNewStep <= aryImg[intStartI].length )
	{
		//alert(intNewStep);
		funShowImg(intNewStep - 1);
		intCurPos = intNewStep;
		
		if (intStep > 0 && (intCurPos - 1 )% intNumRow == 0 )
		{
			jsSwapPage(1)
		}
		else if (intStep < 0 &&  (intCurPos - 1) % intNumRow == intNumRow - 1)
		{
			jsSwapPage(-1)
		}
	}
}

function funShowImg(j)
{
	$("div.cssPhoto div.cssRightPanel div.cssItemImage img").css("display","none");
	if ($("#mzz"+j).length > 0 )
	{
		$("#mzz"+j).css("display","block");
	}
	else
	{
		var objImg = new Image();
		$(objImg).attr('id',"mzz"+(j));
		$(objImg).load( 
			function()
			{
				//strII = ($(this).attr('z'));
				$("div.cssPhoto div.cssRightPanel div.cssItemImage").append(this);
					
				//02px;height:335px;
				intCW = $(this).width();
				intCH = $(this).height();
				$(this).css("height" , 432);
				intCW = intCW / intCH * 432;
				$(this).css("width" , intCW);
				$(this).css("margin-left",(646 - intCW ) / 2 );
				//alert(intCW);
				//$(this).css("margin-top",(335 - intCH ) / 2 );
					
					
			}
		).attr('src',aryPathA[intStartI][1]+'/'+aryImg[intStartI][j]+".jpg");
	}
}

function jsSwapPage(i)
{
	i = parseInt(i) + intPos;
	if (i > 0 && i <= intTotalPage )
	{
		//intCPos = intPos;
		intPos = i;
		intJJ = 0;
		
		$("div.cssPhoto div.cssLeftPanel div.cssItemThum div").each(
			function()
			{
				if (!$(this).hasClass('cssCtl'))
				{
					$(this).remove();
				}
				else
				{
					$(this).css('display','block');
				}
			}
		);
		
		$("div.cssPhoto div.cssLeftPanel div.cssItemThum").html("");
		//alert(((intPos-1)*intNumRow)+" "+(intPos * intNumRow));
		for (var j=(intPos-1)*intNumRow;j<aryImg[intStartI].length && j < intPos * intNumRow ;j++)
		{
			//$("div.cssPhoto div.cssLeftPanel div.cssItemThum ul li:eq("+(intJJ)+")").after("<li id='zz"+(j+1)+"'></li>");
			//alert($("div.cssPhoto div.cssLeftPanel div.cssItemThum div:eq("+(intJJ)+")").length);
			$("div.cssPhoto div.cssLeftPanel div.cssItemThum").append("<div id='zz"+(j+1)+"'></div>");
			intJJ++;
			var objImg = new Image();
			$(objImg).attr('z',"zz"+(j+1));
			$(objImg).load(
				function()
				{
					strII = ($(this).attr('z'));
					$("#"+strII).append(this);
					
					intCH = ($(this).height());
					$(this).css('margin-top', (40 - intCH) / 2);
				}
			).attr('src',aryPathA[intStartI][0]+'/'+aryImg[intStartI][j]+".jpg");
			
			$("#zz"+(j+1)).mouseover(
				function()
				{
					$(this).css('cursor','pointer');
				}
			);
			
			$("#zz"+(j+1)).attr('qi',j);
			$("#zz"+(j+1)).click(
				function()
				{
					funShowImg($(this).attr('qi'));
				}
			);
		}
		
		$("div.cssPhoto div.cssLeftPanel div.cssItemThum").append("<div class='cssClear'></div>");
		$("div.cssPhoto div.cssLeftPanel div.cssItemThumCtl div.cssCtl:eq(0)").css('display',((intPos <= 1)? "none" : "block"));
		$("div.cssPhoto div.cssLeftPanel div.cssItemThumCtl div.cssCtl:eq(1)").css('display',((intPos >= intTotalPage)? "none" : "block"));
	}
}

/* ******************************************************* */

function funloadedItem()
{
	//alert($("div.cssPhotoClips table:eq(1)").length);
	$("div.cssPhotoClips table:eq(1)").css('display','none');
	$("div.cssPhotoClips table tr td").each(
		function()
		{
			$(this).mouseover(
				function()
				{
					$(this).click(
						function()
						{
							aryPath = $(this).children('img').attr('src').split("/");
							strPath = "";
							
							for (z=0;z<aryPath.length;z++)
							{
								if (z == aryPath.length - 1)
									strPath += aryPath[z];
								else if (z == aryPath.length - 2)
									strPath += "large/";
								else
									strPath += aryPath[z]+"/";
							}
							
							jsLoadImg(strPath);
						}
					);
					
					$(this).mouseover(
						function()
						{
							$(this).css('cursor','pointer');
						}
					);
				}
			);
		}
	);
	
	jsLoadImg('images/photo/HK/large/01.jpg');
}

function funloadedItem1()
{
	$("div.cssPhotoClips table tr td").each(
		function()
		{
			$(this).mouseover(
				function()
				{
					$(this).click(
						function()
						{
							aryPath = $(this).children('img').attr('src').split("/");
							strPath = "";
							
							for (z=0;z<aryPath.length;z++)
							{
								if (z == aryPath.length - 1)
									strPath += aryPath[z];
								else if (z == aryPath.length - 2)
									strPath += "large/";
								else
									strPath += aryPath[z]+"/";
							}
							
							jsLoadImg(strPath);
						}
					);
					
					$(this).mouseover(
						function()
						{
							$(this).css('cursor','pointer');
						}
					);
				}
			);
		}
	);
	
	jsLoadImg('images/photo/SH/large/01.jpg');
}

function jsLoadImg(strPath)
{
	$("div.cssPhotoPreview").children().remove();
	
	img = new Image();
	$(img).load(
		function()
		{
			$("div.cssPhotoPreview").append($(this));
			
			$(this).hide();
			var intW = $(this).width() ;
			var intH = $(this).height() ;
			/*
			if (intW > 855)
			{
				$(this).css('width' , 855);
				intW = 855;
			}
			
			if ($(this).height() > 380)
			{
				$(this).css('height' , 380);
				intH = 380;
			}
			
			$(this).css('margin-top', (380 - $(this).height()) / 2);
			*/
			$(this).css('margin-top', 0);
			$("div.cssPhotoPreview img:eq(0)").show();
		}
	).attr('src',strPath);
}

function jsShowPage(i)
{
	$("div.cssPhotoClips table:eq("+(i)+")").css('display','block');
	$("div.cssPhotoClips table:eq("+(1-i)+")").css('display','none');
}
