﻿var nUserAgent = navigator.userAgent;
var nAppVersion	= navigator.appVersion;
var nAppName = navigator.appName;
var nMimeTypes = navigator.mimeTypes;
var dUrl = document.URL;

var OPERA = (nUserAgent.indexOf("Opera", 0) != -1);
var FIREFOX = (nUserAgent.indexOf("Firefox", 0) != -1);
var SAFARI = (nUserAgent.indexOf("Safari", 0) != -1);
var WIN = (nUserAgent.indexOf("Win", 0) != -1);
var MAC = (nUserAgent.indexOf("Mac", 0) != -1);

var fDivId = "flasharea";
var scrollTimer;
var stageHeight;

// initialize
function init(flaVer, id, swfPath, ww, hh, bgColor, salign)
{
	if(hasPlugin(flaVer))
	{
		hideArea("htmlarea");

		var flashArgs				= new Object();
		flashArgs.id				= id;
		flashArgs.width				= ww;
		flashArgs.height			= hh;
		flashArgs.file				= swfPath;
		flashArgs.bgcolor			= bgColor;
		flashArgs.language			= 1;
		flashArgs.quality			= "HIGH";
		flashArgs.menu				= false;
		flashArgs.scale				= "noscale";
		flashArgs.salign			= salign;
		flashArgs.wmode				= "opaque";

		createFlashArea(flashArgs);
	}
	else
	{
		
	}
}

// hide content
function hideArea(id)
{
	document.getElementById(id).style.display = "none";
	document.getElementById(id).style.visibility = "hidden";
}

// show content
function showArea(id)
{
	document.getElementById(id).style.display = "block";
	document.getElementById(id).style.visibility = "visible";
}

// show flash
function createFlashArea(args)
{
	document.open();
	with(document)
	{
		write('<div id="' + fDivId + '">');
		write(getFlashTag(args));
		write('</div>');
	}
	document.close();
}

// set flash area
function initFlashArea(hh)
{
	setStageHeight(hh);
	stageHeight = hh;
}

// show Html area
function showHtmlPage()
{
	hideArea(fDivId);
	showArea("htmlver");
	window.scroll(0, 0);
}

function openWindow(url,target,toTop)
{
	window.open(url,target);
	var w = window.open( url, target );
	if(toTop==true)
		w.focus();
}

function setStageHeight(toH, toY)
{
	if(FIREFOX)
	{
		document.getElementById(fDivId).style.height = toH + "px";
	}
	else
	{
		eval(fDivId).style.height = toH + "px";
	}

	if(toY)
	{
		window.scroll(0, toY);
	}
	else
	{
		window.scroll(0, 0);
	}
}

function getViewportArea()
{
	return {
		x: document.body.scrollLeft || document.documentElement.scrollLeft,
		y: document.body.scrollTop  || document.documentElement.scrollTop,
		width: getViewportWidth(),
		height: getViewportHeight()
	}
}

// get width of browser's viewport 
function getViewportWidth()
{
	if(window.innerWidth)
	{
		return window.innerWidth;
	}
	else if(document.documentElement.clientWidth)
	{
		return document.documentElement.clientWidth;
	}
	else if(document.body)
	{
		return document.body.clientWidth;
	}
	return null;
}

// get height of browser's viewport 
function getViewportHeight()
{
	if(window.innerHeight)
	{
		return window.innerHeight;
	}
	else if(document.documentElement.clientHeight)
	{
		return document.documentElement.clientHeight;
	}
	else if (document.body)
	{
		return document.body.clientHeight;
	}
	return null;
}

// move browser's scroll bar
function moveScrollbar(hh)
{
	var rectHeight = getViewportArea().height;
	var sy = hh - (rectHeight / 2);
	
	var areaHeight = stageHeight - rectHeight;
	if(sy > areaHeight) sy = areaHeight;
	frameScroll(sy);
}

function frameScroll(toY)
{
	if(scrollTimer) clearTimeout(scrollTimer);
	if(!toY || toY < 0) toY = 0;
	var nowY = getViewportArea().y;

	nowY += (toY - nowY) * 0.3;
	if(Math.abs(toY - nowY) <= 0.5)
	{
		nowY = toY;
	}

	window.scroll(0, nowY);

	if(Math.abs(nowY - toY) < 3)
	{
		clearTimeout(scrollTimer);
	}
	else
	{
		scrollTimer = setTimeout("frameScroll("+toY+")", 30);
	}
}
