﻿var dataList	= new Array();

var bMouseOver=1;

function initScrollData(id, obj, data, popup_data, viewRow, separate, interval, scrollTime, styleData) {
	var template	= "";
	dataList[id]	= new scrollData(id, obj, data, popup_data, viewRow, separate, interval, scrollTime, styleData);

	// 상단/하단 영역 생성
	template	+= "<div id='" + id + "1' style='position:absolute; top:0px; width:100%; height:" + obj.clientHeight +"px;' onMouseOver='bMouseOver=0' onMouseOut='bMouseOver=1'>SECTION 1</div>\n";
	template	+= "<div id='" + id + "2' style='position:absolute; top:" + obj.clientHeight + "px; width:100%; height:" + obj.clientHeight +"px;'>SECTION 2</div>\n";

	obj.innerHTML = template;

	viewScrollData(id);
}

function viewScrollData(id) {
	var viewData	= dataList[id];
	var viewSection	= new Array();
	var viewCnt		= 0;
	var viewPos		= 0;
	var tempPos		= 0;
	var tempCnt		= 0;
	var sLIST		= "";
	var itemData;
	var styleData;

	if (viewData == null) return;

	styleData = viewData.styleData;

	viewSection[0]	= document.getElementById(id + "1");
	viewSection[1]	= document.getElementById(id + "2");

	// 영역별 초기 위치 지정
	viewSection[0].style.top		= 0;
	viewSection[1].style.top		= viewData.obj.clientHeight;

	tempPos	= viewData.position;

	for (var i=0; i<2; i++) {
		viewCnt = 0;

		sLIST = "<table border=0 cellpadding=0 cellspacing=0 width=100%>\n";

		// 데이터생성
		//alert("viewData.viewRow==>"+viewData.viewRow);
		while (viewCnt < viewData.viewRow) {
			if (viewData.data[tempPos + viewCnt] == null) break;
			//alert(viewData.data[tempPos + viewCnt]);
			itemData = viewData.data[tempPos + viewCnt].split(viewData.separate);

			sLIST += "<tr ";

			// TR Style
			if (styleData != null && styleData[0] != null) {
				sLIST += styleData[0];
			}
			
			sLIST += ">\n";

			for (var j=0; j<itemData.length; j++) {
				sLIST += "  <td ";
				
				// TD Style
				if (styleData != null && styleData[j+1] != null) {
					sLIST += styleData[j+1];
				}

				sLIST += ">";
				
				if (viewData.popup_data != null) {
					if(j == 0 || j == 1 ) {
					   sLIST += "<a href='#' onClick=\"javascript:open_details(" ;
					   sLIST += viewData.popup_data[tempPos + viewCnt] + ")\">";
					}
				}

				sLIST += itemData[j];

				if (viewData.popup_data != null) {
					if(j == 0 || j == 1 ) {
					   sLIST += "</a>";	
					}
				}
				sLIST += "</td>\n";
				
			}

			sLIST += "</tr>\n";
			//alert(sLIST);
			viewCnt++;
			viewPos++;
		}

		sLIST += "</table>\n";
		viewSection[i].innerHTML = sLIST;

		tempPos += viewCnt;

		if (tempPos >= viewData.data.length) {
			tempPos = 0;
		}

		if (i == 0) {
			tempCnt = viewCnt;
		}
	}

	viewData.position += tempCnt;

	if (viewData.position >= viewData.data.length) {
		viewData.position = 0;
	}

	window.setTimeout("viewingScrollData('"+ id + "')", viewData.interval);

}

function viewingScrollData(id) {
	var viewData = dataList[id];
	var viewSection	= new Array();

	if (viewData == null) return;

	viewSection[0]	= document.getElementById(id + "1");
	viewSection[1]	= document.getElementById(id + "2");

	// 위치변경
	if(bMouseOver == 1) {
		viewSection[0].style.top = parseInt(viewSection[0].style.top) - 1;
		viewSection[1].style.top = parseInt(viewSection[1].style.top) - 1;
	} 

	if (parseInt(viewSection[0].style.top) >= -1 * viewData.obj.clientHeight) {		
		window.setTimeout("viewingScrollData('"+ id + "')", viewData.scrollTime);
	} else {
		viewScrollData(id);
	}
}

function scrollData(id, obj, data, popup_data, viewRow, separate, interval, scrollTime, styleData) {
	this.id			= id;
	this.obj		= obj;
	this.data		= data;
	this.popup_data		= popup_data;
	this.viewRow	= viewRow;
	this.separate	= separate;
	this.interval	= interval;
	this.scrollTime	= scrollTime;
	this.styleData	= styleData;
	this.position	= 0;
}

	