<!--//
/*-- Last Midified : 070208 --*/
function ad_is_number(pVal) { return !(isNaN(parseInt(pVal, 10))); }
function ad_set_cookie(name, value, expires, path, domain, secure) {
	if ((expires) && (expires.constructor == Number)) { var dt = new Date(); dt.setDate(dt.getDate() + expires); expires = dt; }
	var curCookie = name + '=' + escape(value) +
		((expires) ? '; expires=' + expires.toGMTString() : '') +
		((path) ? '; path=' + path : '') +
		((domain) ? '; domain=' + domain : '') +
		((secure) ? '; secure' : '');
	document.cookie = curCookie;
}

function ad_get_cookie(name) {
	var dc = document.cookie;
	var prefix = name + '=';
	var begin = dc.indexOf('; ' + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return '';
	}
	else {
		begin += 2;
	}
	var end = document.cookie.indexOf(';', begin);
	if (end == -1) end = dc.length;
	return unescape(dc.substring(begin + prefix.length, end));
}

//Create Ramdom Number - [0 - p_max]
function ad_get_random_idx(p_max) {
	return Math.floor(Math.random()*p_max);
}

function ad_get_swf_tag(src,w,h,m,id) {
	m = ((typeof(m) == 'undefined') ? 'none' : m);
	w = (((w = ((typeof(w) != 'undefined') ? parseInt(w, 10) : 0)) > 0) ? (' width="' + w + '" ') : '');
	h = (((h = ((typeof(h) != 'undefined') ? parseInt(h, 10) : 0)) > 0) ? (' height="' + h + '" ') : '');
	id = (((typeof(id) != 'undefined') && (id.toString().length > 0)) ? (' id="' + id + '" ') : '');
	var tag = ''
	tag += '<object '+id+' '+w+' '+h+' classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0">';
	tag += '<param name="movie" value="'+src+'"/>';
	tag += '<param name="wmode" value="'+m+'"/>';
	tag += '<param name="quality" value="high"/>';
	tag += '<param name="menu" value="false">';
	tag += '<embed '+w+' '+h+' src="'+src+'" wmode="'+m+'" quality="high" menu="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?p1_prod_version=shockwaveflash"></embed>';
	tag += '</object>';
	return tag;
}

function ad_get_img_tag(src,w,h,id,etc) {
	etc = ((typeof(etc) == 'undefined') ? '' : etc);
	w = (((w = ((typeof(w) != 'undefined') ? parseInt(w, 10) : 0)) > 0) ? (' width="' + w + '" ') : '');
	h = (((h = ((typeof(h) != 'undefined') ? parseInt(h, 10) : 0)) > 0) ? (' height="' + h + '" ') : '');
	id = (((typeof(id) != 'undefined') && (id.toString().length > 0)) ? (' id="' + id + '" ') : '');
	var tag = '<img '+id+' src="'+src+'" '+w+' '+h+' '+etc+' border="0">';
	return tag;
}

function ad_get_html_tag(id) {
	var obj = document.getElementById(id);
	return obj.innerHTML;
}

