//////////////////////////////////////////////////////
//
// Notice Scroll
//
//////////////////////////////////////////////////////
function getRealX (obj) {
	if ( obj.offsetParent == null ) return 0;
    return obj.offsetLeft + getRealX(obj.offsetParent);
}

function getRealY (obj) {
	if ( obj.offsetParent == null ) return 0;
    return obj.offsetTop  + getRealY(obj.offsetParent);
}

function toggle_checkbox( objid ) {
	obj = document.getElementById(objid);
	if (obj.className == "checkbox")
    {
		obj.className = "checkbox_checked";
 		obj.src = ""+skinImageSrc+"images/checkbox_checked.gif";
	 }	
	 else
	{
		obj.className = "checkbox";
 		obj.src = ""+skinImageSrc+"images/checkbox.gif";
	}

}

function NoticeData() {
	this.visible = true;
	this.name = "";
	this.item = new Array();
	this.itemid = new Array();
	this.itemcount = 0;
}

function NoticeScroll() {

	this.name = "NoticeScroll";
	this.divId = "";
	this.frmId = "";

	this.allitemcount = 0;
	this.showitemcount = 0;

	this.currentspeed = 0;
	this.scrollspeed = 1;
	this.pausedelay = 2400;
	this.pausemouseover = true;
	this.stop = false;
	this.height = 100;
	this.width = 100;
	
	this.i = 0;

	this.notice_notice = null;
	this.notice_article = null;
	this.notice_trackback = null;
	this.notice_comment = null;

	this.addcomment = function () {
		var div_name = arguments[0];
	
		var anchors = document.getElementsByName("hidden_comment_data_list_data");

		for (var i=0; i<anchors.length; i++) {
			
			anchor = anchors[i];
			
			this.notice_comment.item[this.notice_comment.itemcount] = anchor.innerHTML;
			this.notice_comment.itemcount = this.notice_comment.itemcount + 1;
			
			if (this.notice_comment.visible)
				{
					this.showitemcount += 1;
				}

			this.allitemcount = this.allitemcount + 1;
				
		}
	};


	this.add = function () {
		var text = arguments[0];
		var type = arguments[1];
		
		switch(type)
		{
			case 'notice':
			{
				this.notice_notice.item[this.notice_notice.itemcount] = text;
				this.notice_notice.itemcount = this.notice_notice.itemcount + 1;
				if (this.notice_notice.visible)
				{
					this.showitemcount += 1;
				}
			}
				break
			case 'article':
			{
				this.notice_article.item[this.notice_article.itemcount] = text;
				this.notice_article.itemcount = this.notice_article.itemcount + 1;
				if (this.notice_article.visible)
				{
					this.showitemcount += 1;
				}
			}
				break
			case 'trackback':
			{
				this.notice_trackback.item[this.notice_trackback.itemcount] = text;
				this.notice_trackback.itemcount = this.notice_trackback.itemcount + 1;
				if (this.notice_trackback.visible)
				{
					this.showitemcount += 1;
				}
			}
				break
		}

		this.allitemcount = this.allitemcount + 1;
			
		
	};

	this.init = function () {
		
		var cookie;

		this.notice_notice = new NoticeData();
		this.notice_notice.name = "notice_notice";

		this.notice_article = new NoticeData();
		this.notice_article.name = "notice_article";
		
		this.notice_trackback = new NoticeData();
		this.notice_trackback.name = "notice_trackback";

		this.notice_comment = new NoticeData();
		this.notice_comment.name = "notice_comment";

		cookie = getCookie('shownotice_notice');
		if (cookie == false)
		{
			setCookie('shownotice_notice' , 'true');
			this.notice_notice.visible = true;
		}
		else
		{
			this.notice_notice.visible = cookie == "true";
		}

		cookie = getCookie('shownotice_article');
		if (cookie == false)
		{
			setCookie('shownotice_article' , 'true');
			this.notice_article.visible = true;
		}
		else
		{
			this.notice_article.visible = cookie == "true";
		}

		cookie = getCookie('shownotice_trackback');
		if (cookie == false)
		{
			setCookie('shownotice_trackback' , 'true');
			this.notice_trackback.visible = true;
		}
		else
		{
			this.notice_trackback.visible = cookie == "true";
		}

		cookie = getCookie('shownotice_comment');
		if (cookie == false)
		{
			setCookie('shownotice_comment' , 'true');
			this.notice_comment.visible = true;
		}
		else
		{
			this.notice_comment.visible = cookie == "true";
		}
	}

	this.start = function () {
		this.divId = arguments[0];

		this.display();

		this.currentspeed = this.scrollspeed;
		this.stop = true;

		setTimeout(this.name+'.scroll()',this.currentspeed);

		if ( this.showitemcount > 1 )
		{
			window.setTimeout(this.name+".stop = false", this.pausedelay);
		}
	};

	this.display = function () {
        var htmlCode;
		var i2 = 0;
		var d = "none";


		htmlCode = '<div id="'+this.name+'" style="position:relative; float:left; left:0px; top:0px; margin-top:3px; width:'+(this.width-17)+'px; height:'+this.height+'px; overflow:hidden;" OnMouseOver="'+this.name+'.onmouseover(); " OnMouseOut="'+this.name+'.onmouseout(); ">';
		
		htmlCode += '<div id="'+this.notice_notice.name+'" style="display:none;">';
		for(var i = 0; i < this.notice_notice.itemcount; i++) {
				this.notice_notice.itemid[i] = this.name+'item'+i2;
				htmlCode += '<div id="'+ this.notice_notice.itemid[i] +'" style="position:absolute; left:6px; top:' + this.height*i2 + 'px;">';
				htmlCode +=  '<div class="notice_icon_notice"></div><div class="link_bg">' + this.notice_notice.item[i] + '</div><div class="clear"></div>';
				htmlCode += '</div>';

				i2 += 1;
		}

		htmlCode += '</div><div id="'+this.notice_article.name+'" style="display:none;">';
		for(var i = 0; i < this.notice_article.itemcount; i++) {
				this.notice_article.itemid[i] = this.name+'item'+i2;
				htmlCode += '<div id="'+ this.notice_article.itemid[i] +'" style="position:absolute; left:6px; top:' + this.height*i2 + 'px;">';
				htmlCode +=  '<div class="notice_icon_article"></div><div class="link_bg">' + this.notice_article.item[i] + '</div><div class="clear"></div>';
				htmlCode += '</div>';

				i2 += 1;
		}

		htmlCode += '</div><div id="'+this.notice_trackback.name+'" style="display:none;">';

		for(var i = 0; i < this.notice_trackback.itemcount; i++) {
				this.notice_trackback.itemid[i] = this.name+'item'+i2;
				htmlCode += '<div id="'+ this.notice_trackback.itemid[i] +'" style="position:absolute; left:6px; top:' + this.height*i2 + 'px;">';
				htmlCode +=  '<div class="notice_icon_trackback"></div><div class="link_bg">' + this.notice_trackback.item[i] + '</div><div class="clear"></div>';
				htmlCode += '</div>';

				i2 += 1;
		}

		htmlCode += '</div><div id="'+this.notice_comment.name+'" style="display:none;">';

		for(var i = 0; i < this.notice_comment.itemcount; i++) {
				this.notice_comment.itemid[i] = this.name+'item'+i2;
				htmlCode += '<div id="'+ this.notice_comment.itemid[i] +'" style="position:absolute; left:6px; top:' + this.height*i2 + 'px;">';
				htmlCode +=  '<div class="notice_icon_comment"></div><div class="link_bg">' + this.notice_comment.item[i] + '</div><div class="clear"></div>';
				htmlCode += '</div>';

				i2 += 1;
		}

		htmlCode += '</div></div><div class="notice_sub"  style="margin-top:3px;"><a href="javascript:'+ this.name +'.toggle_window();"><img src="'+skinImageSrc+'images/notice_sub.gif" border=0 id="notice_toggle_img"></a></div>';
	
		document.getElementById(this.divId).innerHTML = htmlCode;  

		this.change_top_list();
	};
	
	this.makewindow = function () {
		this.frmId = arguments[0];
		
		this.changepos();

		this.window_display();

	};

	this.changepos = function () {
		var obj = document.getElementById(this.divId);
		var frmobj = document.getElementById(this.frmId).style;
		
		var x = getRealX(obj);
		var y = getRealY(obj);

		frmobj.left = x + 'px';
		frmobj.top =  (y + this.height + 6) + 'px';
		frmobj.width = (this.width)+'px';
	};

	this.closewindow = function () {		
		 
		 obj = document.getElementById(this.frmId);

		 if(obj.style.display != "none"){			
			 var img = document.getElementById('notice_toggle_img');
			 img.src = skinImageSrc+'images/notice_sub.gif';

			 obj.style.display = "none";
		 }
	}
	
	this.window_display_now = function () {
		
			var htmlCode = "";
			var vi = 0;

			obj = document.getElementById('notice_checkbox');
			
			if (obj.className == 'checkbox_checked')
			{
				htmlCode += '공지,';
				vi += 1;
			}
	
			obj = document.getElementById('article_checkbox');
			if (obj.className == 'checkbox_checked')
			{
				htmlCode += '최근글,';
				vi += 1;
			}
		
			obj = document.getElementById('trackback_checkbox');
			if (obj.className == 'checkbox_checked')
			{
				htmlCode += '최근트랙백,';
				vi += 1;												
			}

			obj = document.getElementById('comment_checkbox');
			if (obj.className == 'checkbox_checked')
			{
				htmlCode += '최근댓글,';
				vi += 1;			
			}

		obj = document.getElementById('notice_window_nowshow');		

		if (vi == 0)
		{
			obj.innerHTML = '공지창에 아무것도 표시하지않음';
		}
		else
		{
			htmlCode = htmlCode.substring(0,htmlCode.length-1);
			obj.innerHTML = '공지창에' + htmlCode + '를 표시함';
		}


	}

	this.window_display = function () {
		var htmlCode;
		var frmobj = document.getElementById(this.frmId).style;
		var checkbox_visible =  "";
		var checkbox_src = "";

		htmlCode = '<div id="'+this.name+'" style="left:0px; top:0px; width:'+frmobj.width+'px; height:'+frmobj.height+'px;">';
				
		if (this.notice_notice.visible)
		{
			checkbox_visible = "checkbox_checked";
			checkbox_src = skinImageSrc+"images/checkbox_checked.gif";
		}
		else
		{
			checkbox_visible = "checkbox";
			checkbox_src = skinImageSrc+"images/checkbox.gif";
		}

			htmlCode += '<div class="notice_subject"><div class="notice_window_title"><B>notice : </B></div><div class="notice_checkbox_div notice_window_title_checkbox"><a href="javascript:toggle_checkbox(\'notice_checkbox\');' + this.name  + '.window_display_now();' + this.name + '.noticeinfo_change(\'notice_checkbox\',\'shownotice_notice\');" title="선택하면 공지창에 표시합니다."><img src="'+ checkbox_src +'" border="0"  id="notice_checkbox" class="' + checkbox_visible + '"></a></div><div class="clear"></div></div>';

			for(var i = 0; i < this.notice_notice.itemcount; i++) {
				htmlCode += '<div id="notice_window_data" name="notice_window_data" ><div class="link_margin"></div><div class="link_bg2">' + this.notice_notice.item[i] + '</div></div>';
			}

		htmlCode += '<div class="notice_window_line"></div>';
	
		if (this.notice_article.visible)
		{
			checkbox_visible = "checkbox_checked";
			checkbox_src = skinImageSrc+"images/checkbox_checked.gif";
		}
		else
		{
			checkbox_visible = "checkbox";
			checkbox_src = skinImageSrc+"images/checkbox.gif";
		}

			htmlCode += '<div class="notice_subject"><div class="notice_window_title"><B>recent article : </B></div><div class="notice_checkbox_div notice_window_title_checkbox"><a href="javascript:toggle_checkbox(\'article_checkbox\');' + this.name  + '.window_display_now();' + this.name + '.noticeinfo_change(\'article_checkbox\',\'shownotice_article\');" title="선택하면 공지창에 표시합니다."><img src="'+ checkbox_src +'" border="0"  id="article_checkbox" class="' + checkbox_visible + '"></a></div><div class="clear"></div></div>';

			for(var i = 0; i < this.notice_article.itemcount; i++) {
				htmlCode += '<div id="notice_window_data" name="notice_window_data"><div class="link_margin"></div><div class="link_bg2">' + this.notice_article.item[i] + '</div></div>';
			}

		htmlCode += '<div class="notice_window_line"></div>';
	
		if (this.notice_trackback.visible)
		{
			checkbox_visible = "checkbox_checked";
			checkbox_src = skinImageSrc+"images/checkbox_checked.gif";
		}
		else
		{
			checkbox_visible = "checkbox";
			checkbox_src = skinImageSrc+"images/checkbox.gif";
		}

			htmlCode += '<div class="notice_subject"><div class="notice_window_title"><B>recent trackback : </B></div><div class="notice_checkbox_div notice_window_title_checkbox"><a href="javascript:toggle_checkbox(\'trackback_checkbox\');' + this.name  + '.window_display_now();' + this.name + '.noticeinfo_change(\'trackback_checkbox\',\'shownotice_trackback\');" title="선택하면 공지창에 표시합니다."><img src="'+ checkbox_src +'" border="0"  id="trackback_checkbox" class="' + checkbox_visible + '"></a></div><div class="clear"></div></div>';

			for(var i = 0; i < this.notice_trackback.itemcount; i++) {
				htmlCode += '<div id="notice_window_data" name="notice_window_data"><div class="link_margin"></div><div class="link_bg2">' + this.notice_trackback.item[i] + '</div></div>';
			}					

		htmlCode += '<div class="notice_window_line"></div>';
		
		if (this.notice_comment.visible)
		{
			checkbox_visible = "checkbox_checked";
			checkbox_src = skinImageSrc+"images/checkbox_checked.gif";
		}
		else
		{
			checkbox_visible = "checkbox";
			checkbox_src = skinImageSrc+"images/checkbox.gif";
		}
		
			htmlCode += '<div class="notice_subject"><div class="notice_window_title"><B>recent comment : </B></div><div class="notice_checkbox_div notice_window_title_checkbox"><a href="javascript:toggle_checkbox(\'comment_checkbox\');' + this.name  + '.window_display_now();' + this.name + '.noticeinfo_change(\'comment_checkbox\',\'shownotice_comment\');" title="선택하면 공지창에 표시합니다."><img src="'+ checkbox_src +'" border="0"  id="comment_checkbox" class="' + checkbox_visible + '"></a></div><div class="clear"></div></div>';

			for(var i = 0; i < this.notice_comment.itemcount; i++) {
				htmlCode += '<div id="notice_window_data" name="notice_window_data"><div class="link_margin"></div><div class="link_bg2">' + this.notice_comment.item[i] + '</div></div>';
			}

		htmlCode += '<div class="notice_window_line"></div>';

		htmlCode += '<div id="notice_window_nowshow">&nbsp;</div>';
		htmlCode += '</div>';

		document.getElementById(this.frmId).innerHTML = htmlCode;  		
		
		this.window_display_now();
	}

	
	this.scroll_v = function( obj_scroll ) {

		if (obj_scroll.visible)
		{
			for (var i=0;i<obj_scroll.itemcount;i++ )
			{
				obj = document.getElementById(obj_scroll.itemid[i]).style;
				obj.top = (parseInt(obj.top) - 1) + 'px';

				if ( parseInt(obj.top) <= this.height * (-1) ) 
				{	
					obj.top = (this.height * (this.showitemcount-1)) + 'px';
				}
				if ( parseInt(obj.top) == 0 ) {
					this.currentspeed = this.pausedelay;
				}
			}
		}

	};

	this.scroll = function () {
			
			this.currentspeed = this.scrollspeed;

			if ( !this.stop ) {
				this.scroll_v( this.notice_notice );
				this.scroll_v( this.notice_article );
				this.scroll_v( this.notice_trackback );
				this.scroll_v( this.notice_comment );
			}

			window.setTimeout(this.name+".scroll()",this.currentspeed);
	};

	this.change_top_list_v = function( obj_scroll , t ) {
		
		if (obj_scroll.visible)
		{		
			for (var i=0;i<obj_scroll.itemcount;i++ )
			{
				obj = document.getElementById(obj_scroll.itemid[i]).style;
				obj.top = t +'px';

				t += this.height;
			}

			obj = document.getElementById(obj_scroll.name).style;
			obj.display = '';
		}
		else
		{
			obj = document.getElementById(obj_scroll.name).style;
			obj.display = 'none';
		}

		return t;

	};

	this.change_top_list = function() {

			var top = 0;

			top = this.change_top_list_v( this.notice_notice , top );
			top = this.change_top_list_v( this.notice_article , top );
			top = this.change_top_list_v( this.notice_trackback , top );
			this.change_top_list_v( this.notice_comment , top  );

	};

	this.onmouseover = function () {
		if ( this.pausemouseover ) {
			this.stop = true;
		}
	};
	
	this.onmouseout = function () {
		if ( this.pausemouseover ) {		
			if (this.showitemcount <= 1)
			{
				this.stop = true;
			}
			else
			{
				this.stop = false;
			}
		}
	};	

	this.toggle_window = function () {
		obj = document.getElementById(this.frmId);

		 if(obj.style.display == "none"){	
			 this.changepos();
			 obj.style.display = "block";
			 obj = document.getElementById('notice_toggle_img');
			 obj.src = skinImageSrc+'images/notice_sub2.gif';
		 }
		 else {
			 obj.style.display = "none";
			 obj = document.getElementById('notice_toggle_img');
			 obj.src = skinImageSrc+'images/notice_sub.gif';
		 }


	};

	this.noticeinfo_change = function( objid , cookiename ) {

		var v;
		obj = document.getElementById(objid);

		if (obj.className == "checkbox")
		{
			setCookie( cookiename , "false" );
			v = false;
		 }	
		 else
		{
			setCookie( cookiename , "true" );
			v = true;
		}

		switch( cookiename )
		{
			case "shownotice_notice":
					this.notice_notice.visible = v;
					if (v)
					{
						this.showitemcount += this.notice_notice.itemcount;
					}
					else
					{
						this.showitemcount -= this.notice_notice.itemcount;
					}
				break
			case "shownotice_article":
					this.notice_article.visible = v;
					if (v)
					{
						this.showitemcount += this.notice_article.itemcount;
					}
					else
					{
						this.showitemcount -= this.notice_article.itemcount;
					}
				break
			case "shownotice_trackback":
					this.notice_trackback.visible = v;
					if (v)
					{
						this.showitemcount += this.notice_trackback.itemcount;
					}
					else
					{
						this.showitemcount -= this.notice_trackback.itemcount;
					}
				break
			case "shownotice_comment":
					this.notice_comment.visible = v;
					if (v)
					{
						this.showitemcount += this.notice_comment.itemcount;
					}
					else
					{
						this.showitemcount -= this.notice_comment.itemcount;
					}
				break

		}


		this.change_top_list();

	};
	
}

