//<![CDATA[

// window event controller.
var windowEvents = {};
window.addEvent = function () {
	if (arguments.length != 2) {
		return false;
	} else {
		var eventType = arguments[0];

		if (!windowEvents[eventType])
			windowEvents[eventType] = new Array();
		windowEvents[eventType].push(arguments[1]);

		window[arguments[0]] = function (e) {
			var objEvent = e || window.event;

			if (!!windowEvents['on' + objEvent.type] && windowEvents['on' + objEvent.type].length > 0) {
				for (var i=0; i<windowEvents['on' + objEvent.type].length; i++) {
					windowEvents['on' + objEvent.type][i]();
				}
			}
		}

		return true;
	}
}

var Browser = function () {};
Browser.prototype.isIE = (navigator.userAgent.indexOf('MSIE')>=0 && document.all);
Browser.prototype.isIE6 = (navigator.userAgent.indexOf('MSIE 6.')>=0  && document.all);
Browser.prototype.isFirefox = (navigator.userAgent.indexOf('Firefox')>=0 || navigator.userAgent.indexOf('IceWeasel')>=0);
Browser.prototype.isSafari = (navigator.userAgent.indexOf('Safari')>=0);
Browser.prototype.isSafari3 = (navigator.userAgent.indexOf('Safari')>=0 && navigator.userAgent.indexOf('Version/3')>0);
Browser.prototype.isOpera = (!Browser.prototype.isIE&&(navigator.userAgent.indexOf('Opera')>=0));
Browser.prototype.isMozilla = (!Browser.prototype.isIE && !Browser.prototype.isFirefox && !Browser.prototype.isSafari && !Browser.prototype.isOpera && (navigator.userAgent.indexOf('Mozilla')>=0));
var objBrowser = new Browser();

var ELEMENT_NODE = 1;
var ATTRIBUTE_NODE = 2;
var TEXT_NODE = 3;

// extend Object. inspired by Prototype.
Object.extend = function(target, source) {
	for (var property in source)
		target[property] = source[property];
	return target;
}

