var imageA;
var threadA;
var threadB;

function setPreviewBox()
{
	preview.style.posLeft = event.x + 10 + document.body.scrollLeft;
	preview.style.posTop = event.y + 10 + document.body.scrollTop;
}

function showPreview(filename)
{
	if (filename != "")
	{
		var text;
		text = "<table cellpadding='0' cellspacing='0' bgcolor='white' border-style:solid;'>";
		text += "<tr align='center'><td><img alt='' src='" + filename + "' width='200' height='150' /></td></tr></table>";
		preview.innerHTML = text;
		preview.style.visibility = "visible";
	}
}

function hidePreview()
{
	preview.innerHTML = "";
	preview.style.visibility = "hidden";
}

function openImage(filename, filename2)
{
	imageA = new Image();
	imageA.src = filename;

	if (filename2 == null)
	{
		filename2 = filename;
	}

	if (threadB != 0)
	{
		clearTimeout(threadB);
	}

	threadB = setTimeout("openImageStop()", 3000);
	isComplete(filename2);
}

function isComplete(filename)
{
	if (!imageA.complete)
	{
		threadA = setTimeout("isComplete('" + filename+ "')", 200);
		return;
	}

	threadA = 0;
	openImagePrivate(filename);
}

function openImageStop()
{
	if (threadA != 0)
	{
		clearTimeout(threadA);
		alert("File Not Found.");
	}
}

function openImagePrivate(filename)
{
	var left = 0;
	var top = 0;
	var width = imageA.width;
	var height = imageA.height;
	var scroll = "no";

	if (width >= screen.availWidth)
	{
		width = screen.availWidth;
		scroll = "yes";
	}

	if (height >= screen.availHeight)
	{
		height = screen.availHeight;
		scroll = "yes";
	}

	if (width < screen.availWidth)
	{
		left = (screen.availWidth - width) / 2;
	}

	if (height < screen.availHeight)
	{
		top = (screen.availHeight - height) / 2;
	}

	var img = window.open("/viewImage.do?filename=" + filename, "img", "left=" + left + ",top=" + top + ",width=" + width + ",height=" + height + ",toolbars=no,scrollbars=" + scroll);

	if (img != null)
	{
		img.focus();
	}
	else
	{
		alert("팝업이 차단되었습니다. 팝업차단을 해제하세요.");
	}
}

function showMulti(filename, width, height)
{
	var size = "";

	if (width != 0)
	{
		size += "width='" + width + "' height='" + height +"' ";
	}

	var temp = filename.toLowerCase().split(".");
	var ext = temp[temp.length - 1];

	if (filename == "")
	{
		return;
	}
	else if (ext == "jpg" || ext == "gif" || ext == "bmp" || ext == "png")
	{
		document.open();
		document.write("<img src='" + filename + "' " + size + "border='0' align='absmiddle' />");
		document.close();
	}
	else if (ext == "asf" || ext == "mpg" || ext == "mpeg" || ext == "wmv" || ext == "wma" || ext == "mp3" || ext == "avi")
	{
		document.open();
		document.write("<embed src='" + filename + "' " + size + "align='absmiddle' />");
		document.close();
	}
	else if (ext == "swf")
	{
		document.open();
		document.writeln("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' " + size + ">");
		document.writeln("<param name='movie' value='" + filename + "'>");
		document.writeln("<param name='quality' value='high'>");
		document.writeln("<param name='wmode' value='transparent' />");
		document.writeln("<embed src='" + filename + "' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' " + size + "></embed>");
		document.write("</object>");
		document.close();
	}
	else
	{
		document.open();
		document.write("<img src='" + filename + "' " + size + " border='0' />");
		document.close();
	}
}

function showMultiLink(title, url, target, filename, width, height)
{
	var size = "";

	if (width != 0)
	{
		size += "width='" + width + "' height='" + height +"' ";
	}

	var temp = filename.toLowerCase().split(".");
	var ext = temp[1];

	if (filename == "")
	{
//		alert(title + "은 글씨다.");
		document.open();
		document.write("<a href='" + url + "' target='" + target + "'><b>" + title + "</b></a>");
		document.close();
	}
	else if (ext == "jpg" || ext == "gif" || ext == "bmp" || ext == "png")
	{
//		alert(title + "은 그림이다.");
		document.open();
		document.write("<a href='" + url + "' target='" + target + "'><img src='" + filename + "' " + size + "border='0' align='absmiddle' /></a>");
		document.close();
	}
	else if (ext == "swf")
	{
//		alert(title + "은 플래쉬다.");
		document.open();
		document.writeln("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0' " + size + ">");
		document.writeln("<param name='movie' value='" + filename + "' />");
		document.writeln("<param name='quality' value='high' />");
		document.writeln("<param name='wmode' value='transparent' />");
		document.writeln("<embed src='" + filename + "' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' " + size + "></embed>");
		document.write("</object>");
		document.close();
	}
	else
	{
//		alert(title + "은 모르겠다.");
		document.open();
		document.write("<a href='" + url + "' target='" + target + "'><img src='" + filename + "' " + size + "border='0' /></a>");
		document.close();
	}
}

function showFlash(filename, width, height, menuKey)
{
	document.open();
	document.writeln("<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0' width='" + width + "' height='" + height + "' id='menu' align='middle'>");
	document.writeln("<param name='allowScriptAccess' value='sameDomain' />");
	document.writeln("<param name='movie' value='" + filename + "' />");
	document.writeln("<param name='quality' value='high' />");
	document.writeln("<param name='wmode' value='transparent' />");
	document.writeln("<param name='bgcolor' value='#ffffff' />");
	document.writeln("<param name='FlashVars' value='m=" + menuKey + "' />");
	document.writeln("<embed src='" + filename + "' quality='high' wmode='transparent' bgcolor='#ffffff' width='" + width + "' height='" + height + "' name='menu' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />");
	document.write("</object>");
	document.close();
}

function resizeImage()
{
	for (var i = 0; i < document.images.length; i++)
	{
		if (document.images[i].name == "boardImage" && document.images[i].complete)
		{
			if (document.images[i].width > 500)
			{
				document.images[i].width = 500;
			}
		}
	}
}

function showMultiBoard(filename, filename2)
{
	var temp = filename.toLowerCase().split(".");
	var ext = temp[temp.length - 1];

	if (filename == "")
	{
		return;
	}
	else if (ext == "jpg" || ext == "gif" || ext == "bmp" || ext == "png")
	{
		document.open();
		document.write("<img alt='' name='boardImage' src='" + filename + "' onclick='openImage(\"" + filename + "\", \"" + filename2 + "\")' border='0' style='cursor:hand' align='absmiddle' />");
		document.close();
	}
	else if (ext == "asf" || ext == "mpg" || ext == "mpeg" || ext == "wmv" || ext == "wma" || ext == "mp3" || ext == "avi")
	{
		document.open();
		document.write("<embed src='" + filename + "' autostart='false' />");
		document.close();
	}
	else if (ext == "swf")
	{
		document.open();
		document.writeln("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' width='400' height='300'>");
		document.writeln("<param name='movie' value='" + filename + "'>");
		document.writeln("<param name='quality' value='high'>");
		document.writeln("<param name='wmode' value='transparent' />");
		document.writeln("<embed src='" + filename + "' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='400' height='300'></embed>");
		document.write("</object>");
		document.close();
	}
}

