//------------------------------------------------------------------------------------------------------------
function xgAuctionTimer(idx, title, d, h, m, s, vtype){
	this.idx = idx;
	this.title = title;
	this.day = d;
	this.hour = h;
	this.min = m;
	this.sec = s;
	this.vtype = vtype;
	
	if(vtype == 'img'){
		// image Objects...
		this.dd1 = document.all[ 'ddigit' + idx + '_1' ];
		this.dd2 = document.all[ 'ddigit' + idx + '_2' ];
		this.dh1 = document.all[ 'hdigit' + idx + '_1' ];
		this.dh2 = document.all[ 'hdigit' + idx + '_2' ];
		this.dm1 = document.all[ 'mdigit' + idx + '_1' ];
		this.dm2 = document.all[ 'mdigit' + idx + '_2' ];
		this.ds1 = document.all[ 'sdigit' + idx + '_1' ];
		this.ds2 = document.all[ 'sdigit' + idx + '_2' ];
		
		// Number Src...
		this.imgList = new Array;
		for(var i=0; i<10; i++){
			this.imgList[i] = 'http://img.xgclub.com/images/auction/re_time_0' + i + '.gif';
		}
	}
	else if(vtype == 'img1'){
		// image Objects...
		this.dd1 = document.all[ 'ddigit' + idx + '_1' ];
		this.dd2 = document.all[ 'ddigit' + idx + '_2' ];
		this.dh1 = document.all[ 'hdigit' + idx + '_1' ];
		this.dh2 = document.all[ 'hdigit' + idx + '_2' ];
		this.dm1 = document.all[ 'mdigit' + idx + '_1' ];
		this.dm2 = document.all[ 'mdigit' + idx + '_2' ];
		this.ds1 = document.all[ 'sdigit' + idx + '_1' ];
		this.ds2 = document.all[ 'sdigit' + idx + '_2' ];
		
		// Number Src...
		this.imgList = new Array;
		for(var j=0; j<10; j++){
			this.imgList[j] = 'http://img.xgclub.com/images/main/1226_0' + j + '.gif';
		}
	}
	else if(vtype == 'img2'){
		// image Objects...
		this.dd1 = document.all[ 'ddigit' + idx + '_1' ];
		this.dd2 = document.all[ 'ddigit' + idx + '_2' ];
		this.dh1 = document.all[ 'hdigit' + idx + '_1' ];
		this.dh2 = document.all[ 'hdigit' + idx + '_2' ];
		this.dm1 = document.all[ 'mdigit' + idx + '_1' ];
		this.dm2 = document.all[ 'mdigit' + idx + '_2' ];
		this.ds1 = document.all[ 'sdigit' + idx + '_1' ];
		this.ds2 = document.all[ 'sdigit' + idx + '_2' ];
		
		// Number Src...
		this.imgList = new Array;
		for(var j=0; j<10; j++){
			this.imgList[j] = 'http://img.xgclub.com/images/main/1226_000' + j + '.jpg';
		}
	}
	else if(vtype == 'img3'){
		// image Objects...
		this.dd1 = document.all[ 'ddigit' + idx + '_1' ];
		this.dd2 = document.all[ 'ddigit' + idx + '_2' ];
		this.dh1 = document.all[ 'hdigit' + idx + '_1' ];
		this.dh2 = document.all[ 'hdigit' + idx + '_2' ];
		this.dm1 = document.all[ 'mdigit' + idx + '_1' ];
		this.dm2 = document.all[ 'mdigit' + idx + '_2' ];
		this.ds1 = document.all[ 'sdigit' + idx + '_1' ];
		this.ds2 = document.all[ 'sdigit' + idx + '_2' ];
		
		// Number Src...
		this.imgList = new Array;
		for(var j=0; j<10; j++){
			this.imgList[j] = 'http://img.xgclub.com/images/thema/' + j + '.gif';
		}
	}
	else if(vtype == 'img4'){
		// image Objects...
		this.dd1 = document.all[ 'ddigit' + idx + '_1' ];
		this.dd2 = document.all[ 'ddigit' + idx + '_2' ];
		this.dh1 = document.all[ 'hdigit' + idx + '_1' ];
		this.dh2 = document.all[ 'hdigit' + idx + '_2' ];
		this.dm1 = document.all[ 'mdigit' + idx + '_1' ];
		this.dm2 = document.all[ 'mdigit' + idx + '_2' ];
		this.ds1 = document.all[ 'sdigit' + idx + '_1' ];
		this.ds2 = document.all[ 'sdigit' + idx + '_2' ];
		
		// Number Src...
		this.imgList = new Array;
		for(var j=0; j<10; j++){
			this.imgList[j] = 'http://img.xgclub.com/images/counter/' + j + '.gif';
		}
	}
	else{
		// Layer Objects...
		this.dday = document.all[ 'rDay' + idx ];
		this.dhour = document.all[ 'rHour' + idx ];
		this.dmin = document.all[ 'rMin' + idx ];
		this.dsec = document.all[ 'rSec' + idx ];
	}
	
	this.setDigit();
}