// extend Elements.
Object.extend(Object, {
	createHTMLElement: function (tag, data) {
		var objElement = document.createElement(tag);

		for (prop in data) {
			switch (prop.toLowerCase()) {
			case 'classname':
				objElement.className = data[prop];
				break;
			case 'onclick':
				objElement.onclick = data[prop];
				break;
			default:
				objElement.setAttribute(prop, data[prop]);
				break;
			}
		}

		return objElement;
	},

	calcOptimizedImageSize: function (argWidth, argHeight, boxWidth, boxHeight, resizeFlag) {
		if (!resizeFlag) resizeFlag = 'reduce';

		if (!boxWidth && !boxHeight) {
			return array(argWidth, argHeight);
		} else if (!!boxWidth && !boxHeight) {
			if (argWidth > boxWidth) {
				newWidth = boxWidth;
				newHeight = Math.ceil(argHeight * newWidth / argWidth);
			} else {
				newWidth = argWidth;
				newHeight = argHeight;
			}
		} else if (!boxWidth && !!boxHeight) {
			if (argHeight > boxHeight) {
				newHeight = boxHeight;
				newWidth = Math.ceil(argWidth * newHeight / argHeight);
			} else {
				newWidth = argWidth;
				newHeight = argHeight;
			}
		} else {
			if (argWidth > boxWidth) {
				newWidth = boxWidth;
				newHeight = Math.ceil(argHeight * newWidth / argWidth);
			} else {
				newWidth = argWidth;
				newHeight = argHeight;
			}

			if (newHeight > boxHeight) {
				tempHeight = newHeight;
				newHeight = boxHeight;
				newWidth = Math.ceil(newWidth * newHeight / tempHeight);
			}
		}

		if (argWidth * argHeight > newWidth * newHeight) {
			if (resizeFlag == 'reduce' || resizeFlag == 'both') {
				imgWidth = newWidth;
				imgHeight = newHeight;
			} else {
				imgWidth = argWidth;
				imgHeight = argHeight;
			}
		} else if (argWidth * argHeight == newWidth * newHeight) {
			imgWidth = argWidth;
			imgHeight = argHeight;
		} else if (argWidth * argHeight < newWidth * newHeight) {
			if (resizeFlag == 'enlarge' || resizeFlag == 'both') {
				imgWidth = newWidth;
				imgHeight = newHeight;
			} else {
				imgWidth = argWidth;
				imgHeight = argHeight;
			}
		}

		return {width:imgWidth, height:imgHeight};
	},

	get: function (id) {
		return document.getElementById(id);
	},

	getChildNodes: function () { // [0]:object, [1]:tag name, [2]:class name, [3]:only element
		if (Object.isElement(arguments[0]) != 1)
			return [];
		if (arguments[0].childNodes.length == 0)
			return [];

		if (!arguments[1])
			var targetNodeName = null;
		else
			var targetNodeName = arguments[1].toLowerCase();

		var targetClassName = (arguments.length < 3) ? null : arguments[2];
		var onlyElement = (arguments[3] == undefined) ? true : !!arguments[3];

		var resultArray = new Array();

		if (onlyElement == true) {
			for (var i=0; i<arguments[0].childNodes.length; i++) {
				if (Object.isElement(arguments[0].childNodes[i])) {
					if (targetNodeName == null) {
						if (targetClassName == null || arguments[0].childNodes[i].className == targetClassName)
							resultArray.push(arguments[0].childNodes[i]);
						else
							continue;
					} else {
						if (arguments[0].childNodes[i].nodeName.toLowerCase() == targetNodeName) {
							if (targetClassName == null || arguments[0].childNodes[i].className == targetClassName)
								resultArray.push(arguments[0].childNodes[i]);
							else
								continue;
						} else {
							continue;
						}
					}
				} else {
					continue;
				}
			}
		} else {
			resultArray = arguments[0].childNodes;
		}

		return resultArray;
	},

	getFirstChild: function () { // [0]:object, [1]:boolean
		if (Object.isElement(arguments[0]) != 1)
			return null;
		if (arguments[0].childNodes.length == 0)
			return null;

		var onlyElement = (arguments[1] == undefined) ? true : !!arguments[1];

		for (var i=0; i<arguments[0].childNodes.length; i++) {
			if (onlyElement) {
				if (Object.isElement(arguments[0].childNodes[i]))
					return arguments[0].childNodes[i];
			} else {
				return arguments[0].childNodes[0];
			}
		}

		return null;
	},

	getLastChild: function () { // [0]:object, [1]:boolean
		if (Object.isElement(arguments[0]) != 1)
			return null;
		if (arguments[0].childNodes.length == 0)
			return null;

		var onlyElement = (arguments[1] == undefined) ? true : !!arguments[1];

		for (var i=arguments[0].childNodes.length-1; i>=0; i++) {
			if (onlyElement) {
				if (arguments[0].childNodes[i].isElement())
					return arguments[0].childNodes[i];
			} else {
				return arguments[0].childNodes[arguments[0].childNodes.length-1];
			}
		}

		return null;
	},

	getOffset: function () {
		var objRoot = null;
		var currentObj = document.getElementById(arguments[0]);
		var bLoop = !!arguments[1];
		var data = {left:0, top:0, width:0, height:0}

		data.width = currentObj.offsetWidth;
		data.height = currentObj.offsetHeight;

		switch (bLoop) {
		case true:
			while (!!currentObj && currentObj.nodeName.toLowerCase() != 'body') {
				data.top += currentObj.offsetTop;
				data.left += currentObj.offsetLeft;
				currentObj = currentObj.offsetParent;
			}
			break;
		case false:
			data.top = currentObj.offsetTop;
			data.left = currentObj.offsetLeft;
			break;
		}

		return data;
	},

	getPreviousSibling: function () {
		if (Object.isElement(arguments[0]) != 1)
			return null;

		var onlyElement = (arguments[1] == undefined) ? true : !!arguments[1];
		var objNodeList = this.parentNode.getChildNodes(null, null, onlyElement);

		for (var i=0; i<objNodeList.length; i++) {
			if (objNodeList[i] == arguments[0]) {
				if (!!objNodeList[i - 1])
					return objNodeList[i - 1];
				else
					return null;
			}
		}

		return null;
	},

	getNextSibling: function () {
		if (Object.isElement(arguments[0]) != 1)
			return null;

		var onlyElement = (arguments[1] == undefined) ? true : !!arguments[1];
		var objNodeList = Object.getChildNodes(arguments[0].parentNode, null, null, onlyElement);

		for (var i=0; i<objNodeList.length; i++) {
			if (objNodeList[i] == arguments[0]) {
				if (!!objNodeList[i + 1])
					return objNodeList[i + 1];
				else
					return null;
			}
		}

		return null;
	},

	getParentNode: function () { // [0]:object, [1]:tag name
		if (Object.isElement(arguments[0]) == false || arguments.length != 2)
			return null;

		var currentNode = arguments[0];
		var targetName = arguments[1].toLowerCase();

		while (currentNode != undefined) {
			if (currentNode.nodeName.toLowerCase() == targetName)
				return currentNode;
			else
				currentNode = currentNode.parentNode;
		}

		return null;
	},

	getRealStyle: function () {
		var realstyle = null;

		if (Object.isElement(arguments[0]) && arguments.length == 2) {
			var element = arguments[0];
			var stylename = arguments[1];

			if (element.currentStyle)
				realstyle = element.currentStyle[stylename];
			else
				realstyle = window.getComputedStyle(element, null)[stylename];
		}

		return realstyle;
	},

	getScreenSize: function () {
		if (document.all) {
			// IE4+ or IE6+ in standards compliant
			screenW  = (document.documentElement.clientWidth) ? document.documentElement.clientWidth : document.body.clientWidth;
			screenH = (document.documentElement.clientHeight) ? document.documentElement.clientHeight : document.body.clientHeight;
			screenS = (document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
		} else {
			// TODO: bug in Opera.
			// Non-IE
			screenW = window.innerWidth;
			screenH = window.innerHeight;
			screenS = window.pageYOffset;
		}

		// Core code from - quirksmode.org
		if (window.innerHeight && window.scrollMaxY) {
			wholeW = document.body.scrollWidth;
			wholeH = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
			wholeW = document.body.scrollWidth;
			wholeH = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			wholeW = document.body.offsetWidth;
			wholeH = document.body.offsetHeight;
		}

		return {
			display:{
				width:screenW,
				height:screenH
			},
			whole:{
				width:wholeW,
				height:wholeH
			}
		}
	},

	getOpacity: function (obj) {
		return Object.getRealStyle(obj, 'opacity');
	},

	setOpacity: function (obj, value) {
		if (typeof(obj) == 'string')
			obj = document.getElementById(obj);

		// If it's 100, set it to 99 for Firefox.
		if (navigator.userAgent.indexOf('Firefox') != -1) {
			if (value == 100) { value = 99.9999; } // This is majorly retarded
		}

		// Multi-browser opacity setting
		obj.style.filter = 'alpha(opacity=' + value + ')'; 	// IE/Win
		//obj.KhtmlOpacity = (value / 100);            		// Safari 1.1 or lower, Konqueror
		//obj.MozOpacity = (value / 100);              		// Older Mozilla+Firefox
		obj.style.opacity = (value / 100);                 	// Safari 1.2, Firefox+Mozilla
	},

	isArray: function () {
		return "join" in arguments[0];
	},

	isElement: function () {
		return arguments[0] && arguments[0].nodeType == ELEMENT_NODE;
	}
});

// extend String.
Object.extend(String.prototype, {
	isEmpty: function () {
		if (this == undefined || this == null)
			return true;
		else
			return this.trim() == "";
	},

	trim: function () {
		return this.replace(/(^\s*|\s*$)/g, "");
	}
});

var Flash = function () {
	var base = {
		data:{
			ext:'.swf',
			param:'movie',
			classid:'clsid:d27cdb6e-ae6d-11cf-96b8-444553540000',
			mimetype:'application/x-shockwave-flash'
		}
	}

	this.generateCode = function () {
		var ret = getArgs(arguments[0]);
		return create(ret.objAttrs, ret.params, ret.embedAttrs);
	}

	var create = function (objAttrs, params, embedAttrs) {
		var str = '';

		if (objBrowser.isIE) {
			str += '<object ';
			for (var i in objAttrs)
				str += i + '="' + objAttrs[i] + '" ';
			str += '>';

			for (var i in params)
				str += '<param name="' + i + '" value="' + params[i] + '" /> ';
		}

		str += '<embed ';

		for (var i in embedAttrs)
			str += i + '="' + embedAttrs[i] + '" ';
		str += ' ></embed>';

		if(objBrowser.isIE)
			str += '</object>';

		return str;
	}

	var getArgs = function (data) {
		var ret = new Object();
		ret.embedAttrs = new Object();
		ret.params = new Object();
		ret.objAttrs = new Object();

		for (prop in data) {
			var currArg = prop.toLowerCase();

			switch (currArg){
			case 'classid':
				break;
			case 'pluginspage':
				ret.embedAttrs[prop] = data[prop];
				break;
			case 'src':
			case 'movie':
				data[prop] = addExtension(data[prop], base.data.ext);
				if (!!data.querystring) data[prop] += '?' + data.querystring;

				ret.embedAttrs['src'] = data[prop];
				ret.params[base.data.param] = data[prop];
				break;
			case 'onafterupdate':
			case 'onbeforeupdate':
			case 'onblur':
			case 'oncellchange':
			case 'onclick':
			case 'ondblclick':
			case 'ondrag':
			case 'ondragend':
			case 'ondragenter':
			case 'ondragleave':
			case 'ondragover':
			case 'ondrop':
			case 'onfinish':
			case 'onfocus':
			case 'onhelp':
			case 'onmousedown':
			case 'onmouseup':
			case 'onmouseover':
			case 'onmousemove':
			case 'onmouseout':
			case 'onkeypress':
			case 'onkeydown':
			case 'onkeyup':
			case 'onload':
			case 'onlosecapture':
			case 'onpropertychange':
			case 'onreadystatechange':
			case 'onrowsdelete':
			case 'onrowenter':
			case 'onrowexit':
			case 'onrowsinserted':
			case 'onstart':
			case 'onscroll':
			case 'onbeforeeditfocus':
			case 'onactivate':
			case 'onbeforedeactivate':
			case 'ondeactivate':
			case 'type':
			case 'codebase':
				ret.objAttrs[prop] = data[prop];
				break;
			case 'width':
			case 'height':
			case 'align':
			case 'vspace':
			case 'hspace':
			case 'class':
			case 'title':
			case 'accesskey':
			case 'name':
			case 'id':
			case 'tabindex':
				ret.embedAttrs[prop] = ret.objAttrs[prop] = data[prop];
				break;
			default:
				ret.embedAttrs[prop] = ret.params[prop] = data[prop];
			}
		}

		ret.objAttrs['classid'] = base.data.classid;
		ret.embedAttrs['type'] = base.data.mimetype;

		return ret;
	}

	var addExtension = function (src, ext) {
		if (src.indexOf('?') != -1)
			return src.replace(/\?/, ext+'?');
		else
			return src + ext;
	}
}


// top
function initMoving(name, position, topLimit, btmLimit) {
	var target = document.getElementById(name);
	if (!target)
		return false;

	var obj = target;
	obj.initTop = position;
	obj.topLimit = topLimit;
	if (navigator.userAgent.indexOf("MSIE")>=0  && document.all) {
		obj.bottomLimit = document.documentElement.scrollHeight - btmLimit - 124;
	} else {
		obj.bottomLimit = document.documentElement.scrollHeight - btmLimit;
	}

	obj.style.position = "absolute";
	obj.top = obj.initTop;
	obj.left = obj.initLeft;

	if (typeof(window.pageYOffset) == "number") {
		obj.getTop = function() {
			return window.pageYOffset;
		}
	} else if (typeof(document.documentElement.scrollTop) == "number") {
		obj.getTop = function() {
			return document.documentElement.scrollTop;
		}
	} else {
		obj.getTop = function() {
			return 0;
		}
	}

	if (self.innerHeight) {
		obj.getHeight = function() {
			return self.innerHeight;
		}
	} else if(document.documentElement.clientHeight) {
		obj.getHeight = function() {
			return document.documentElement.clientHeight;
		}
	} else {
		obj.getHeight = function() {
			return 500;
		}
	}

	obj.move = setInterval(function() {
		if (obj.initTop > 0) {
			pos = obj.getTop() + obj.initTop;
		} else {
			pos = obj.getTop() + obj.getHeight() + obj.initTop;
			//pos = obj.getTop() + obj.getHeight() / 2 - 15;
		}

		if (pos > obj.bottomLimit)
			pos = obj.bottomLimit;
		if (pos < obj.topLimit)
			pos = obj.topLimit;

		interval = obj.top - pos;
		obj.top = obj.top - interval / 3;
		obj.style.top = obj.top + "px";
	}, 30)
}


function fl_open()
{
	var objId = document.getElementById('business_roll');
	objId.style.width = '706px';

	if (navigator.userAgent.indexOf("MSIE 6.")>=0  && document.all) {
		var objFrame = document.createElement('iframe');
		objFrame.setAttribute('id', 'business_roll_frame');
		objId.appendChild(objFrame);
		objFrame.style.position = 'absolute';
		objFrame.style.top = '0';
		objFrame.style.left = '0';
		objFrame.style.zIndex = '1';
		objFrame.style.width = '706px';
		objFrame.style.height = '255px';
		objFrame.style.filter = 'Alpha(opacity=0)';
	}
	//alert('a');
	//return "레이어오버"
}
function fl_close()
{
	var objId = document.getElementById('business_roll');
	objId.style.width = '35px';

	if (navigator.userAgent.indexOf("MSIE 6.")>=0  && document.all) {
		var objFrame = document.getElementById('business_roll_frame');
		objId.removeChild(objFrame);
	}

	//alert('b');
	//return "레이어 아웃"
}


try { // IE only
	document.execCommand('BackgroundImageCache', false, true);
} catch(e) { }


function frameResize() {
	var objFrame = document.getElementById('newsLetterFrame');

	var innerDoc = (objFrame.contentDocument) ? objFrame.contentDocument.documentElement : objFrame.contentWindow.document.body;
	//alert(innerDoc.offsetHeight);
	objFrame.style.height = innerDoc.offsetHeight + 'px';

}

// Flash publishing with Cross Browsing
function swfprint(http, furl,fvars,fwidth,fheight,fscript,transoption, Id) {
	if (Id) {
		document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="'+http+'://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" width="'+ fwidth +'" height="' + fheight +'" align="middle" id="'+Id+'" name="'+Id+'">');
	} else {
		document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="'+http+'://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" width="'+ fwidth +'" height="' + fheight +'" align="middle">');
	}
	document.write('<param name="movie" value="'+ furl +'"/>');
	if (fvars) {
		document.write('<param name="flashVars" value="'+ fvars +'"/>');
	}
	document.write('<param name="allowScriptAccess" value="'+ fscript +'"/>');	//sameDomain
//	document.write('<param name="allowScriptAccess" value="always"/>');			//sameDomain
//	document.write('<param name="allowFullScreen" value="false"/>');
//	document.write('<param name="quality" value="high"/>');
	if (transoption == "t") {
		document.write('<param name="wmode" value="transparent"/>');
	} else if (transoption == "o") {
		document.write('<param name="wmode" value="opaque"/>');
	}
	document.write('<!-- Hixie method -->');
	document.write('<!--[if !IE]> <-->');
	if (fvars) {
		document.write('<object type="application/x-shockwave-flash" allowScriptAccess="'+ fscript +'" data="'+ furl + '?' + fvars +'" width="'+ fwidth +'" height="' + fheight +'"');
	} else {
		document.write('<object type="application/x-shockwave-flash" allowScriptAccess="'+ fscript +'" data="'+ furl + '" width="'+ fwidth +'" height="' + fheight +'"');
	}
	
	if (transoption == "t") {
		document.write(' wmode="transparent"');
	} else if (transoption == "o") {
		document.write(' wmode="opaque"');
	}
	if (Id) {
		document.write(' id="'+Id+'" name="'+Id+'"');
	}
	document.write('></object>');
	document.write('<!--> <![endif]-->');
	document.write('</object>');
}

// Movie (Media Player File) Playing publishing with Cross Browsing
function mprint(http,mfile,mstart,mwidth,mheight) {
	document.write('<object classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" width="'+mwidth+'" height="'+mheight+'">');
	document.write('<param name="Filename" value="'+mfile+'" />');
	if (mstart == "0") {
		document.write('<param name="AutoStart" value="false" />');
	} else if (mstart == "1") {
		document.write('<param name="AutoStart" value="true" />');
	}
	document.write('<!--[if !IE]> <-->');
	document.write('<object type="video/x-ms-wmv" data="'+ mfile +'" width="'+ mwidth +'" height="'+ mheight +'" />');
	if (mstart == "0") {
		document.write('<param name="AutoStart" value="0" />');
	} else if (mstart == "1") {
		document.write('<param name="AutoStart" value="1" />');
	}
	document.write('<embed pluginspage="'+http+'://www.microsoft.com/Windows/Downloads/Contents/Products/MediaPlayer/" src="'+ mfile +'" width="'+ mwidth +'" height="'+ mheight +'" type="video/x-ms-wmv" name="plugin"');
	if (mstart == "0") {
		document.write('autostart="0"></embed>');
	} if (mstart == "1") {
		document.write('autostart="1"></embed>');
	}
	document.write('</object>');
	document.write('<!--> <![endif]-->');
	document.write('</object>');
}
//]]>