var Durian = {
	alert : function(msg, type) {
		var layer = $('__alert__');
		if (layer) {
			Durian.alertLayer(layer, msg);
		} else {
			if (typeof Ajax != 'undefined') {
				new Ajax({
					url : '/common/js/alert/alert.html',
					method : 'POST',
					type : 'HTML',
					param : {
						msg : msg,
						dummy : Util.random(1, 10000)
					},
					callback : Durian.alertCallback
				});
			} else {
				alert(msg);
			}
		}
	},
	alertLayer : function(layer, msg) {
		Durian.showLayer(layer, {
			center : true,
			block : true
		})
		$('__alert_msg__').innerHTML = msg;
	},
	alertCloseMode : 0,
	alertClose : function() {
		var layer = $('__alert__');
		if (typeof Durian.alertCloseMode == 'string' && Durian.alertCloseMode != '') {
			location.href = Durian.alertCloseMode;
		} else if (typeof Durian.alertCloseMode == 'number') {
			switch (Durian.alertCloseMode) {
				case -1 : history.back(); break;
				case 1 : location.reload; break;
				case -2 : self.close(); break;
			}
			if (typeof layer.blockPage != 'undefined' && layer.blockPage) {
				var block = $('__block_page__');
				if (block) {
					Element.hide(block);
				}
			}
			Element.hide(layer);
		}
	},
	alertCallback : function(r) {
		if (r.isSuccess()) {
			var layer = $c('div');
			layer.id = '__alert__';
			Element.setStyle(layer, {
				padding : '0 0 150px 0'
			})
			document.body.appendChild(layer);
			layer.innerHTML = r.value;
			Durian.alertLayer(layer, this.param.msg);
		} else {
			alert(this.param.msg);
		}
	},
	showIf : function(obj, value) {
		if (value) {
			Element.show(obj);
		} else {
			Element.hide(obj);
		}
	},
	showHide : function(show, hide, display) {
		if (hide) {
			hide = $array(hide);
			for (var i=0; i<hide.length; i++) {
				Element.hide(hide[i]);
			}
		}
		if (show) {
			show = $array(show);
			for (var i=0; i<show.length; i++) {
				Element.show(show[i], display);
			}
		}
	},
	showLayer : function(obj, option) {
		obj = $(obj);
		Element.show(obj);
		if (typeof option.style == 'string') {
			obj.style.cssText = option.style;
		} else if (typeof option.style == 'object') {
			Element.setStyle(obj, option.style);
		}
		Element.setStyle(obj, 'position', 'absolute');

		var key = ['left', 'top', 'width', 'height'];
		for (var i=0; i<key.length; i++) {
			if (typeof option[key[i]] != 'undefined') {
				Element.setStyle(obj, key[i], option[key[i]]);
			}
		}
		if (option.block) {
			Element.setStyle(obj, {
				zIndex : 2000
			});
			Durian.blockPage(1000, '#777777');
			obj.blockPage = true;
		} else {
			obj.blockPage = false;
		}

		if (option.center) {
			var pos = Element.getCenter(obj);
			Element.moveTo(obj, pos);
		}

		if (Util.isIE) {
			var group = obj.id || Util.randomId();
			Element.attachBlocker(obj, group);
		}
		if (option.drag) {
			obj.drag = new Drag(obj, {
				handler : option.handler || []
			});
		}
	},
	showFrameLayer : function(url, option) {
		var obj = $c('div');
		if (!option.id) {
			option.id = 'common';
		}
		obj.id = '__frame_layer_' + option.id;
		obj.option = option;
		document.body.appendChild(obj);

		obj.innerHTML = '<iframe src="' + url + '" onload="Durian.autoResizeIframe(this);" allowTransparency="true" frameborder="0" scrolling="no"></iframe>';
		obj.iframe = obj.childNodes[0];

		// show layer
		this.showLayer(obj, option);

		// url
		if (typeof option.url == 'string') {
			obj.iframe.src = option.url;
		}
	},
	autoResizeIframe : function(iframe) {
		Util.autoResizeIframe(iframe);
		var obj = iframe.parentNode;
		if (obj.option) {
			if (obj.option.center) {
				var pos = Element.getCenter(obj);
				Element.moveTo(obj, pos);
			}		
		}
	},
	
	// iframe resizing
	resizeIframe : function(iframe, height) {
		var iframe = $(iframe);
		if (typeof iframe != 'undefined') {			
			if (height > 0) {
				Element.setStyle(iframe, 'height', height);
			} else {
				Util.autoResizeIframe(iframe, true, false);
				//Durian.autoResizeIframe(iframe);
			}		
		}
	},

	// parent : 1 base offset
	searchParentTag : function(obj, tag, offset) {
		tag = tag.toLowerCase();
		var count = 0;
		var p = obj.parentNode;
		while (p != document.body) {
			if (p.tagName.toLowerCase() == tag) {
				count++;
				if (count == offset) {
					return p;
				}
			}
			p = p.parentNode;
		}
		return false;
	},

	// child : 1 base offset
	searchChildTag : function(obj, tag, offset) {
		var list = obj.getElementsByTagName(tag);

		if (typeof list[offset-1] != 'undefined') {
			return list[offset-1];
		} else {
			return false;
		}
	},

	// prev : 1 base offset
	searchPrevSameTag : function(obj, offset, parent) {
		var tag = obj.tagName;
		var list = (parent || document).getElementsByTagName(tag);

		var key = -1;
		for (var i=0; i<list.length; i++) {
			if (list[i] == obj) {
				key = i;
				break;
			}
		}
		if (key > -1 && key >= offset) {
			return list[key - offset];
		} else {
			return false;
		}
	},

	// next : 1 base offset
	searchNextSameTag : function(obj, offset, parent) {
		var tag = obj.tagName;
		var list = (parent || document).getElementsByTagName(tag);

		var key = -1;
		for (var i=0; i<list.length; i++) {
			if (list[i] == obj) {
				key = i;
				break;
			}
		}
		if (key > -1 && key + offset < list.length) {
			return list[key + offset];
		} else {
			return false;
		}
	},

	searchByClassName : function(obj, className) {
		var list = obj.getElementsByTagName('*');
		var result = [];
		for (var i=0; i<list.length; i++) {
			if (Element.classExists(list[i], className)) {
				result.push(list[i]);
			}
		}

		if (result.length) {
			if (result.length == 1) {
				return result[0];
			} else {
				return result;
			}
		} else {
			return false;
		}
	},

	// popup window
	openWin : function(name, url, x, y, sc) {
		if (arguments.length > 2) {
			var winl = (screen.width - x) / 2;
			var wint = (screen.height - y) / 2;
			var w = window.open(url, name, 'scrollbars=' + sc + ', resizable=yes, width=' + x + ', height=' + y + ', top='+wint+', left='+winl);
		} else {
			var w = window.open(url, name);
		}
		if (w) {
			w.focus();
		}

		return w;
	},

	// modal window
	openModalWin : function(url, x, y, resize, arg) {
		if (window.showModalDialog) {
			return Durian.openWin('', url, x, y, resize);
		} else {
			return window.showModalDialog(url, arg || self, 'dialogHeight: '+y+'px; dialogWidth: '+x+'px; edge: Raised; center: Yes; help: No; resizable: '+resize+'; status: No; scroll: No;');
		}
	},

	// open webftp window
	openWebFTP : function(imgServer) {
		if (!imgServer) {
			imgServer = location.href.slice(0, location.href.indexOf('/', 7));
		}
		x = 960;
		y = 550;
		var winl = (screen.width - x) / 2;
		var wint = (screen.height - y) / 2;
		var w = window.open(imgServer + '/admin/?act=common.webftp&ch=pop', 'webftp', 'scrollbars=no, resizable=no, width=' + x + ', height=' + y + ', top='+wint+', left='+winl);
		w.focus();

		return w;
	},

	// clipboard copy - ZeroClipboard
	attachClipCopy : function(obj, callback, endCallback) {
		ZeroClipboard.setMoviePath('/common/js/ZeroClipboard/ZeroClipboard.swf');
		var clip = new ZeroClipboard.Client();
		clip.setHandCursor(true);
		
		clip.addEventListener('mousedown', callback);
		if (endCallback) {
			clip.addEventListener('complete', endCallback);
		}
		
		if (!(obj instanceof Array)) {
			obj = [obj];
		}

		clip.glue(obj[0]);
		
		$l(obj, 'mouseover', Durian._attachClipCopy.bindForEvent(clip));
	},
	_attachClipCopy : function(evt, obj) {
		//if (this.domElement != obj) {
			this.reposition(obj);
		//}
	},

	imgDefault : function(img, src) {
		if (!src || /^[0-9]+$/.test(src) || img.src.search(src) > -1) {
			var size = parseInt((src || img.width || img.getAttribute('width')), 10) || 100;
			if (size <= 50) {
				src = '/images/default/common/default_50.gif';
			} else if (size <= 100) {
				src = '/images/default/common/default_100.gif';
			} else if (size <= 300) {
				src = '/images/default/common/default_300.gif';
			} else {
				src = '/images/default/common/default_500.gif';
			}
		}

		if (img.src.search(src) == -1) {
			img.src = src;
		}
	},
	formatPrice : function(value, forceSign) {
		var number = parseInt(value, 10);
		if (number < 0) {
			var sign = '-';
		} else if (forceSign && number > 0) {
			var sign = '+';
		} else {
			var sign = '';
		}

		var value = ('' + value).trim().replace(/[^0-9]/, '');
		var gap = value.length % 3 || 3;
		var str = value.slice(0, gap);
		value = value.slice(gap);
		while (value) {
			str += ',' + value.slice(0, 3);
			value = value.slice(3);
		}
		return sign + str;
	},

	// upload
	checkUploadCount : function(option) {
		option = Class.extend(option || {});
		
		var max = parseInt(option.max, 10) || 0;
		if (!max) {
			return true;
		}

		var count = count2 = 0;
		
		if (typeof option.single != 'undefined' && option.single == true) {
			count = !option.file_path ? 0 : 1;
			count2 = !option.db_file_path ? 0 : 1;		
		} else {
			if (typeof option.list != 'undefined') {
				var list_child = option.list.childNodes;
				for (i = 0; i < list_child.length; i++) {
					if (list_child[i].nodeType == 1) {
						count++;
					}
				}
			}

			if (typeof option.db_list != 'undefined') {
				var db_list_child = option.db_list.childNodes;
				for (i = 0; i < db_list_child.length; i++) {
					if (db_list_child[i].nodeType == 1) {
						count2++;
					}
				}		
			}	
		}

		var total = count + count2;
		if (max <= total) {
			alert('첨부파일은 최대 ' + max + '개까지 업로드 가능합니다.');
			return false;
		} else {
			return true;
		}
	},

	openUploadWin : function(option) {
		option = Class.extend({
			act : 'common.popup_upload2',
			ch : 'pop',
			upload_mode : 'FILE'
		}, option || {});

		var domain = 'http://' + Durian.getDomain();
		var img_server = 'http://' + Durian.getImgServer();
		var sub_path = Durian.getDomainSubPath();
		option.domain = domain;
		var query = ''.encodeQuery(option);
		
		if (sub_path) {
			return Durian.openWin('upload', img_server + sub_path + '/?' + query, 550, 400, 'yes');		
		} else {		
			return Durian.openWin('upload', img_server + '?' + query, 600, 450, 'yes');
		}
	},

	openUploadWinSingle : function(option) {
		option = Class.extend({
			act : 'common.popup_upload',
			ch : 'pop',
			upload_mode : 'FILE'
		}, option || {});

		var domain = 'http://' + Durian.getDomain();
		var img_server = 'http://' + Durian.getImgServer();
		var sub_path = Durian.getDomainSubPath();
		option.domain = domain;
		var query = ''.encodeQuery(option);
		
		if (sub_path) {
			return Durian.openWin('upload', domain + sub_path + '/?' + query, 550, 300, 'yes');		
		} else {		
			return Durian.openWin('upload', domain + '?' + query, 520, 250, 'yes');
		}
	},

	ajaxDeleteFile : function(option, obj) {
		option = Class.extend({
			act : 'common.upload_delete_ajax',
			upload_mode : 'FILE'
		}, option || {});

		new Ajax({
			url : './',
			method : 'post',
			type : 'JSON',
			param : option,
			callback : Durian.ajaxDeleteFileCallback,
			obj : obj
		});
	},

	ajaxDeleteFileCallback : function(r) {
		if (r.isSuccess()) {
			var success = r.value.success;
			if (success) {
				applyDeleteFile(r, this.obj);
			} else {
				alert(r.value.msg);
			}
		}
	},

	getDomain : function() {
		return location.href.split('/')[2];
	},

	getDomainSubPath : function() {
		var path = location.href.split('/')[3];
		if (path == 'admin') {
			return '/admin';
		} else {
			return '';
		}
	},

	getBaseDomain : function() {
		var domain = Durian.getDomain();
		// ip
		if (domain.search(/^[0-9\.]+$/) > -1) {
			return domain;
		}

		var tmp = domain.split('.');
		var l = tmp.length;
		if (l > 2) {
			if (tmp[l-2].search(/^(co|ne|or|pe|go|com|net|org)$/) > -1) {
				return tmp.slice(-3).join('.');
			} else {
				return tmp.slice(-2).join('.');
			}		
		} else {
			return domain;
		}

	},

	getImgServer : function() {
		return Durian.getDomain();
	},

	// Editor
	initEditor : function(option) {
		return Durian.initCHEditor(option);
	},
	initCHEditor : function(option) {
		if (option.mode == 'ALL') {
			option.item = option.mode;
		} else {
			if (typeof option.item == 'string') {
				option.item = option.item.split(',');
			} else {
				// error
				alert('ERROR : Invalid Editor Configuration.');
				return;
			}
		}
		var u = new Durian.CHEditor(option);

		// focus problem :-(
		setTimeout(function() {
			window.scrollTo(0, 0);
		}, 500);
	},
	// upload
	initUpload : function(option) {
		return new Durian.SWFUpload(option);
		//return new Durian.TrueUpload(option);
	},
	// display Image or Flash
	displayImageFlash : function(url, width, height) {
		if (url.search(/\.swf$/i) > -1) {
			Durian.displayFlash(url, width, height);
		} else {
			Durian.displayImage(url, width, height);
		}
	},
	displayImage : function(url, width, height) {
		if (width && height) {
			var size = 'width="' + width + '" height="' + height + '"';
		} else {
			var size = '';
		}
		var html = '<img src="' + url + '" ' + size + '>';
		document.write(html);
	},

	// displayFlash
	displayFlash : function(url, width, height, id, vars, wmode, bg, scriptAccess) {
		var html = Durian.getFlashHTML(url, width, height, id, vars, wmode, bg);
		document.write(html);
	},
	getFlashHTML : function(url, width, height, id, vars, wmode, bg, scriptAccess) {
		if (width && height) {
			var size = 'width="' + width + '" height="' + height + '"';
		} else {
			var size = 'width="100%" height="100%"';
		}
		if (!id) {
			id = Util.randomId(4, 'flash');
		}
		if (!vars) {
			vars = '';
		}
		if (!wmode) {
			wmode = 'transparent';
		}
		if (!bg) {
			bg = '';
		}
		if (!scriptAccess) {
			scriptAccess = 'sameDomain';
		}

		var html = '<object id="' + id + '" ' + size + ' align="middle" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0">'
				 + '<param name="movie" value="' + url + '" />'
				 + '<param name="flashvars" value="' + vars + '" />'
				 + '<param name="wmode" value="' + wmode + '" />'
				 + '<param name="bgcolor" value="' + bg + '" />'
				 + '<param name="AllowScriptAccess" value="' + scriptAccess + '" /> '
				 + '<param name="menu" value="false" / >'
				 + '<param name="quality" value="high" / >'
				 + '<embed id="' + id + '_embed" name="' + id + '" src="' + url + '" ' + size + ' flashvars="' + vars + '" wmode="' + wmode + '" bgcolor="' + bg + '" allowScriptAccess="' + scriptAccess + '"'
				 + ' align="middle" quality="high" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer"'
				 + '></embed>'
				 + '</object>';
		return html;
	},

	// block page
	blockPage : function(zIndex, color) {
		if (!zIndex) {
			zIndex = 1000;
		}

		var div = $('__block_page__');
		if (!div) {
			div = $c('div');
			div.id = '__block_page__';
			document.body.appendChild(div);
			Element.setStyle(div, {
				'position' : 'absolute',
				'left' : '0px',
				'top' : '0px',
				//'border' : '1px solid red',
				//'cursor' : 'not-allowed',
				'zIndex' : zIndex
			});
		}

		if (color) {
			Element.setStyle(div, {
				'backgroundColor' : color,
				'opacity' : 0.3
			});
		}

		Element.setSize(div, Util.getDocSize());

		//$l(document, 'mousedown', function(evt) { Event.stop(evt); });
		//$l(document, 'mouseup', function(evt) { Event.stop(evt); });
		//$l(document, 'click', function(evt) { Event.stop(evt); });
		//$l(document, 'keypress', function(evt) { Event.stop(evt); });
	},
	
	// check if member (not secure!)
	isMember : function() {
		if (Util.getCookie('user_level')) {
			return true;
		} else {
			return false;
		}
	},
	
	// add bookmark
	// refered to http://www.dynamicdrive.com/dynamicindex9/addbook.htm
	bookmark : function(url, title) {
		if (Util.isIE) {
			window.external.AddFavorite(url, title);
		} else if (Util.isFF) {
			window.sidebar.addPanel(title, url, '');
		} else if (Util.isOpera) {
			var elem = document.createElement('a');
			elem.setAttribute('href',url);
			elem.setAttribute('title',title);
			elem.setAttribute('rel', 'sidebar');
			elem.click();
		}
	}
}


