var strBaseUrlPath = "";
var strFileName = "";
var strFullName = "";
var aryQuery = [];

$(
	function()
	{
		initQS();
		initEnv();
		
		$("#footer").load("footer.html" , 
			function(e)
			{
				if (getQS("fs") > 0 )
				{
					var intNu = parseInt(getQS("fs"));
					$("#footer").find(".cssMenuItem:eq("+((intNu - 1 )* 2)+")").find("a:eq(0)").addClass("cssPicked");
					//alert($("#footer").find(".cssMenuItem:eq("+((intNu - 1 )* 2)+")").length);
				}
			}
		);
		
		$("#menu").load("menu.html" , 
			function(e)
			{
				initMenu();
			}
		);	
		
		//if (intJSInitNO != undefined)
		//if ( intJSInitNO != 1)
		if (strFileName != "reservation_promotion")
		if ($(".cssScrollPanel").length > 0 )
		{
			$(".cssScrollPanel").each(
				function()
				{
					$(this).jScrollPane( 
						{
							trackClickSpeed : 5 
							//verticalDragMaxHeight : 40,
							//verticalDragMinHeight : 40

						} 
					);

				}
			);
		}
		
		//alert($("img.cssEnlarge").length);
		$("img.cssEnlarge").each(
			function()
			{
				//alert('123');
				$(this).click(
					function()
					{
						//window.open($("#enlarge").attr("enlarge"));
					}
				);
				
				$(this).mouseout(
					function()
					{
						$("#enlarge").remove();
						objEnlarge = $("#enlarge");
						$(this).parent().css('cursor', "pointer");
					}
				);
				
				$(this).mousemove(
					function(e)
					{
						objEnlarge = $("#enlarge");
						$(this).parent().css('cursor', "none");
						
						objEnlarge.css('top' , e.clientY + 10);//intT + intH - 16);
						objEnlarge.css('left' ,e.clientX + 10);// intL + intW - 16 );
					}
				);
				
				$(this).mouseover(
					function(e)
					{
						//$(this).parent().css('cursor', "none");
						//alert($(this).css('cursor'));
						$(this).css("cursor" , "none");
						$(this).parent().css("cursor" , "none");
						//$(this).parent().addClass('cur');//.css('cursor', "default");
						
						var intW = $(this).width();
						var intH = $(this).height();
						var intL = $(this).offset().left;
						var intT = $(this).offset().top;
						
						if ($("#enlarge").length == 0 )
						{
						
							objEnlarge = $("<div id='enlarge' style='border-style:solid;border-width:0px;'><img src='images/events/magnifier.png' /></div>");
							$("body").append(objEnlarge);
							objEnlarge.css('position' , 'absolute');
							objEnlarge.css('z-index' , '30');
							objEnlarge.css('top' , e.clientY + 10 );//intT + intH - 16);
							objEnlarge.css('left' ,e.clientX + 10);// intL + intW - 16 );
						}
						//*/
						//$(this).css('cursor' , 'none');
						
					}
				);
			}
		);
		
		
		funResizeFrame();
		
		$(window).resize(
			function()
			{
				funResizeFrame();
			}
		);
		
		$(".cssMOver").each(
			function()
			{
				$(this).find("img").hide();
				$(this).find("img:eq(0)").show();
				
				$(this).mouseover(
					function()
					{
						$(this).find("img").hide();
						$(this).find("img:eq(1)").show();
					}
				);
				
				$(this).mouseout(
					function()
					{
						$(this).find("img").hide();
						$(this).find("img:eq(0)").show();
					}
				);
			}
		);
		
		
		
		$("img").each(
			function()
			{
				//alert('123');
				var strSrcPath = $(this).attr('src');
				if (strSrcPath.substr(0,4).toLowerCase() != "http")
					$(this).attr('src' , strBaseUrlPath+strSrcPath);
				
				
			}
		);
		
		$("a").each(
			function()
			{
				//alert('123');
				var strSrcPath = $(this).attr('href');
				
				if (strSrcPath.substr(0,4).toLowerCase() != "http")
					$(this).attr('href' , strBaseUrlPath+strSrcPath);
					
					
			}
		);
	}
);

function funResizeFrame()
{
	var intH = $(window).height();
	var intFH = $(".cssMasterPanel").height();
	
	
	if (intH > intFH )
	{
		//alert((intH - intF) / 2);
		$(".cssMasterPanel").css('margin-top' , (intH - intFH) / 2 );
	}
	else
		$(".cssMasterPanel").css('margin-top' , "2px");
}

function initQS()
{
	strPath = window.location.href ;
	aryPath = strPath.split("/");
	aryPathInfo = aryPath[aryPath.length-1].split(".");
	strFullName = aryPath[aryPath.length-1];
		
	strFileName = aryPathInfo[0];
	strQuery = "";
	
	for (var i=1;i<aryPathInfo.length;i++)
	{
		strQuery += aryPathInfo[i];
	}
	
	aryQS = strQuery.split("?");
	aryQuery = [];
	if (aryQS.length > 1 )
	{
		aryRow = aryQS[1].split("&");
		for (var i=0;i<aryRow.length;i++)
		{
			aryField = aryRow[i].split("=");
			var objCell = new Object();
			objCell.name = aryField[0];
			objCell.value = aryField[1];
			aryQuery[i] = objCell;
		}
	}
}

function getQS(strName)
{
	var strV = null;
	
	for (var i=0;i<aryQuery.length;i++)
	{
		if (aryQuery[i].name == strName )
		{
			strV = aryQuery[i].value;
			break;
		}
	}
	
	return strV;
}

function initEnv()
{
	switch (strFileName)
	{
		default:
			init_index();
		break;
	}
}

/* Index */

function init_index()
{
	
	$.ajax(
		{
			url: "data/index.xml",
			data: {},
			success: function(data)
			{
				
				$(data).find("item").each(
						function()
						{
							strID = ($(this).find("slot").text());
							strImg = ($(this).find("url").text());
							strUrl = ($(this).find("link").text());
							intNew = ($(this).find("newwin").text());
							
							strBanner = "<img src='"+strImg+"' />";
							objImg = $(strBanner);
							$("#"+strID).html("");
							
							//alert(strUrl);
							$("#"+strID).append(objImg);
							
							if (strUrl != "")
							{
								objImg.data('l' , strUrl );
								objImg.data('n' , intNew );
								
								objImg.mouseover( function() {$(this).css('cursor' , 'pointer') } );
								
								objImg.click(
									function()
									{
										if ($(this).data("n") == 1)
										{
											window.open($(this).data("l"));
										}
										else
										{
											window.location.href = $(this).data("l");
										}
									}
								);
							}
						}
					);
			}
		}
	);
	
	
	/*
	$.post("data/index.xml" , {} , 
		function(data)
		{
			$(data).find("item").each(
				function()
				{
					strID = ($(this).find("slot").text());
					strImg = ($(this).find("url").text());
					strUrl = ($(this).find("link").text());
					intNew = ($(this).find("newwin").text());
					
					strBanner = "<img src='"+strImg+"' />";
					objImg = $(strBanner);
					$("#"+strID).html("");
					
					$("#"+strID).append(objImg);
					
					if (strUrl != "")
					{
						objImg.data('l' , strUrl );
						objImg.data('n' , intNew );
						
						objImg.mouseover( function() {$(this).css('cursor' , 'pointer') } );
						
						objImg.click(
							function()
							{
								if ($(this).data("n") == 1)
								{
									window.open($(this).data("l"));
								}
								else
								{
									window.location.href = $(this).data("l");
								}
							}
						);
					}
				}
			);
		}
	);
	*/
}

/* End of Index */