xgAuctionTimer.prototype.setImgSrc = function(img1,img2, num) {
	if(num == 0){
		img1.src = this.imgList[0];
		img2.src = this.imgList[0];
	}
	else{
		img1.src = this.imgList[ Math.floor(num/10) ];
		img2.src = this.imgList[ (num%10) ];
	}
}

xgAuctionTimer.prototype.setHtmlSrc = function(layer, num){
	if(num<10){
		layer.innerHTML = '0' + num.toString();
	}
	else{
		layer.innerHTML = num.toString();
	}
}

xgAuctionTimer.prototype.setDigit = function(){
	if(this.vtype == 'img'){
		this.setImgSrc(this.dd1, this.dd2, this.day);
		this.setImgSrc(this.dh1, this.dh2, this.hour);
		this.setImgSrc(this.dm1, this.dm2, this.min);
		this.setImgSrc(this.ds1, this.ds2, this.sec);
	}
	else if(this.vtype == 'img1' || this.vtype == 'img2' || this.vtype=='img3'){
		this.setImgSrc(this.dd1, this.dd2, this.day);
		this.setImgSrc(this.dh1, this.dh2, this.hour);
		this.setImgSrc(this.dm1, this.dm2, this.min);
		this.setImgSrc(this.ds1, this.ds2, this.sec);
	}
	else if(this.vtype == 'img4'){
		this.setImgSrc(this.dm1, this.dm2, this.min);
		this.setImgSrc(this.ds1, this.ds2, this.sec);
	}
	else{
		this.setHtmlSrc(this.dday, this.day);
		this.setHtmlSrc(this.dhour, this.hour);
		this.setHtmlSrc(this.dmin, this.min);
		this.setHtmlSrc(this.dsec, this.sec);
	}
}

xgAuctionTimer.prototype.start = function(){
	if(this.sec == 0){
		this.sec = 59;
		if(this.min == 0){
			this.min = 59;
			if(this.hour == 0){
				this.hour = 23;
				if(this.day == 0){
					if(this.title != ''){
						alert(this.title + '°¡ Á¾·áµÇ¾ú½À´Ï´Ù.');
						document.location.reload();	//´ÙÀ½È¸Â÷ °æ¸Å¸¦ º¸±â À§ÇØ¼­ ÇöÀç ÆäÀÌÁö¸¦ ´Ù½Ã ºÒ·¯¿Â´Ù..
					}
				}
				else{
					--this.day;
				}
			}
			else{
				--this.hour;
			}
		}
		else{
			--this.min;
		}
	}
	else{
		--this.sec;
	}
	
	// 10ºÐ °æ¸Å ´çÃ·ÀÚ ¹ßÇ¥¿¡ ³ª¿À´Â ºÎºÐ
	if(this.day == '06' && this.hour == '23' && this.min == '50' && this.sec == '00')
	{
		alert('°æ¸Å ´çÃ·ÀÚ ¼±Á¤ÀÌ ¿Ï·á µÇ¾ú½À´Ï´Ù.');
		document.location.reload();	//´ÙÀ½È¸Â÷ °æ¸Å¸¦ º¸±â À§ÇØ¼­ ÇöÀç ÆäÀÌÁö¸¦ ´Ù½Ã ºÒ·¯¿Â´Ù..
	}
	// °æ¸Å¹ßÇ¥ 5ºÐÀü
	if(this.day == '00' && this.hour == '00' && this.min == '04' && this.sec == '59')
	{
		alert('°æ¸Å ÀÔÂû ¸¶°¨ 5ºÐ ÀüÀÔ´Ï´Ù.');
		document.location.reload();	//°æ¸Å¹ßÇ¥¸¦ À§ÇØ¼­ Ã³¸®
	}
	
	this.setDigit()
}

