/**
 * @(#)page_util.js
 *
 * 페이지 유틸리티
 */

// 페이지 온로드 이벤트시 실행할 객체
function PageLoad() {
	this.todo = new Array();

	// 함수 추가
	this.add = function(func) {
		this.todo[this.todo.length] = func;
	}

	// 함수 실행
	this.process = function() {
		for (var i = 0; i < this.todo.length; i++) {
			try {
				eval(this.todo[i]);
			} catch(e) {
				//
			}
		}
	}
}

// 동영상 플래이어 로드
//
// @param id Object 아이디
// @param url 플래시 URL
// @param w 넓이
// @param h 높이
//
function create_player(id, url, w, h) {
	var strObj = '\
	<object id="' + id + '" \
			classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" \
			codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" \
			standby="Loading Microsoft Windows Media Player components..." \
			type="application/x-oleobject" \
			bgcolor="DarkBlue" width="' + w + '" Height="' + h + '" VIEWASTEXT> \
			<param name="FileName" value="' + url + '"> \
			<param name="AutoStart" value="1"> \
			<param name="AutoSize" value="1"> \
			<param name="AnimationAtStart" value="0"> \
			<param name="DisplayMode" value="4"> \
			<param name="Enabled" value="1"> \
			<param name="ShowControls" value="0"> \
			<param name="ShowAudioControls" value="0"> \
			<param name="ShowDisplay" value="0"> \
			<param name="ShowGotoBar" value="0"> \
			<param name="ShowPositionControls" value="0"> \
			<param name="ShowStatusBar" value="0"> \
			<param name="Volume" value="100"> \
			<param name="ShowCaptioning" value="0"> \
			<param name="TransparentAtStart" value="0"> \
			<embed name="' + id + '" Name="MediaPlayer" invokeURLs="false" \
				type="application/x-mpPlayerOnPlayBtn_div" \
				pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/Products/MediaPlayer/" \
				AutoStart="1" \
				AutoSize="1" \
				AnimationAtStart="0" \
				DisplayMode="4" \
				Enabled="1" \
				ShowControls="0" \
				ShowAudioControls="0" \
				ShowDisplay="0" \
				ShowGotoBar="0" \
				ShowPositionControls="0" \
				ShowStatusBar="0" \
				Volume="0" \
				ShowCaptioning="0" \
				TransparentAtStart="1"></embed> \
		</object>';

	document.write(strObj);
}

// 플래시 로드
//
// @param id Object 아이디
// @param url 플래시 URL
// @param width 넓이
// @param height 높이
//
function write_flash(id, url, w, h) {
	var strObj = '\
	<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" \
		codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" \
		width="' + w + '" height="' + h + '" id="' + id + '"> \
		<param name="allowScriptAccess" value="sameDomain" /> \
		<param name="movie" value="' + url + '" /> \
		<param name="quality" value="high" /> \
		<param name=wmode value=transparent  /> \
		<embed src="' + url + '" quality="high" width="' + w + '" height="' + h + '" name="' + id + '" \
			allowScriptAccess="sameDomain" \
			type="application/x-shockwave-flash" \
			pluginspage="http://www.macromedia.com/go/getflashplayer" /> \
	</object>';
	document.write(strObj);
}

// 팝업 창 중앙으로 띄우기
// 보정값은 현재 20
//
// @param url URL
// @param wname 창 이름
// @param w 창 너비
// @param h 창 높이
//
function popupCenterWindow(url, wname, w, h) {
	var gab = 20;
	var wx = (window.screen.width-w)/2;
	var wy = (window.screen.height-h)/2;
	if(wy > gab) {
		wy -= gab;
	}
	var p=window.open(url, wname, "width="+w+",height="+h+",left="+wx+",top="+wy);
	p.focus();
}

// 팝업 창 브라우져 조절 
// 보정값 gab
//
// @param url URL
// @param wname 창이름
// @param w 창 너비
// @param h 창 높이
// @param f
function popupWindow(url, wname, w, h, f) {
	var gab = 0;
	if(f != undefined && f == true) {
		var agent = navigator.userAgent.toLowerCase();
		if (agent.indexOf("msie") != -1 ) {
			gab += 50;
		}
		if (agent.indexOf("firefox") != -1 ) {
			gab += 20;
		}
		h += gab;
	}
	var p=window.open(url, wname, "width="+w+",height="+h);
	p.focus();
}

// 이미지사이즈 조절
// 최대 값을 넘기지 못하게 한다
// 
// @param 이미지 객체
// @param imgWidth 최대넓이
// @param imgHeight 최대높이
//
function changeSize(img, maxWidth, maxheight) {
	var imgWidth = img.width;
	var imgHeight = img.height;
	if (imgWidth >= maxWidth) {
		imgHeight = imgHeight / (imgWidth / maxWidth);			
		imgWidth = maxWidth;
	}
	if ( imgHeight >= maxheight) {
		imgWidth = imgWidth / (imgHeight / maxheight);
		imgHeight = maxheight;			
	}
	img.width = imgWidth;
	img.height = imgHeight;
}
// EOF