// Object multi display - [drm:061121]
function mp_display_obj(id) {
	this.id = id;						// ½Äº°¸íÄª
	this.start_idx = -1;		// Default Start Index
	this.delay = 0;					// Time
	this.width = 0;					// width
	this.height = 0;				// height
	this.width_ext = 0;			// width(ext)
	this.height_ext = 0;		// height(ext)
	this.top_ext = 0;				// top(ext)
	this.left_ext = 0;			// left(ext)
	this.pausemouseover = true;
	this.swf_m = '';				// Flash mode
	this.view_items = 1;
	this.blank_hori = 0;
	this.zindex = 0;

	this.m_arr = null;			// ÀÚ·á [0:Type, 1:Resource, 2:Link, 3:±¤°í code](20070917 ±¤°í count Ãß°¡)
	this.m_arr_code = null;	//20070917 ±¤°í count Ãß°¡
	this.is_pause = false;	// µ¿ÀÛ¿©ºÎ
	this.obj;
	this.is_init = false;
	this.set_data = function (p_arr) { this.m_arr = p_arr; }
	this.init = function () {
		this.obj = document.getElementById(this.id);
		if (!this.obj) { return; }

		var i, n_arr_idx, n_idx;
		var arr_t = new Array;
		var arr_code = new Array;//±¤°í count 20070917 Ãß°¡	
		var a_data, s_data_type, s_data_res, s_data_link, s_acode, s_tag, s_style;
		var w = parseInt(this.width, 10);
		var h = parseInt(this.height, 10);
		var is_fixed_size = ((w > 0) && (h > 0));
		var s_overflow = 'hidden';
		var cur_t_pos, t_pos, l_pos;
		var s_mouseover, s_mouseout;

		if (this.m_arr.constructor != Array) { this.m_arr = new Array; }

		this.start_idx = ad_get_cookie(this.id);
		if (!ad_is_number(this.start_idx)) { this.start_idx = ad_get_random_idx(this.m_arr.length); }
		this.start_idx = parseInt(this.start_idx, 10);
		
		s_style = '';
		s_mouseover = ' onmouseover="{if (this.style.zIndex!=999) {this.zIndex_sv=this.style.zIndex; this.style.zIndex=999;}}" ';
		s_mouseout  = ' onmouseout="{if (this.style.zIndex!=this.zIndex_sv) {this.style.zIndex=this.zIndex_sv;}}" ';

		cur_t_pos = 0;
		n_arr_idx = 0;
		for (i = 0; i < this.m_arr.length; i++) {
			n_idx = ((this.start_idx + i) % this.m_arr.length);
			a_data = this.m_arr[n_idx];
			if (a_data.constructor != Array) { continue; }
			if (a_data.length < 2) { continue; }
			s_data_type = a_data[0].toLowerCase();
			s_data_res = a_data[1];
			s_data_link = ((a_data.length >= 3) ? a_data[2] : '');
			//20070917 ±¤°í count Ãß°¡
			s_acode = '';
			if (a_data.length >= 3) {
				s_acode = a_data[a_data.length - 1];
				s_acode = ((s_acode.length == 10) ? s_acode : '');
				s_data_link = ((s_data_link == s_acode) ? '' : s_data_link);
			}
			//20070917 ±¤°í count Ãß°¡
			s_tag = '';
			if (s_data_type == 'img')          { s_tag += ad_get_img_tag(s_data_res); }
			else if (s_data_type == 'swf')     { s_tag += ad_get_swf_tag(s_data_res,this.width, this.height, this.swf_m); }
			else if (s_data_type == 'swf_ext') { s_tag += ad_get_swf_tag(s_data_res,this.width_ext, this.height_ext, this.swf_m); }
			else if (s_data_type == 'html')    { s_tag += ad_get_html_tag(s_data_res); }
			else { continue; }
			if (s_data_link.length > 0) {     s_tag = ('<a href="'+s_data_link+'" target="_blank">' + s_tag + '</a>'); }
			if (is_fixed_size == true) {
				if (s_data_type == 'swf_ext') { t_pos = this.top_ext; l_pos = this.left_ext; s_overflow = ''; }
				else {                          t_pos = 0;            l_pos = 0; }
				s_style = 'style="position:absolute; left:' + l_pos + 'px; top:' + (cur_t_pos + t_pos) + 'px;"';
				if (this.view_items > 1) { cur_t_pos += (this.height + this.blank_hori); }
			}
			s_tag = '<div id="'+this.id+'_item'+n_arr_idx+'" ' + s_style + s_mouseover + s_mouseout + '>' + s_tag + '</div>';
			arr_t[n_arr_idx] = s_tag;
			arr_code[n_arr_idx] = s_acode;//20070917 ±¤°í count Ãß°¡
			n_arr_idx++;
		}
		this.view_items = ((n_arr_idx < this.view_items) ? n_arr_idx : this.view_items);

		w = (((w = parseInt(w, 10)) > 0) ? (' width:' + w + '; ') : '');
		h = (((h = parseInt(h, 10)) > 0) ? (' height:' + ((h * this.view_items) + (this.blank_hori * (this.view_items - 1))) + '; ') : '');

		s_style = '';
		if (parseInt(this.zindex, 10) > 0) {
			s_style = 'z-index: ' + this.zindex + '; ';
		}
		s_tag = '<div id="'+this.id+'_items" style="position:relative; overflow:'+s_overflow+'; '+s_style+w+h+'"></div>';
		this.obj.innerHTML = s_tag;
		this.obj = document.getElementById(this.id + '_items');
		this.obj.ad_obj = this;
		if ((this.delay > 0) && (this.pausemouseover ==  true)) {
			if (!this.obj.onmouseover) { this.obj.onmouseover = function() { this.ad_obj.onmouseover(); } }
			if (!this.obj.onmouseout)  { this.obj.onmouseout =  function() { this.ad_obj.onmouseout(); } }
		}

		this.m_arr = arr_t;
		this.m_arr_code = arr_code;//20070917 ±¤°í count Ãß°¡
		this.is_init = true;
	}
	this.onmouseover = function () { if (this.pausemouseover) { this.is_pause = true; } }
	this.onmouseout = function ()  { if (this.pausemouseover) { this.is_pause = false; } }
	this.run = function () {
		var is_first_run = false;
		if (!this.is_init) { 
			this.init();
			is_first_run = true;
		}
		if (!this.obj) { return; }
		if (this.m_arr.length <= 0) { return; }
		if ((this.delay > 0) && (this.pausemouseover ==  true)) {
			if (this.is_pause) { window.setTimeout(this.id+'.run()', this.delay); return; }
		}

		var n_idx;
		var s_acode = '';//20070917 ±¤°í count Ãß°¡
		var s_tag = '';
		var s_tag_hori = ((parseInt(this.blank_hori, 10) > 0) ? '<div style="margin-bottom:' + this.blank_hori + '"></div>' : '');
		for (var i = 0; (i < this.view_items) && (i < this.m_arr.length); i++) {
			n_idx = ((this.start_idx + i) % this.m_arr.length);
			if (is_first_run == true) { n_idx = i; }
			s_tag += (((i > 0) ? s_tag_hori : '') + this.m_arr[n_idx]);
		}
		this.obj.innerHTML = s_tag;
		//20070917 ±¤°í count Ãß°¡
		var s_acode = this.m_arr_code[n_idx];
		if (s_acode.length == 10) {
			ad_pub_proc(this.id, s_acode, 1, 0);//-- \Script\Ad_Pub_Proc.js ÀÌ ÀÖ¾î¾ß ÇÔ
		}
		//20070917 ±¤°í count Ãß°¡
		if (this.delay > 0) { window.setTimeout(this.id+'.run()', this.delay); }

		this.start_idx++;
		this.start_idx %= this.m_arr.length;

		var expireDate = new Date;
		expireDate.setMonth(expireDate.getMonth() + 12);
		ad_set_cookie(this.id, this.start_idx, expireDate, '/');
	}
	this.next = function () {
		this.run();
	}
	this.prev = function () {
		this.start_idx += (this.m_arr.length - 2);
		this.start_idx %= this.m_arr.length;
		this.run();
	}
}