//------------------------------------------------------------------------------------------------------------

function xgScroll(name, w, h, src, c, s, d){
	this.name = name;
	this.width = w;
	this.height = h;
	this.count = c;
	this.step = s;
	this.direction = d;
	this.pause = false;
	
	this.scrollDatas = new Array;
	
	for(var i=0;i < c; i++){
		this.scrollDatas[i] = eval('document.all.' + name + i);	// ·¹ÀÌ¾î¸¦ °ü¸®ÇÏ±â À§ÇØ ¹è¿­¿¡ ³ÖÀÚ..
		if(d == 'left' || d == 'right'){
			this.scrollDatas[i].style.left = w * i;								// ÃÊ±â À§Ä¡ ¼¼ÆÃ..
		}
		else{
			this.scrollDatas[i].style.pixelTop = h * i;						// ÃÊ±â À§Ä¡ ¼¼ÆÃ..
		}
		this.scrollDatas[i].innerHTML = src.innerHTML;		// °¢ ·¹ÀÌ¹ö¿¡ ³»¿ë ¼¼ÆÃ
	}
	
	this.Interval = setInterval( name + '.scroll()', 50);
}

xgScroll.prototype.scroll = function(){
	if(this.pause == false){
		var x;
		var y;
		var chkPos;
		
		for(var i=0;i<this.count; i++){
			if(this.direction == 'left'){
				x = parseInt( this.scrollDatas[i].style.left );
				chkPos = this.width - this.step;
				if(x <= -chkPos){
					x = this.width * (this.count-1);
				}
				else{
					x -= this.step;
				}
				this.scrollDatas[i].style.left = x;
			}
			else if(this.direction == 'right'){
				x = parseInt( this.scrollDatas[i].style.left );
				chkPos = this.width + this.step;
				if(x >= chkPos){
					x = -( this.width * (this.count-1) );
				}
				else{
					x += this.step;
				}
				this.scrollDatas[i].style.left = x;
			}
			else if(this.direction == 'up'){
				y = parseInt( this.scrollDatas[i].style.pixelTop );
				chkPos = -(this.height - this.step);
				if(y <= chkPos){
					y = this.height * (this.count-1);
				}
				else{
					y -= this.step;
				}
				this.scrollDatas[i].style.pixelTop = y;
			}
			else if(this.direction == 'down'){
				y = parseInt( this.scrollDatas[i].style.pixelTop );
				chkPos = this.height + this.step;
				if(y >= chkPos){
					y = -( this.height * (this.count-1) );
				}
				else{
					y += this.step;
				}
				this.scrollDatas[i].style.pixelTop = y;
			}
		}// end for
	}// end check pause
}

xgScroll.prototype.setPause = function(){
	this.pause = true;
}

xgScroll.prototype.clearPause = function(){
	this.pause = false;
}

//------------------------------------------------------------------------------------------------------------

