/**
* ÆÄÀÏ¸í: lib.textSlider.js
* ¼³  ¸í: ´º½º Ticker ¶óÀÌºê·¯¸®
* ÀÛ¼ºÀÚ: tenshi[±è±º¿ì] - jstoy project
* ³¯  Â¥: 2004-03-25

var PM = new TextSlider('PM'); // Å¬·¡½º ¸íÀ» ÀÎÀÚ·Î ³Ñ±ä´Ù.
PM.item_array = [ // ÄÁÅÙÃ÷¸¦ ¹è¿­·Î ÀÔ·Â
	'Å×½ºÆ®ÀÔ´Ï´Ù 1',
	'<a href="http://google.co.kr">±¸±ÛÀÔ´Ï´Ù 2</a>',
	'Å×½ºÆ®ÀÔ´Ï´Ù 3'
]; 
PM.width = 145; // TickerÀÇ °¡·Î±æÀÌ
PM.height = 40; // TickerÀÇ ¼¼·Î±æÀÌ
PM.speed = 50; // text°¡ slideµÇ´Â ºü¸£±â. ´ÜÀ§´Â ms
PM.pixel = 1;  // text°¡ ÇÑ¹ø slideÇÒ ¶§ ¿òÁ÷ÀÏ ÇÈ¼¿.
PM.interval = 1000; // text°¡ slideµÈ ÈÄ ´ÙÀ½ text°¡ slideµÇ±â ±îÁöÀÇ ´ë±â½Ã°£
PM.size = 50;  // text°£ÀÇ °£°Ý. height¿Í °°°Å³ª Å©°Ô ÇÏ¿©¾ß Á¦´ë·Î º¸ÀÎ´Ù.
PM.direction = 'up'; // text°¡ slideµÉ ¹æÇâ
PM.align = 'left'; // textÀÇ Á¤·Ä (left|right)
PM.init(); // TextSliderÀÇ ÀÛµ¿À» Áö½ÃÇÑ´Ù.

¸ÞÀÎ¿¡ ÁÖ¿äÇà»ç, ½ºÇÇµå±¸ÀÎ¿¡ »ç¿ë
***********************************************
*/

