/* Javascript Doc Version 1.3 y.s. */

function SubWindow()
{
	var szSubWindow = [500, 350, 500*0.9, 350*0.9, 500*1.02, 350*1.02];	// Size date of this animation.
	var ptSubWindow = [430, 650, 20]; 									// Animation: for IE, for other browsers, distance.
	var isOpened = false;
	
	var imgWidgets =
	[
		"img/subWindow_bg.gif",
		"img/btnClose.gif"
	];
	for ( var i = 0; i < imgWidgets.length; i++)
		imgWidgets[i] = $("<img>").attr("src", imgWidgets[i]);
	
	// Make it easy to recognise.
	var subWindow_bg = imgWidgets[0];
	var btnClose = imgWidgets[1];
	
	var main = $("<div>"); // Don't use the "<div>Content</div>", this is a jquery bug.
	$("#compment").prepend(main);
	$(main).append(subWindow_bg);
	$(main).append(btnClose);
	$(main).css(
		{
			width:szSubWindow[0],
			height:szSubWindow[1],
			margin:'auto',
			opacity:0,
			display:'none',
			overflow:'hidden'
		}
	);
	$(subWindow_bg).css("opacity", 0.85);
	
	$(btnClose).css({ top:15, cursor:'pointer', marginTop:1, zIndex:10000 });
	$(btnClose).hover(
		function(){ $(this).css({ opacity:1,   marginTop:0 }); },
		function(){ $(this).css({ opacity:0.8, marginTop:1 }); }
	);
		
	// Click the Close button to close it.
	$(btnClose).click(Close);
	
	// Click outside the subWindow to close it.
	$("#compment *").click(function(e){ e.stopPropagation(); });
	$("body").click(function(){ if(isOpened) Close(); });

	// Show subWindow animation.
	this.Show = function()
	{
		isOpened = true;
		// SubWindow Bg Animation.
		$(subWindow_bg).css(
			{
				width:szSubWindow[2],
				height:szSubWindow[3],
				margin:'auto'
			}
		);
		$(main).css("display", "inline");
		$(main).animate(
			{
				opacity:'1'
			},
			300
		);
		$(subWindow_bg).animate(
			{
				width:szSubWindow[4],
				height:szSubWindow[5]
			},
			200,
			function()
			{
				$(this).animate(
					{
						width:szSubWindow[0],
						height:szSubWindow[1]
					},
					100
				);
			}
		);
		
		// Close Button Animation
		if($.browser.msie)	// Browser Compatibility Setting
		{
			$(btnClose).css(
				{
					opacity:0.8,
					position:'absolute',
					left:ptSubWindow[0]
				}
			);
			$(btnClose).animate(
				{
					left:ptSubWindow[0] + ptSubWindow[2]
				},
				200
			);
		}
		else
		{
			$(btnClose).css(
				{
					opacity:0.8,
					position:'absolute',
					left:ptSubWindow[1]
				}
			);
			$(btnClose).animate(
				{
					left:ptSubWindow[1] + ptSubWindow[2]
				},
				200
			);
		}
	}

	// Close subWindow animation.
	function Close()
	{
		isOpened = false;
		
		$(subWindow_bg).animate(
			{
				width:szSubWindow[2],
				height:szSubWindow[3]
			},
			200
		);
		$(main).animate(
			{
				opacity:'0'
			},
			200,
			function(){ $(this).css("display","none"); }
		);
		$("#subject").fadeOut("fast");
		
		if($.browser.msie)	// Browser Compatibility Setting
		{
			$(btnClose).animate(
				{
					left:ptSubWindow[0]
				},
				200
			);
		}
		else
		{
			$(btnClose).animate(
				{
					left:ptSubWindow[1]
				},
				200
			);
		}
	}
}

