var sa = new Object();

sa.Scroll = function() {
	this.version = "0.2";
	this.name = "sascroll";
	this.divId = "";
	this.item = new Array();
	this.itemcount = 0;
	this.currentspeed = 0;
	this.scrollspeed = 50;
	this.pausedelay = 1000;
	this.pausemouseover = false; //true
	this.stop = false;
	this.height = 93;  //100
	this.width = 226;   //150
	this.stopHeight=0;
	this.i=0;
	this.reloadData = 0;
	this.currentlocation = 0;
}

sa.Scroll.prototype = {
	add : function (text) {
		this.item[this.itemcount] = text;
		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 = '<span id="'+this.name+'" style="height:'+this.height+'px; width:'+(this.width * 2)+'px; position:absolute; overflow:hidden; padding:0 0 0 0;" onmouseover="'+this.name+'.onmouseover(); " onmouseout="'+this.name+'.onmouseout(); ">';
		for(var i = 0; i < this.itemcount; i++) {
			htmlCode += '<span id="'+this.name+'item'+i+'"style="left:' + (this.width*i) + 'px; width:'+this.width+'; position:absolute; top:0px;padding:0 0 0 0;text-align:center;">';
			htmlCode += this.item[i];
			htmlCode += '</span>';
		}
		htmlCode += '</span>';
		document.getElementById(this.divId).innerHTML=htmlCode;
		
	},
	
	scroll : function (div) {
		this.currentspeed = this.scrollspeed; //½ºÅ©·ÑÅ¸ÀÓ
		if ( !this.stop ) { //½ºÅ©·ÑÅ¸ÀÓ
			for (var i = 0; i < this.itemcount; i++) {
				obj = document.getElementById(this.name+'item'+i).style;

				if (div > 0) {
					obj.left = parseInt(obj.left) - this.width;
					if ( parseInt(obj.left) <= this.left * (-1) ) obj.left = this.width *  (this.itemcount-1);
					if ( parseInt(obj.left) == 0 ) {
						this.currentspeed = this.pausedelay;
						this.i = i;
						this.stop = true;
					}
				}
				else if (div < 0) {
					obj.left = parseInt(obj.left) + this.width;
					if ( parseInt(obj.left) > this.left ) obj.left = (-1) * this.width * (this.itemcount-1);
					if ( parseInt(obj.left) == 0 ) {
						this.currentspeed = this.pausedelay;
						this.i = i;
						this.stop = true;
					}
				}
			}
		}
		
		window.setTimeout(this.name+".scroll(" + div + ")",this.currentspeed);
	},

	move_prev : function () {
		if (this.currentlocation > 0) {
			this.currentlocation--;
		}
		else {
			return;
		}

		this.stop = false;
		this.scroll(-1);
	},

	move_next : function () {
		if ((this.itemcount - this.currentlocation) > 2) {
			this.currentlocation++;
		}
		else {
			return;
		}

		this.stop = false;
		this.scroll(1);
	}
}

sa.Ranking = function(scrollWidth, divid, scrollname){
	this.sascroll = new sa.Scroll();
	this.sascroll.name = "";
	this.sascroll.name = scrollname;
	this.sascroll.height = 226;   //110
	this.sascroll.width = scrollWidth;
	this.sascroll.scrollspeed = 1;
	this.sascroll.pausedelay = 2000;
	this.sascroll.pausemouseover = true;
	this.sascroll.divId = divid;
}

sa.Ranking.prototype = {
	init : function(){
		this.sascroll.setDivId(this.sascroll.divId);
		this.sascroll.onmouseover = function() {}
		this.sascroll.onmouseout = function() {}
	},
	add : function(text){
		this.sascroll.add(text);
	},
	start : function(){
		this.init();
		this.sascroll.start();
	}
}