///////////////////////////////////////////////////////////////////////////////////////////////////
// init common

Durian.initCommon = {
	isUser : location.href.indexOf('/admin/') == -1 ? true : false,
	isPopup : location.href.search(/&ch=(pop|iframe)/) > -1 ? true : false,
	init : function() {
		var D = Durian.initCommon;

		// user
		if (D.isUser) {
			D.initUser();
		// admin
		} else {
			D.initAdmin();
		}

		// common

		// inputbox
		D.initInputBox();
	},

	// user
	initUser : function() {
		var D = Durian.initCommon;
		// fly
		try {
			var obj_fly = ['L_TODAY_GOODS', 'L_QUICK_MENU'];
			for (var i=0; i<obj_fly.length; i++) {
				var obj = $(obj_fly[i]);
				if (obj && obj.getAttribute('scroll') == '1') {
					D.initScroll(obj);
				}
			}
		} catch (e) {}

		// bbs link
		try {
			var obj_bbs = ['L_NOTICE', 'L_QNA', 'M_AFTERNOTE', 'M_BBS_NOTICE', 'M_BBS_ADD'];
			for (var i=0; i<obj_bbs.length; i++) {
				var obj = $(obj_bbs[i]);
				if (obj) {
					var list = obj.getElementsByTagName('a');
					for (var j=0; j<list.length; j++) {
						if (list[j].href.indexOf('pop=1') > -1) {
							$l(list[j], 'click', D.onPopViewBBS);
						}
					}
				}
			}
		} catch (e) {}

		// popup launch
		if (!D.isPopup) {
			D.initPopup();
		}
	},
	
	initAdmin : function() {
	},

	// popup
	initPopup : function() {
		var D = Durian.initCommon;

		var data = Util.getCookie('POPUP_DATA');
		if (!data) {
			D.getPopupListAjax();
		} else if (data != '-1') {
			D.applyPopup(data);
		}
	},
	applyPopup : function(data) {
		var D = Durian.initCommon;

		var query = location.href.parseQuery(true);

		var list = data.split('|^|');
		for (var i=0; i<list.length; i++) {
			var row = list[i].split('|');
			var url = row.pop();
			if (url) {
				if (D.checkQueryMatch(query, url.parseQuery())) {
					D.openPopup(row);
				}
			} else {
				// refer to main/index.php for var isMain
				if (typeof isMain != 'undefined' && isMain) {
					D.openPopup(row);
				}
			}
		}
	},
	openPopup : function(data) {
		var seq    = data[0];
		var width  = data[1];
		var height = data[2];
		var left   = data[3];
		var top    = data[4];
		var scroll = data[5];
		var wType  = data[6];
		var bType  = data[7];

		var block_name = 'POPUP_BLOCK_' + seq;
		if (Util.getCookie(block_name)) {
			return;
		}

		var url = '?act=common.event_popup_view&seq=' + seq;
		if (wType == '0') {
			var scroll = (scroll == '0' ? 'no' : 'yes');
			var win = window.open(url, 'event_' + seq, 'width=' + width + ', height=' + height + ', left=' + left + ', top=' + top + ', scrollbars=' + scroll);
			if (win) {
				win.focus();
			}
		} else {
			var scroll = (scroll == '0' ? 'no' : 'yes');

			var div = $c('div');
			div.id = 'layer_event_' + seq;
			Element.setStyle(div, {
				'position' : 'absolute',
				'width' : width + 'px',
				'height' : height + 'px',
				'left' : left + 'px',
				'top' : top + 'px',
				'cursor' : 'move',
				'border' : '10px solid #CCCCCC',
				'backgroundColor' : '#FFFFFF'
			});

			var iframe = $c('iframe');
			iframe.id = div.id + '_iframe';
			Element.setStyle(iframe, {
				'width' : '100%',
				'height' : '100%',
				'border' : '0'
			});
			iframe.setAttribute('frameborder', '0');
			iframe.setAttribute('border', '0');
			iframe.setAttribute('scrolling', scroll);

			document.body.appendChild(div);
			div.appendChild(iframe);

			iframe.src = url + '&layer=1';

			if (wType == '1') {
				var D = Durian.initCommon;
				new Drag(div, {
					onMove : D.onPopupLayerMove,
					onEnd : D.onPopupLayerEnd
				});
			}
		}
	},
	closePopup : function(seq) {
		var div = $('layer_event_' + seq);
		if (div) {
			Element.remove(div);
		}
	},
	onPopupLayerMove : function(evt) {
		var iframe = $(this.object.id + '_iframe');
		iframe.style.visibility = 'hidden';
	},
	onPopupLayerEnd : function(evt) {
		var iframe = $(this.object.id + '_iframe');
		iframe.style.visibility = 'visible';
	},
	checkQueryMatch : function(base, part) {
		var flag = true;
		for (var key in part) {
			if (typeof base[key] == 'undefined' || base[key] != part[key]) {
				flag = false;
				break;
			}
		}
		return flag;
	},
	getPopupListAjax : function() {
		var D = Durian.initCommon;

		new Ajax({
			url : '/',
			method : 'POST',
			type : 'TEXT',
			param : {
				act : 'common.event_popup_ajax'
			},
			callback : D.getPopupListAjaxCallback
		});
	},
	getPopupListAjaxCallback : function(r) {
		if (r.isSuccess()) {
			if (r.value) {
				var D = Durian.initCommon;
				D.applyPopup(r.value);

				Util.setCookie('POPUP_DATA', r.value, 0, '/');
			} else {
				Util.setCookie('POPUP_DATA', -1, 0, '/');
			}

		}
	},
	
	initInputBox : function(obj) {
		var D = Durian.initCommon;
		var list = (obj || document).getElementsByTagName('input');
		for (var i=0; i<list.length; i++) {
			if (list[i].type == 'text' || list[i].type == 'password') {
				$l(list[i], 'focus', D.onInputFocus);
				$l(list[i], 'blur', D.onInputBlur);
			}
		}
	},

	// input box focus/blur action
	onInputFocus : function(evt, obj) {
		//var size = Element.getSize(obj);
		Element.addClass(obj, 'on');
		//Element.setSize(obj, size.width-4, size.height-4);
	},
	onInputBlur : function(evt, obj) {
		//var size = Element.getSize(obj);
		Element.delClass(obj, 'on');
		//Element.setSize(obj, size.width-2, size.height-2);
	},

	// for scroll
	scrollInit : false,
	scrollList : [],
	scrollSleep : 50,
	scrollDelay : 50,
	scrollNow : 0,
	scrollTimer : null,
	scrollPos : {},
	initScroll : function(obj) {
		var D = Durian.initCommon;
		if (!D.scrollList.has(obj)) {
			D.scrollList.push(obj);

			obj.gap = parseInt(Element.getStyle(obj, 'top'), 10) || 0;
		}

		if (!D.scrollInit) {
			$l(window, 'scroll', D.onScroll);
		}
	},
	onScroll : function(evt, obj) {
		var D = Durian.initCommon;
		D.scrollNow = 0;
		if (D.scrollTimer) {
			clearTimeout(D.scrollTimer);
		}
		D.scrollTop = window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop || 0;
		D.scrollTimer = setTimeout(D.scrollPlay, D.scrollSleep);
	},
	scrollPlay : function() {
		var D = Durian.initCommon;
		D.scrollNow++;
		var flag = false;
		for (var i=0; i<D.scrollList.length; i++) {
			var obj = D.scrollList[i];
			var top = parseInt(obj.style.top, 10) || 0;
			var gap = D.scrollTop + obj.gap - top;
			if (Math.abs(gap) > 1) {
				obj.style.top = (top + parseInt(gap/2, 10)) + 'px';
				flag = true;
			} else {
				obj.style.top = (top + gap) + 'px';
			}
		}
		if (flag) {
			D.scrollTimer = setTimeout(D.scrollPlay, D.scrollDelay);
		}
	},
	
	onPopViewBBS : function(evt, obj) {
		Event.stop(evt);

		var url = obj.href;
		var match = url.match(/&bbs_code=([^&]+)/);
		var bbs_code = (typeof match[1] != 'undefined') ? match[1] : 'bbs_dummy';
		Durian.openWin(bbs_code, url, 700, 500, 'yes');
	}
}

// for flash wizard
function flashInfo(id, w, h)
{
	var area = $(id + '_area');
	if (area) {
		if (id == 'L_CATEGORY_flash' && area.getAttribute('design_type') == '03') {
			Element.setSize(area, w, h);
		} else {
			if (area.getAttribute('inited') != '1') {
				Element.setSize(area, w, h);
				area.setAttribute('inited', '1');
			}
		}
	}

	var box = $(id + '_box');
	if (box) {
		Element.setSize(box, w, h);
	}

	if (Util.isIE) {
		Element.setSize(id, w, h);
	} else {
		Element.setSize(id + '_embed', w, h);
	}
}

$l(window, 'load', Durian.initCommon.init);