TextSlider = function(className) {
    document.write("<div id='TextSliderPLayer_"+ className +"'><div id='TextSliderLayer_"+ className +"'></div></div>");

    this.item_array = [];	
    this.width = this.height = this.speed = this.pixel = this.interval = this.size = this.moveCount = this.X = this.Y = 0;
    this.direction = "";
    this.pLayer = document.getElementById("TextSliderPLayer_"+ className);
    this.layer = document.getElementById("TextSliderLayer_"+ className);
    this.align = "left";
    this.intervalId = null;
    this.className = className;
    this.isPause = false;
}
TextSlider.prototype.init = function() {
    with (this.pLayer.style) {
        width = this.width+"px";
        height = this.height+"px";
        overflow = "hidden";
		position = "absolute";
    }
    with (this.layer.style) {
        width = this.direction=='up' || this.direction=='down' ? this.width+"px" : this.size*(this.item_array.length+1)+"px";
        height = this.direction=='up' || this.direction=='down' ? this.size*(this.item_array.length+1)+"px" : this.height+"px";
        top = 0;
        left = 0;
        position = "relative";
    }
	if (this.speed)
	{
		if (this.direction=='up' || this.direction=='down')
		{		
			for (var i=0; i<parseInt(this.height / this.size, 10)+1; i++)
				this.item_array[this.item_array.length] = this.item_array[i];
		}
		else
		{
			for (var i=0; i<parseInt(this.width / this.size, 10)+1; i++)
				this.item_array[this.item_array.length] = this.item_array[i];
		}
	}
    switch (this.direction) {
        case "up": this.X = this.Y = 0; break;
        case "down": this.X = 0; this.layer.style.top = this.Y = -this.size*(this.item_array.length-1); break;
        case "left": this.X = this.Y = 0; break;
        case "right": this.Y = 0; this.layer.style.left = this.X = -this.size*(this.item_array.length-1); break;
    }
    var __html = "<div onmouseover='"+this.className+".pause()' onmouseout='"+this.className+".unpause()'>";
    if (this.direction=='up' || this.direction=='down') {
        __html += "<table width='"+ this.layer.style.width +"' cellspacing='0' cellpadding='0' border='0'>";		
        for (i=0; i<this.item_array.length; i++)
		{
			__html += "<tr><td height='" + this.size + "' style='overflow:hidden' align='" + this.align + "' valign='top'>" + this.item_array[i] + "</td></tr>";
		}
        __html += "</table>";
    } else {
        __html += "<table cellspacing='0' cellpadding='0' border='0'><tr>";
        for (i=0; i<this.item_array.length; i++)
            __html += "<td width='"+this.size+"' height='"+ this.layer.style.height +"' align='"+this.align+"' \
                valign='top' style='overflow:hidden;'>"+this.item_array[i]+"</td>";
        __html += "</tr></table>";
    }
    __html += "</div>";
    this.layer.innerHTML = __html;
    this.start();
}
TextSlider.prototype.start = function() {
	if (this.speed)
		this.intervalId = setInterval(this.className+".move()", this.speed);
}
TextSlider.prototype.move = function() {
    if (this.isPause) return;
    switch (this.direction) {
        case "up": this.Y -= this.pixel; break;
        case "down": this.Y += this.pixel; break;
        case "left": this.X -= this.pixel; break;
        case "right": this.X += this.pixel; break;
    }
    if (this.direction=='up' || this.direction=='down') {
        if (Math.abs(this.Y)%this.size==0) this.stop();
        this.layer.style.top = this.Y;
    } else {
        if (Math.abs(this.X)%this.size==0) this.stop();
        this.layer.style.left = this.X;
    }
}
TextSlider.prototype.stop = function() {
    clearInterval(this.intervalId);
    switch (this.direction) {
    case "up":
        if (Math.abs(this.Y) >= parseInt(this.layer.style.height,10)-this.size) this.Y = this.layer.style.top = 0;
        break;

    case "down":
        if (Math.abs(this.Y) <= 0) this.Y = this.layer.style.top = -this.size*(this.item_array.length-1);
        break;

    case "left":
        if (Math.abs(this.X) >= parseInt(this.layer.style.width,10)-this.size) this.X = this.layer.style.left = 0;
        break;

    case "right":
        if (Math.abs(this.X) <= 0) this.X = this.layer.style.left = -this.size*(this.item_array.length-1);
        break;
    }
    setTimeout(this.className+".start()", this.interval);
}
TextSlider.prototype.pause = function() {this.isPause = true;}
TextSlider.prototype.unpause = function() {this.isPause = false;}


/* ¹è³Ê ½ºÅ©·Ñ (¸ÞÀÎ ¿ÀÀÏÀåÅÍ¿¡ »ç¿ë)
	banner_roll("divÅÂ±× id", ¹è³Ê1°³³ôÀÌ, µô·¹ÀÌ, 1Ä­ÀÌµ¿¼Óµµ, 0);
*/
var banner_1_mouseEvent = 1;
function banner_roll(div_id, banner_height, banner_delay, banner_speed, this_height){

if(eval(div_id + "_mouseEvent")){
	var div_tag = document.getElementById(div_id);
	var a_tag, i;

	this_height++;
	if(this_height < banner_height){
		div_tag.style.top = 0;	
		setTimeout("banner_roll('" + div_id + "', " + banner_height + ", " + banner_delay + ", " + banner_speed + ", " + this_height + ");", banner_speed);
	}
	else{
		a_tag = div_tag.getElementsByTagName("TABLE");
		div_tag.appendChild(a_tag[0]);
		div_tag.style.top = 0;
		setTimeout("banner_roll('" + div_id + "', " + banner_height + ", " + banner_delay + ", " + banner_speed + ", 0);", banner_delay);
	}
}
else
{
	setTimeout("banner_roll('" + div_id + "', " + banner_height + ", " + banner_delay + ", " + banner_speed + ", " + this_height + ");", banner_speed);
}
return true;
}