function ArchiveList()  {
	this.name = "archivelist";
	this.item = new Array();
	this.itemcount = 0;
	this.divId = "";
	this.frmId = "";

	this.add = function() {
		var text =  arguments[0];
		var link =  arguments[1];
		var count = arguments[2];

		this.item[this.itemcount] = "<a href='"+ link +"' title='"+text+" 검색' >" + text + " (" +  count + ") </a>";
		this.itemcount = this.itemcount + 1;
	};

	this.start = function ()  {
		this.divId = arguments[0];
		var htmlCode ="";

		htmlCode += '<div id="archivelist_data"><B>archive</B></div>';
		htmlCode += '<div id="archivelist_sub"><a href="javascript:'+ this.name +'.toggle_window();"><img src="'+skinImageSrc+'images/notice_sub.gif" border=0 id="archive_toggle_img"></a></div>';
			
		document.getElementById(this.divId).innerHTML = htmlCode; 
	};


	this.makewindow = function () {
		this.frmId = arguments[0];	
		
		var frmobj = document.getElementById(this.frmId).style;

		frmobj.width = (document.getElementById(this.divId).offsetWidth)+'px';

		this.window_display();

	};

	this.changewindow = function () {
		
			var obj = document.getElementById(this.divId);
			var frmobj = document.getElementById(this.frmId).style;
			
			var x = getRealX(obj);
			var y = getRealY(obj);


			frmobj.left = (x) + 'px';
			frmobj.top =  (y + this.height + 3) + 'px';	
		
	};

	this.closewindow = function () {		
		 
		 obj = document.getElementById(this.frmId);

		 if(obj.style.display != "none"){			
			 var img = document.getElementById('archive_toggle_img');
			 img.src = skinImageSrc+'images/notice_sub.gif';

			 obj.style.display = "none";
		 }
	}

	this.toggle_window = function () {
		 obj = document.getElementById(this.frmId);

		 if(obj.style.display == "none"){			
		
			 this.changewindow();
			 obj.style.display = "block";
			 obj = document.getElementById('archive_toggle_img');
			 obj.src = skinImageSrc+'images/notice_sub2.gif';
		 }
		 else {
			 obj.style.display = "none";
			 obj = document.getElementById('archive_toggle_img');
			 obj.src = skinImageSrc+'images/notice_sub.gif';

		 }
	};

	this.window_display = function () {
		var frmobj = document.getElementById(this.frmId).style;

		var htmlCode = '<div style="left:0px; top:0px; width:'+frmobj.width+'px; height:'+frmobj.height+'px;">';
				
		for(var i = 0; i < this.itemcount; i++) {
				htmlCode += '<div id="archive_data" name="archive_data" onmouseover="this.className=\'archive_data_hover\'" onmouseout="this.className=\'\'">' + this.item[i] + '</div>';
			}

		htmlCode += '</div>';

		document.getElementById(this.frmId).innerHTML = htmlCode;
	};
}