function viewMenu(elem){
	$(elem).toggle();
	PopSerial();
}

function closeMenu(elem){
	$(elem).hide();
	PopSerial();
}

var HiddenMenu = {
	view:function(elem){
		$(elem).setStyle({
			'display' : 'block'
		});
	},
	hide:function(elem){
		$(elem).setStyle({
			'display' : 'none'	
		});
	}
};

TextRolling = Class.create({
	index:0,
	pos:0,
	option:{
		term: 2000,
		moveSize: 18,
		interval: 30,
		step: 1
	},
	suspension:true,
	wait:null,
	move:null,
	initialize:function(obj){
		this.obj = $(obj);
	},
	setOption:function(item, options){
		this.item = item;
		Object.extend(this.option, options||{});
		this.scrollTo(0);
		this.resume();
	},
	scrollTo: function(pos){
		pos = pos % ((this.item.length-1) * this.option.moveSize);
		this.setScrollPos(pos);
	},
	setScrollPos: function(pos){
		this.obj["scrollTop"] = pos;
	},
	getScrollPos: function(){
		return this.obj["scrollTop"];
	},
	resume:function(){
		this.suspension = false;
		if(!this.move){this.startWait();}
	},
	pause: function(){
		this.suspnesion = true;
		this.stopWait();
	},
	startWait:function(){
		if(this.suspension)return;
		this.stopWait()
		this.stopMove();
		this.wait = setTimeout(this.startMove.bind(this), this.option.term);
	},
	stopWait:function(){
		if(this.wait){
			clearTimeout(this.wait);
		}
		this.wait = null;
	},
	startMove:function(){
		this.stopWait();
		this.stopMove();
		this.index = 0;
		this.move = setInterval(this.change.bind(this), this.option.interval);
	},
	stopMove:function(){
		if(this.move){
			clearInterval(this.move);
		}
		this.move = null;
	},
	change: function(){
		if(this.index >= this.option.moveSize){
			this.startWait();
			return;
		}
		this.index += this.option.step;
		this.scrollTo(this.getScrollPos()+this.option.step);
	},
	moveState: function(item){
		citem = item * this.option.moveSize;
		this.scrollTo(citem);
		this.startWait();
	},
	getItem: function(){
		var nowItem=this.getScrollPos();
		return Math.round(nowItem/this.option.moveSize);
	}
});

var getAjax = {
	option: {},
	Value : function(func, url, options){
		Object.extend(this.option, options||{});
		new Ajax.Request(url,{
			method: 'post',
			parameters : this.option,
			onSuccess : function(msg){ func.apply(null, arguments) },
			onFailure : function(){}
		});
	}
};

function paging(obj, pageNum){
	obj.pageNum.value = pageNum;
	obj.submit();
}

function set_cookie( name, value, expiredays ) { 
	var todayDate = new Date(); 
	todayDate.setDate( todayDate.getDate() + expiredays ); 
	document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";" 
}

function get_cookie ( cookie_name ){
	var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );
	if ( results )    
		return ( unescape ( results[2] ) );  
	else    
		return null;
}

// 연재 검색 추가 Notice 팝업
function PopSerial(){
	if(!get_cookie("SerialSearch") || get_cookie("SerialSearch") != "done"){
		if($('menulist').style.display == 'none'){
			$('SearchString').removeClassName('SearchTextBox');
			HiddenMenu.view('serialPopNotice');
		}else {
			HiddenMenu.hide('serialPopNotice');
			PopSerialFocusable.Blur();
		}
	}else {
		closeSerialPop();
		PopSerialFocusable.Blur();
		HiddenMenu.hide('serialPopNotice');
	}
}

var PopSerialFocusable = {
	Focus : function(){
		if(newTrim($('SearchString').value).length == 0){
			$('SearchString').removeClassName('SearchTextBox');
		}
	},
	Blur : function(){
		if(newTrim($('SearchString').value).length == 0){
			$('SearchString').addClassName('SearchTextBox');
		}
	}
}

function closeSerialPop(){
	set_cookie("SerialSearch", "done", 365);
	HiddenMenu.hide('serialPopNotice');
}
