/*
	@@ 작성자	: 이준형
	@@ 내용		: 글로벌 롤링 컨트롤
	@@ 객체명	: RollingHandler
	@@ 인스턴스
				: rollPage		(롤링 페이지 번호)
				: rollCnt		(총 롤링할 페이지 개수)
				: viewCnt		(하나의 롤링 페이지에 노출되는 개수 )
				: jsonData		(롤링될 그룹 elementID)
				: firstIdNum	(롤링될 그룹 elementID 첫번째로 실행될 아이디 뒷 번호 ex) sketch_0 ~ sketch_11 까지 있을경우 0이 firstIdNum)
				: styleDis01	(노출 및 숨김)
				: styleDis02	(노출 및 숨김)
				: titleFlag		(롤링 타이틀 사용여부)
				: jsonTitle		(롤링될 타이틀)
				: titleID		(롤링될 타이틀 영역 elementID)

	@@ 메소드
				: rolling		(롤링 처리 메소드)
				: nextRoll		(next 롤링 버튼 처리)
				: prevRoll		(prev 롤링 버튼 처리)
*/
var RollingHandler	= function()
{
	this.rollPage	= 1;
	this.rollCnt;
	this.viewCnt;
	this.jsonData;
	this.styleDis01	= "none";
	this.styleDis02	= "block";
	this.titleFlag	= false;
	this.jsonTitle;
	this.titleID;
	this.ListID;
	this.noListID;
	this.giveData	= false;
	this.pageFlag	= false;

	this.rolling	= function()
	{

		for(var i=0; i < this.jsonData.length; i++)
		{
			if(O(this.jsonData[i])==null) continue;

			
			O(this.jsonData[i]).style.display = this.styleDis01;
		}

		var startLoop	= this.viewCnt * this.rollPage - this.viewCnt;
		var endLoop		= startLoop + this.viewCnt;

		if(endLoop > this.jsonData.length)
		{
			var endLoop		= startLoop + (startLoop + this.jsonData.length - endLoop);
		}


		for(var i=startLoop; i < endLoop; i++)
		{
			if(O(this.jsonData[i])==null) continue;
			
			if(!isNaN(arguments[0]))
			{
				O(this.jsonData[arguments[0]]).style.display = this.styleDis02;
			}
			else
			{
				O(this.jsonData[i]).style.display = this.styleDis02;
			}
			
			this.giveData = true;
		}

		if(O(this.noListID)!=null) {
			if(this.giveData==false) {
				O(this.noListID).style.display = this.styleDis02;
				O(this.noListID).innerHTML = "<div style='text-align:center;height:120px;'>등록된 <b>"+this.jsonTitle[this.rollPage-1]+"</b> 영상이 없습니다.</div>";
			} else {
				O(this.noListID).style.display = this.styleDis01;
				this.giveData = false;
			}
		}
	}

	this.nextRoll	= function()
	{
		this.rollPage = (this.rollPage == this.rollCnt) ? 1 : this.rollPage + 1 ;

		this.rolling();

		if(this.titleFlag) this.titleRoll();
	}

	this.prevRoll	= function()
	{
		this.rollPage = (this.rollPage == 1) ? this.rollCnt : this.rollPage - 1 ;

		this.rolling();

		if(this.titleFlag) this.titleRoll();
	}


	this.titleRoll	= function()
	{		
		O(this.titleID).innerHTML = this.jsonTitle[this.rollPage-1];		
	}
}