function xgTextScroll(name, w, h, c, s, d, t, p){
  if(isNaN(p) == true) p = 100;
	this.name = name;
	this.width = w;
	this.height = h;
	this.count = c;
	this.step = s;
	this.direction = d;
	this.showtime = t;
	this.speed = p;
	this.pause = false;
	
	this.scrollDatas = new Array;
	
	for(var i=0;i < c; i++){
		this.scrollDatas[i] = eval('document.all.' + name + i);	// ·¹ÀÌ¾î¸¦ °ü¸®ÇÏ±â À§ÇØ ¹è¿­¿¡ ³ÖÀÚ..
		if(d == 'left' || d == 'right'){
			this.scrollDatas[i].style.left = w * i;								// ÃÊ±â À§Ä¡ ¼¼ÆÃ..
		}
		else{
			this.scrollDatas[i].style.pixelTop = h * i;						// ÃÊ±â À§Ä¡ ¼¼ÆÃ..
		}
	}
	this.timer = setTimeout( this.name + '.start()', this.showtime);
	this.interval = '';
}

xgTextScroll.prototype.start = function(){
	clearTimeout( this.timer );
	this.interval = setInterval( this.name + '.scroll()', this.speed);
}

xgTextScroll.prototype.scroll = function(){
	//if(this.pause == false){
		var x;
		var y;
		var chkPos;
		var clearInterv = false;
		
		for(var i=0;i<this.count; i++){
			if(this.direction == 'left'){
				x = parseInt( this.scrollDatas[i].style.left );
				chkPos = this.width - this.step;
				if(x <= -chkPos){
					clearInterv = true;
					x = this.width * (this.count-1);
				}
				else{
					x -= this.step;
				}
				this.scrollDatas[i].style.left = x;
			}
			else if(this.direction == 'right'){
				x = parseInt( this.scrollDatas[i].style.left );
				chkPos = this.width + this.step;
				if(x >= chkPos){
					clearInterv = true;
					x = -( this.width * (this.count-1) );
				}
				else{
					x += this.step;
				}
				this.scrollDatas[i].style.left = x;
			}
			else if(this.direction == 'up'){
				y = parseInt( this.scrollDatas[i].style.pixelTop );
				chkPos = -(this.height - this.step);
				if(y <= chkPos){
					clearInterv = true;
					y = this.height * (this.count-1);
				}
				else{
					y -= this.step;
				}
				this.scrollDatas[i].style.pixelTop = y;
			}
			else if(this.direction == 'down'){
				y = parseInt( this.scrollDatas[i].style.pixelTop );
				chkPos = this.height + this.step;
				if(y >= chkPos){
					clearInterv = true;
					y = -( this.height * (this.count-1) );
				}
				else{
					y += this.step;
				}
				this.scrollDatas[i].style.pixelTop = y;
			}
		}// end for
		
		if(clearInterv){
			clearInterval( this.interval );
			clearTimeout( this.timer );
			this.timer = setTimeout( this.name + '.start()', this.showtime);
		}
	// }// end check pause
}

xgTextScroll.prototype.setPause = function(){
	this.pause = true;
	clearTimeout( this.timer );
}

xgTextScroll.prototype.clearPause = function(){
	this.pause = false;
	this.timer = setTimeout( this.name + '.start()', this.showtime);
}

//------------------------------------------------------------------------------------------------------------

// var bExplorer4plus = (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.substring(0,1) >= "4");

var mainTableWidth = 940;

function setScrollDepth(chkDiv){
	//if(chkDiv > 100){
		return Math.ceil( chkDiv / 5 );
	//}
	//else{
	//	return Math.ceil( chkDiv / 2 );
	//}
}

function xgScrollBox( idx, bname, sbox, w, h, startY, y ){
	this.idx = idx;
	this.bname = bname;
	this.width = w;
	this.height = h;
	this.sbox = sbox;
	this.maxY = startY;
	this.startY = startY;
	this.y = y;
	
	this.sbox.style.pixelTop = this.y;
}

