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.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 = parseInt(obj_style.top, 10) - 1;
				if (parseInt(obj_style.top, 10) <= this.item_height * (-1) ) {
					obj_style.top = this.item_height * (this.m_arr.length - 1);
				}
				if (parseInt(obj_style.top, 10) == 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 parseInt(obj_style.top, 10);
	}
	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 = parseInt(obj_style.top, 10) - (delta);
			if (parseInt(obj_style.top, 10) <= (this.item_height * (-1))) {
				obj_style.top = this.item_height * (this.m_arr.length - 1);
			}
			if (parseInt(obj_style.top, 10) == 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 = parseInt(obj_style.top, 10) + (delta);
			if (parseInt(obj_style.top, 10) <= this.item_height * (-1) ) {
				obj_style.top = this.item_height * (this.m_arr.length - 1);
			}
			if (parseInt(obj_style.top, 10) >= (this.item_height * this.m_arr.length)) {
				obj_style.top = 0;
			}
			if (parseInt(obj_style.top, 10) == 0) {
				this.current_top_item = i;
			}
		}
		this.scroll_item_cnt = 0;
		this.time_id = window.setTimeout(this.id+'.scroll()', this.delay);
	}
}

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;
}