hfscroll = function() {
	this.version = "0.2";
	this.name = "hfscroll";
	this.divId = "";
	this.item = new Array();
	this.itemcount = 0;
	this.currentspeed = 0;
	this.scrollspeed = 50;
	this.pausedelay = 1000;
	this.pausemouseover = false;
	this.stop = false;
	this.height = 100;
	this.width = 100;
	this.stopHeight=0;
	this.i=0;
	this.reloadData = 0;
	this.scrollHeight = 1;
}
hfscroll.prototype = {
	add : function () {
		var title = arguments[0];
		var rank = arguments[1];
		var oper = arguments[2];
        var url = arguments[3];
		if (oper=="+"){operimg="icon_up.gif";}
		else if (oper=="-"){operimg="icon_down.gif";}
		else{operimg="new.gif";}
		var searchhtmlCode;

        if(url==null) {
		    searchhtmlCode = '<img style="padding: 1px 0 0 0; float: left;" src="http://www.casa.co.kr/comm2/img/n'+ (this.itemcount+1) +'.gif" alt=""/> <a href="javascript:hot_keyword_search_form(\''+title+'\');" title="'+title+'" style="padding: 1px 0 0 0; display: block; float: left; width: 100px;">'+title+'</a>';
        } else {
            searchhtmlCode = '<img style="padding: 1px 0 0 0; float: left;" src="http://www.casa.co.kr/comm2/img/n'+ (this.itemcount+1) +'.gif" alt=""/> <a href="'+url+'" title="'+title+'" style="padding: 1px 0 0 0; display: block; float: left; width: 100px;">'+title+'</a>';
        }

		if (operimg=="new.gif"){
		searchhtmlCode += '<span style="float: left;"></span>';
		}else{
		searchhtmlCode += '<span style="float: left; margin:2px 0 0 0;"><img src="http://main.imgcss.com/090601/images/'+operimg+'" alt=""/></span>';
		searchhtmlCode += '<span style="float: left; width: 30px; margin:1px 0 0 2px;">'+rank+'<span>';
		}
		searchhtmlCode += '';
		this.item[this.itemcount] = searchhtmlCode;
		this.itemcount = this.itemcount + 1;
	},
	setDivId : function(name) {
			this.divId = name
	},
	start : function () {
		if ( this.itemcount == 1 ) {
			this.add(this.item[0]);
		}
		this.display();
		this.currentspeed = this.scrollspeed;
		this.stop = true;
		setTimeout(this.name+'.scroll()',this.currentspeed);
		window.setTimeout(this.name+".stop = false", this.pausedelay);
	},
	display : function () {
		var htmlCode;
		htmlCode = '<div id="'+this.name+'" style="height:'+this.height+'px; width:'+this.width+'px;position:relative;">';
		for(var i = 0; i < this.itemcount; i++) {
			htmlCode += '<div id="'+this.name+'item'+i+'" style="left:0; width:'+this.width+'px; position:absolute; top:'+((this.height)*i)+'px; ">';
			htmlCode += this.item[i];
			htmlCode += '</div>';
		}
		htmlCode += '</div>';
//alert(this.divId);		


//		document.search.aaaa.value = htmlCode;
		document.getElementById(this.divId).innerHTML=htmlCode;

	},

	scroll : function () {

		this.currentspeed = this.scrollspeed;
		if ( !this.stop ) {
			
			for (var i = 0; i < this.itemcount; i++) {
				
			obj = document.getElementById(this.name+'item'+i).style;
			obj.top = parseInt(obj.top) - this.scrollHeight;
				if(parseInt(obj.top) <= this.height * (-1)){
				obj.top = this.height * (this.itemcount-1);
				}
				if(parseInt(obj.top) == 0){
				this.currentspeed = this.pausedelay;
				this.i = i;
				}
			}
		}

	window.setTimeout(this.name+".scroll()",this.currentspeed);
	},
	onmouseover : function () {},
	onmouseout : function () {}
}

Ranking = function(){
	this.hfscroll = new hfscroll();
	this.hfscroll.name = "";
	this.hfscroll.name = "quicknewstop.hfscroll";
	this.hfscroll.height = 20;
	this.hfscroll.width = 300;
	this.hfscroll.scrollspeed = 1;
	this.hfscroll.pausedelay = 2000;
	this.hfscroll.pausemouseover = true;
}

Ranking.prototype = {
	init : function(){
		this.hfscroll.setDivId("list");

		this.hfscroll.onmouseover = function() {
	
			if( this.i < 5 ) msg('IssueLayer01');
			else msg('IssueLayer02');

			if ( this.pausemouseover ) {
				this.stop = true;
			}
		
			for( var i = 0; i < 10; ++i ) {
				var ii = i + 1;
				
				if( ii < 10 ) ii = "r0" + ii;
				else ii = "r" + ii;
				var itemObj = document.getElementById(ii);
				if( itemObj ) {
					if( i == this.i ) itemObj.style.fontWeight='bold';
					else itemObj.style.fontWeight='normal';
				}
			}
		}
		this.hfscroll.onmouseout = function() {
			if ( this.pausemouseover ) {
				this.stop = false;
			}
		}
	
	},
	add : function(text1,text2,text3,text4){
		this.hfscroll.add(text1,text2,text3,text4);
	},
	start : function(){
		this.init();
		this.hfscroll.start();
	},
	onmouseover : function(){
		this.hfscroll.onmouseover();
	},
	onmouseout : function(){
		this.hfscroll.onmouseout();
	}
}

var msg_hidden_idle=null;

function msg(id) {
	if(msg_hidden_idle) {
		clearInterval(msg_hidden_idle);
	}
	var _div_tag = document.getElementsByTagName("div");


	for (var i=0;i<_div_tag.length;i++) {
		if (_div_tag[i].id.indexOf('IssueLayer')==0) {
//	alert(i);
		_div_tag[i].style.display = 'none';
		_div_tag[i].style.visibility = 'hidden';
		}
	}
	if(id) {
		var tot=document.getElementById("IssueLayerTot");
		tot.style.display='';
		tot.style.visibility='visible';
		var mid=document.getElementById(id);
		mid.style.display='block';
		mid.style.visibility='visible';
	}
}

function msg_hidden(id,f) {
	if(f==1) {
		hidden(id);
	}else{
		msg_hidden_idle=setInterval("hidden('"+id+"')",100);
	}
}

function hidden(id) {
	var tot=document.getElementById("IssueLayerTot");
	tot.style.display='none';
	tot.style.visibility='hidden';

	var mid=document.getElementById(id);
	mid.style.display='none';
	mid.style.visibility='hidden';
}

function cut(keyword) {
	var str = keyword;
    str = str.replace(" ","");
	var l = 0;
	for (var i=0; i<str.length; i++) {
	l += (str.charCodeAt(i) > 128) ? 2 : 1;
	if (l > 15) return str.substring(0,i)+'..';
	}
	return str;
}