xgScrollBox.prototype.moveNow = function(){
	this.maxY = document.body.scrollTop + this.startY;	// ÀÌµ¿½ÃÄÑ¾ßÇÒ Y ÁÂÇ¥ ¼¼ÆÃ..
	
	var chkDiv = 0;
	var mStep = 1;
	
	if(this.maxY > this.y){	// ÇöÀç À§Ä¡°¡ ¸ñÇ¥°ªº¸´Ù À§ÂÊÀÎ°æ¿ì
		chkDiv = this.maxY - this.y;
		mStep = setScrollDepth(chkDiv);
		this.y = this.y + mStep;
		this.sbox.style.pixelTop = this.y;
	}
	else if(this.maxY < this.y){	// ÇöÀç À§Ä¡°¡ ¸ñÇ¥°ªº¸´Ù ¾Æ·¡ÂÊÀÎ °æ¿ì..
		chkDiv = this.y - this.maxY;
		mStep = setScrollDepth(chkDiv);
		this.y = this.y - mStep;
		this.sbox.style.pixelTop = this.y;
	}
	else{	// ÇöÀç Æ÷Áö¼ÇÀÌ °°Àº°æ¿ì..
		clearInterval( sboxTimerList[ this.idx ] );
		if( (sboxCount-1) == this.idx ){
			clearTimeout( chkTimer );
			chkTimer = setTimeout('chkScrollBox()', 1000); // 1ÃÊÈÄ ½ºÅ©·ÑÀÌ ÇÊ¿äÇÑÁö Ã¼Å©..
		}
	}
}

var sInterval = '';
var sBox = '';
var sboxList = new Array;
var sboxTimerList = new Array;
var sboxIndex = 0;
var chkTimer = '';
var sboxCount = 2;

function makeSideScroll(bn, w, h, y){
	var sbox = eval('document.all.' + bn);
	
	sBox = new xgScrollBox(sboxIndex, bn, sbox, w, h, y, y);
	sboxList[sboxIndex] = sBox;
	
	++sboxIndex;
}

function chkScrollBox(){
	for(var i=0; i<sboxCount; i++){
		sInterval = setInterval('sboxList[' + i + '].moveNow()', 10);
		sboxTimerList[i] = sInterval;
	}
}

function setWidthPos(){
	//if( bExplorer4plus ){
		var baseWidth = document.body.clientWidth;
		var x = 0;
		
		for(var i=0; i < sboxList.length;i++){
			
			
			if( sboxList[i].bname == 'mainScrollLeft'){
				if(baseWidth <= mainTableWidth ){
					x = -( sboxList[i].width );
				}
				else{
					x = ((baseWidth - mainTableWidth) / 2) - 10;
				}
				//alert(baseWidth +"-"+ mainTableWidth);
				--x;
			}
			else if( sboxList[i].bname == 'mainScrollRight'){
				if(baseWidth <= mainTableWidth ){
					x = mainTableWidth;
				}
				else{
					x = mainTableWidth + ((baseWidth - mainTableWidth) / 2);
				}
				++x;
			}
			
			sboxList[i].sbox.style.left = x;
			if(sboxList[i].sbox.style.visibility == 'hidden'){
				sboxList[i].sbox.style.visibility = 'visible';
			}
		}
	//}
}

function initSideScroll(){
	
	//makeSideScroll(name, w, h, y);
	makeSideScroll('mainScrollLeft', 20, 95, 146); // ¿ÞÂÊ ¸Þ´º..
	makeSideScroll('mainScrollRight', 20, 56, 320); // ¿À¸¥ÂÊ ¸Þ´º..
	
	setWidthPos();
	
	chkTimer = setTimeout('chkScrollBox()', 3000); // 3ÃÊÈÄ ½ºÅ©·ÑÀÌ ÇÊ¿äÇÑÁö Ã¼Å©..
}

onresize=setWidthPos

//------------------------------------------------------------------------------------------------------------

