// JavaScript Document
/**

<input type="button" onclick="mDiv.moveStart();" value="New" />

<div id="newSharedCard" style="background-image:url(newcard.jpg); display:none; position:absolute;">
<table width="100%" height="100%" border="1">
<tr><td>&nbsp;</td></tr>
</table>
</div>

<script type="text/javascript">
<!--
var no		= new Object();
no.name		= 'mDiv';
no.direct = 1;
no.obj		= getObj('newSharedCard');
no.x			= -140;
no.y			= 0;
no.height = 140;
no.width	= 500;
no.obj.style.height = no.height + 'px';
no.obj.style.width 	= no.width + 'px';
no.obj.style.bottom = no.y + 'px';
no.obj.style.right	= no.x + 'px';

var mDiv = new MoveObj(no);
getObj('newSharedCard').onmouseover = function() {mDiv.moveStop()};
getObj('newSharedCard').onmouseout 	= function() {mDiv.moveStart()};

//-->
</script>

*/

function checkIE() {
	return (document.all)? true : false;
}

function getObj(id) {
	return document.getElementById(id);
}

function MoveObj(param) {
	//屬性
	this.x					= param.x;	//必要
	this.y					= param.y;	//必要
	this.height			= (param.height)? param.height : 200;
	this.width			= (param.width)? param.width : 200;
	this.obj				= param.obj;	//必要	
	this.isStart		= true;
	this.direct			= (param.direct)? param.direct : 1; 	//1:右到左 2:下到上
	this.runTime		= (param.runTime)? param.runTime : 30; //移動時間
	this.addIn			= (param.addIn)? param.addIn : 5;	//每次移動像素
	this.alpha			= (param.alpha)? param.alpha : 100;
	this.name				= (param.name)?	param.name : 'MO';
	this.pause			= true;
	this.status			= 4; // 0 run 1 pause 2 fade 3 stop 4 reset
	this.wait				= (param.wait)? param.wait : 5000;
	
	
	//方法
	this.moveRTL		= moveRTL;
	this.moveBTT		= moveBTT;
	this.moveStart	= moveStart;
	this.moveStop		= moveStop;
	this.moveDiv		= moveDiv;
			
}


function moveRTL() {
	this.x += this.addIn;
	
	if(this.isStart) {
		this.obj.style.display = 'block';
		if(this.x < document.body.clientWidth) {
			this.moveDiv();
			setTimeout( this.name + '.moveRTL();', this.runTime);
		} else {
			this.obj.style.display = 'none';
			this.x = -(this.width);			
		}
	}	
}


function moveBTT() {
	this.y += this.addIn;
			
	if(this.y <= 0 && this.status == 0 && this.isStart) { this.status = 0;} //移動
	
	if(this.y >= 0 && this.status == 0 && this.isStart) { this.status = 1;}	//到達目的暫停
	
	if(this.status == 2 && this.isStart) { this.status = 2;}	//到達目的淡出
			
	if(this.y >= 0 && this.status == 3 && this.isStart) { this.status = 3; }	//停止
		
	
	
	if(this.isStart) {
		
		
				
		switch(this.status) {
			case 0:
				this.moveDiv();
				this.obj.style.display = '';				
				setTimeout( this.name + '.moveBTT();', this.runTime);			
			break;
			
			case 1:
				this.status = 2;
				setTimeout( this.name + '.moveBTT();', this.wait);			
			break;
			
			case 2:
				if(this.alpha >= 0) {
				this.alpha -= 5;
				
				if(checkIE()) {
					this.obj.style.filter = 'alpha(opacity='+this.alpha+')';		
				} else {
					this.obj.style.opacity = this.alpha / 100;
				}
				
				setTimeout(this.name + '.moveBTT();', 40);			
				} else {
					this.obj.style.display = 'none';
					this.status	= 3;
					setTimeout(this.name + '.moveBTT();', 40);			
				}
			break;
			
			
			case 3:
					this.alpha 	= 100;
					this.y 			= -(this.height);
					this.obj.style.bottom		= (this.y) + 'px';
				
					if(checkIE()) {
						this.obj.style.filter = 'alpha(opacity='+this.alpha+')';
					} else {
						this.obj.style.opacity = this.alpha / 100;
					}					
					this.obj.style.display 	= 'none';
						
			break;
			
		}

	}
}



function moveStop() {
	this.isStart = false;
	this.status		= 1;
}


function moveStart() {
	this.isStart 		= true;
	this.status		= 0;
	switch(this.direct) {
		case 1:
			this.moveRTL();
		break;
		
		case 2:
			this.moveBTT();
		break;
			
		default:
			this.moveRTL();
	}
}


function moveDiv() {
	var canvas = document[ 'CSS1Compat' == document.compatMode ? 'documentElement' : 'body'];
	var l = parseInt(canvas.scrollLeft,10) ;
  var t = parseInt(canvas.scrollTop,10);
    
	this.obj.style.right = this.x + 'px';
	if(checkIE()) {
		this.obj.style.bottom = (this.y) + 'px';
	} else {
		this.obj.style.bottom = (this.y - t) + 'px';	
	}
	/*
	var l = parseInt(canvas.scrollLeft,10) 
    var t = parseInt(canvas.scrollTop,10) 
    oj.style.left = l + ofx+"px"
    oj.style.top  = t + ofy+"px"
    */
}