function mp_scroll_obj(id) {
	this.id = id;			// ½Äº°¸íÄª
	this.start_idx = -1;		// Default Start Index
	this.delay = 0;					// Time
	this.width = 0;					// width
	this.height = 0;				// height
	this.pausemouseover = true;
	this.swf_m = '';				// Flash mode
	this.scroll_items = 1;
	this.view_items = 1;
	this.scroll_speed = 1;

	this.item_height = 0;
	this.scroll_item_cnt = 0;
	this.current_top_item = 0;
	this.time_id;

	this.m_arr = null;			// ÀÚ·á [0:Type, 1:Resource, 2:Link]
	this.is_pause = false;	// µ¿ÀÛ¿©ºÎ
	this.obj;
	this.is_init = false;
	this.set_data = function (p_arr) { this.m_arr = p_arr; }

	this.init = function () {
		this.obj = document.getElementById(this.id);
		if (!this.obj) { return; }

		var i, ii, n_arr_idx, n_idx;
		var a_data, s_data_type, s_data_res, s_data_link, s_tag, s_tag_all, s_style;

		if (this.m_arr.constructor != Array) { this.m_arr = new Array; }

		this.start_idx = ad_get_cookie(this.id);
		if (!ad_is_number(this.start_idx)) { this.start_idx = ad_get_random_idx(this.m_arr.length); }
		this.start_idx = parseInt(this.start_idx, 10);

		s_tag = '<div id="'+this.id+'_items" style="position:relative; overflow:hidden; width:'+this.width+'; height:'+this.height+';"></div>';
		this.obj.innerHTML = s_tag;
		this.item_height = (this.height/this.view_items);
		s_style = 'style="position:absolute; left:0px; top:0px; display:hidden; width:'+this.width+'; height:'+this.item_height+';"';
		
		this.obj = document.getElementById(this.id + '_items');
		this.obj.ad_obj = this;
		if (this.pausemouseover ==  true) {
			if (!this.obj.onmouseover) { this.obj.onmouseover = function() { this.ad_obj.onmouseover(); } }
			if (!this.obj.onmouseout)  { this.obj.onmouseout =  function() { this.ad_obj.onmouseout(); } }
		}

		n_arr_idx = 0;
		s_tag_all = '';
		for (i = 0; i < this.m_arr.length; i++) {
			n_idx = ((this.start_idx + i) % this.m_arr.length);
			a_data = this.m_arr[n_idx];
			if (a_data.constructor != Array) { continue; }
			if (a_data.length < 2) { continue; }
			s_data_type = a_data[0].toLowerCase();
			s_data_res = a_data[1];
			s_data_link = ((a_data.length == 3) ? a_data[2] : '');
			s_tag = '';
			if (s_data_type == 'img') {       s_tag += ad_get_img_tag(s_data_res); }
			else if (s_data_type == 'swf') {  s_tag += ad_get_swf_tag(s_data_res, this.width, this.height, this.swf_m); }
			else if (s_data_type == 'html') { s_tag += ad_get_html_tag(s_data_res); }
			else { continue; }
			if (s_data_link.length > 0) {     s_tag = ('<a href="'+s_data_link+'" target="_blank">' + s_tag + '</a>'); }
			s_tag = '<div id="'+this.id+'_item'+n_arr_idx+'" ' + s_style + '>' + s_tag + '</div>';
			s_tag_all += s_tag;
			n_arr_idx++;
		}
		this.obj.innerHTML = s_tag_all;

		this.m_arr = new Array;
		for (i = 0; i < n_arr_idx; i++) {
			ii = (i + this.start_idx) % n_arr_idx;
			this.m_arr[i] = document.getElementById(this.id+'_item'+ii);
			this.m_arr[i].style.top = this.fmt_val2str_px(this.item_height * i);
			this.m_arr[i].style.display = 'block';
		}

		this.is_init = true;
	}
	this.onmouseover = function () { if (this.pausemouseover) { this.is_pause = true;  } }
	this.onmouseout = function ()  { if (this.pausemouseover) { this.is_pause = false; } }
	this.run = function () {
		if (!this.is_init) { this.init(); }
		if (!this.obj) { return; }
		if (this.m_arr.length <= 0) { return; }

		this.is_pause = true;
		this.scroll_item_cnt = 0;
		this.time_id = window.setTimeout(this.id+'.scroll()', this.scroll_speed);
		window.setTimeout(this.id+".is_pause = false", this.delay);

		this.start_idx++;
		this.start_idx %= this.m_arr.length;

		var expireDate = new Date;
		expireDate.setMonth(expireDate.getMonth() + 12);
		ad_set_cookie(this.id, this.start_idx, expireDate, '/');
	}
	this.scroll = function () {
		if (this.is_pause) { this.time_id = window.setTimeout(this.id+'.scroll()', this.scroll_speed); return; }
		var delay = this.scroll_speed;
		var obj_style;
		if (!this.is_pause) {
			for (var i = 0; i < this.m_arr.length; i++) {
				obj_style = this.m_arr[i].style;
				obj_style.top = this.fmt_val2str_px(this.fmtstr2val_px(obj_style.top) - 1);
				if (this.fmtstr2val_px(obj_style.top) <= (this.item_height * (-1))) {
					obj_style.top = this.fmt_val2str_px(this.item_height * (this.m_arr.length - 1));
				}
				if (this.fmtstr2val_px(obj_style.top) == 0) {
					this.current_top_item = i;
					this.scroll_item_cnt++;
					if (this.scroll_item_cnt >= this.scroll_items) {
						delay = this.delay;
						this.scroll_item_cnt = 0;
					}
				}
			}
		}
		this.time_id = window.setTimeout(this.id+'.scroll()', delay);
	}
	this.current_top_position = function() {
		var obj_style = this.m_arr[this.current_top_item].style;
		return this.fmtstr2val_px(obj_style.top);
	}
	this.up = function() {
		window.clearTimeout(this.time_id);
		var delta = (this.item_height - (this.current_top_position() * -1));
		delta = ((delta == 0) ? this.item_height : delta);

		for (var i = 0; i < this.m_arr.length; i++) {
			obj_style = this.m_arr[i].style;
			obj_style.top = this.fmt_val2str_px(this.fmtstr2val_px(obj_style.top) - delta);
			if (this.fmtstr2val_px(obj_style.top) <= (this.item_height * (-1))) {
				obj_style.top = this.fmt_val2str_px(this.item_height * (this.m_arr.length - 1));
			}
			if (this.fmtstr2val_px(obj_style.top) == 0) {
				this.current_top_item = i;
			}
		}
		this.scroll_item_cnt = 0;
		this.time_id = window.setTimeout(this.id+'.scroll()', this.delay);
	}
	this.dn = function() {
		window.clearTimeout(this.time_id);
		var delta = (this.current_top_position() * -1);
		delta = ((delta == 0) ? this.item_height : delta);

		for (var i = 0; i < this.m_arr.length; i++) {
			obj_style = this.m_arr[i].style;
			obj_style.top = this.fmt_val2str_px(this.fmtstr2val_px(obj_style.top) + delta);
			if (this.fmtstr2val_px(obj_style.top) <= (this.item_height * (-1))) {
				obj_style.top = this.fmt_val2str_px(this.item_height * (this.m_arr.length - 1));
			}
			if (this.fmtstr2val_px(obj_style.top) >= (this.item_height * this.m_arr.length)) {
				obj_style.top = this.fmt_val2str_px(0);
			}
			if (this.fmtstr2val_px(obj_style.top) == 0) {
				this.current_top_item = i;
			}
		}
		this.scroll_item_cnt = 0;
		this.time_id = window.setTimeout(this.id+'.scroll()', this.delay);
	}
	//-- position convert
	this.fmt_val2str_px = function(p_val) {
		return (p_val + 'px');
	}	
	this.fmtstr2val_px = function(p_pos_str) {
		return parseInt(p_pos_str, 10);
	}	
}
//-->