var boxWidth = 218;
var boxHeight = 144;
var boxCount = 1;
var showAll = false;

function alertBox( box, idx, maxY, x, y ){
	this.box = box;
	this.idx = idx;
	this.maxY = maxY;
	this.interval = '';
	this.x = x;
	this.y = y;
	
	this.box.style.pixelLeft = this.x;
	this.box.style.pixelTop = this.y;
}

alertBox.prototype.move = function(type, step){
	this.box.style.position='absolute';
	switch(type){
		case 'up':
			this.y = this.y-step;
			this.box.style.pixelTop = this.y;
			break;
		case 'down':
			this.y = this.y+step;
			this.box.style.pixelTop = this.y;
			break;
		case 'left':
			this.x = this.x-step;
			this.box.style.pixelLeft = this.x;
			break;
		case 'right':
			this.x = this.x+step;
			this.box.style.pixelLeft = this.x;
			break;
	}
}

alertBox.prototype.setHideBox = function(stime){
	timerList[this.idx] = setTimeout("boxList[" + (this.idx) + "].hideBox()", stime );
}

alertBox.prototype.moveUp = function(){
	if(this.y > this.maxY){
		this.move('up', 4);
	}
	else{
		clearInterval( interval );
		if(this.idx < (boxCount-1) ){
			moveBoxNow(this.idx + 1);
		}
		else{
			showAll = true;
			setTimeoutALL();
		}
	}
}

alertBox.prototype.resetTimeout = function(dtime){
	this.setHideBox( dtime + ( (boxCount - this.idx) * 1000) );
}

alertBox.prototype.hideBox = function(){
	this.box.style.visibility = 'hidden';
}

var boxIndex = 0;
var box = '';
var interval;
var boxList = new Array;
var timerList = new Array;
var bMaxY = 0;
var baseX = 0;
var baseY = 0;

function moveBoxNow(nidx){
	var noOpen = getCookie('NO_OPEN_ABOX');
	if( noOpen == null)	{
		var maxY = bMaxY - ((nidx+1) * boxHeight);
		var curX = baseX;
		var curY = baseY - (nidx * boxHeight);;
		
		var cbox = eval( 'document.all.alertBox' + nidx );
		
		cbox.style.visibility='visible';
		
		box = new alertBox( cbox, nidx, maxY, curX, curY);
		interval = setInterval('box.moveUp()', 20);
		
		boxList[nidx] = box;
	}
}

function clearTimeoutALL(){
	if(showAll){
		for(var i=0; i<boxCount; i++){
			clearTimeout(timerList[i]);
			timerList[i] = null;
		}
	}
}

function setTimeoutALL(){
	if(showAll){
		for(var i=0; i<boxCount; i++){
			boxList[i].resetTimeout(2000);
		}
	}
}

function hideToday(){
	for(var i=0; i<boxCount; i++){
		boxList[i].hideBox();
	}
}

//ÄíÅ°°ª ¾ò±â
function getCookie(name) {
	var nameStr = name + '=' ;
	var nameLen = nameStr.length;		
	var cookieLen = document.cookie.length;
	
	var i = 0;
	while( i < cookieLen ) {
		var j = i + nameLen;
		if ( document.cookie.substring(i, j) == nameStr ) {
			var end = document.cookie.indexOf(';', j);
			if( end == -1) end = document.cookie.length;
			return unescape( document.cookie.substring(j, end) );
		}
		i = document.cookie.indexOf(' ', i) + 1;
		if ( i == 0) {
			break;
		}
	}
}

function startMoveBoxNow(){
	
	if(boxCount > 0){
		bMaxY = document.body.scrollTop + document.body.clientHeight;
		baseX = document.body.scrollLeft + document.body.clientWidth - boxWidth - 10;
		baseY = document.body.scrollTop + document.body.clientHeight;
		
		moveBoxNow(boxIndex);
	}
}

//------------------------------------------------------------------------------------------------------------