// ###    eXtensible Flow utilities for client		###
// ###    programed by Kool.Sk8er.YJ (endymion@millesky.com)	###
// ###    Copyright (c) 2009 Millesky.com						###
// ###    All rights reserved.									###

function _XFlow_Object(name)
{
	// Public property
	// [
		this.name = name;
		this.cellwidth = 0;
		this.cellheight = 0;
		this.speed = 1;
		this.wait = 1000;
		this.reload = 0;
		this.cells;
		this.composeHTML;
	// ]

	// Private property
	// [
		this.html = "";
		this.isflow = true;
		this.ismouseover = true;
		this.poscell = 0;
		this.currentcell = 0;
		this.rotationcount = 0;
	// ]

	// Public Method
	// [
		this.startFlow = _XFlow_startFlow;
	// ]

	// Private Method
	// [
		this.setMouseOver = _XFlow_setMouseOver;
	// ]
}

function _XFlow_startFlow()
{
	if(typeof(this.cells) == "object")
	{
		document.write("<div style=\"height:" + this.cellheight + "px; width:" + this.cellwidth + "px; position:relative; overflow:hidden\" onMouseover=\"" + this.name + ".setMouseOver(false);\" onMouseout=\"" + this.name + ".setMouseOver(true);\">\n");
		for(var i=0; i<this.cells.length; i++)
		{
			document.write("<div style=\"top:" + (this.cellheight * i) + "px; height:" + (this.cellheight + 0) + "px; position:absolute; padding:0 0 0 0\" id=\"XFlow_scroll_area_" + this.name + "_" + i + "\">\n");
			var lsHtml = this.composeHTML(i);
			document.write(lsHtml);
			document.write("</div>\n");
		}
		document.write("</div>\n");
		window.setTimeout("_XFlow__scrollDiv(\"" + this.name + "\");", this.wait);
	}
}

function _XFlow_setMouseOver(pbFlag)
{
	this.ismouseover = pbFlag;
}

function _XFlow__scrollDiv(psName)
{
	if(eval(psName).ismouseover && eval(psName).isflow)
	{
		for(var i=0; i<eval(psName).cells.length; i++)
		{
			eval(psName).poscell++;
			var loDivStyle = document.getElementById("XFlow_scroll_area_" + psName + "_" + i).style;
			loDivStyle.top = parseInt(loDivStyle.top) - 1;
			if(parseInt(loDivStyle.top) <= eval(psName).cellheight * (-1))
			{
				loDivStyle.top = eval(psName).cellheight * (eval(psName).cells.length - 1);
			}
			if(eval(psName).poscell > (eval(psName).cellheight - 1) * eval(psName).cells.length)
			{
				eval(psName).isflow = false;
				eval(psName).poscell = 0;
				eval(psName).currentcell++;
				if(eval(psName).currentcell >= eval(psName).cells.length)
				{
					eval(psName).currentcell = 0;
					eval(psName).rotationcount++;
					if(eval(psName).reload != 0 && eval(psName).reload <= eval(psName).rotationcount)
					{
						eval(psName).rotationcount = 0;
					}
				}
				window.setTimeout(psName + ".isflow=true; " + psName + ".poscell=0;", eval(psName).wait);
			}
		}
	}
	window.setTimeout("_XFlow__scrollDiv(\"" + psName + "\")", eval(psName).speed);
}