﻿//-----------------------------------------------------------------------------------

	var bVer=parseInt(navigator.appVersion);
	var bName=navigator.appName.toLowerCase();
	var agent=navigator.userAgent.toLowerCase();

	var browser = {
		version:(agent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [])[1],
		ie:/msie/.test(agent) && !/opera/.test(agent),
		ie6:/msie 6.0/.test(agent),
		ie7:/msie 7.0/.test(agent),
		ie8:/msie 8.0/.test(agent),
		safari:/webkit/.test(agent),
		opera:/opera/.test(agent),
		mozilla:/mozilla/.test(agent) && !/(compatible|webkit)/.test(agent),
		firefox2:/firefox\/2/.test(agent),
		firefox3:/firefox\/3/.test(agent),
		ns9:/navigator\/9/.test(agent),
		flock:/flock/.test(agent),
		chrome:/chorme/.test(agent)
	};
	var isIE = browser.ie;
	var isNS = !browser.ie;

	var bWidth,bHeight;
	var scrollWidth;

	/*
	navigator.appName return value
	IE 6.0.3790	:Microsoft Internet Explorer 4
	Netscape 8.1	:Netscape 5
	FireFox 1.5.0.1	:Netscape 5
	Mozilla 1.7.12	:Netscape 5
	Opera 8.5	:Microsoft Internet Explorer 4
	Opera 8.5	:Opera 8


	Agent:
	IE		:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; Alexa Toolbar; mxie; .NET CLR 1.1.4322)
	Netscape	:Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.7.5) Gecko/20060111 Netscape/8.1
	FireFox		:Mozilla/5.0 (Windows; U; Windows NT 5.2; zh-TW; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1
	Mozilla		:Mozilla/5.0 (Windows; U; Windows NT 5.2; zh-TW; rv:1.7.12) Gecko/20050915
	Opera		:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; zh-tw) Opera 8.50
	Opera 8.5	:opera/8.5 (window nt5.2;u;zh-tw)

	*/

function init(){

	if (isIE){
		//bHeight=document.body.clientHeight;
		//bWidth=document.body.clientWidth;
		bHeight=window.document.documentElement.clientHeight;
		bWidth=window.document.documentElement.clientWidth;
	}

	if (isNS){
		bHeight=window.innerHeight;
		bWidth=window.innerWidth;
	}

	scrollWidth=getScrollerWidth();
}



var __methods={
	test:true,
	version:'0.1',
	intervalOBJ:null,
	agent:navigator.userAgent.toLowerCase(),
	ie:/msie/.test(this.agent) && !/opera/.test(this.agent),
	bWidth:(/msie/.test(this.agent) && !/opera/.test(this.agent))?window.document.documentElement.clientWidth:window.innerWidth,
	bHeight:(/msie/.test(this.agent) && !/opera/.test(this.agent))?window.document.documentElement.clientHeight:window.innerHeight,
	//CSS Setting or Return Property
	width:function(x){
		if (typeof x=='undefined'){
			return parseInt(this.style.width);
		}else{
			if (isNaN(x)){
				this.style.width=x;
			}else{
				this.style.width=x+'px';
			}
		}
		return this;
	},

	setwidth:function(x){
		if (typeof x=='undefined'){
			return parseInt(this.style.width);
		}else{
			if (isNaN(x)){
				this.style.width=x;
			}else{
				this.style.width=x+'px';
			}
		}
		return this;
	},

	height:function(x){
		if (typeof x=='undefined'){
			return parseInt(this.style.height);
		}else{

			if (isNaN(x)){
				this.style.height=x;
			}else{
				this.style.height=x+'px';
			}
		}
		return this;
	},

	setheight:function(x){
		if (typeof x=='undefined'){
			return parseInt(this.style.height);
		}else{

			if (isNaN(x)){
				this.style.height=x;
			}else{
				this.style.height=x+'px';
			}
		}
		return this;
	},

	top:function(x){
		if (typeof x=='undefined'){
			return parseInt(this.style.top);
		}else{
			if (this.position()!='absolute' && this.position()!='relative'){
				this.position('absolute');
			}
			this.style.top=isNaN(x)?x:x+'px';
		}
		return this;
	},

	topBy:function(x){
		if (typeof x!='undefined'){
			this.position('absolute');
			var currTop=$(this).getOffsetTop();
			this.style.top=currTop+x+'px';
		}
		return this;
	},

	left:function(x){
		if (typeof x=='undefined'){
			return parseInt(this.style.left);
		}else{
			if (this.position()!='absolute' && this.position()!='relative'){
				this.position('absolute');
			}
			this.style.left=isNaN(x)?x:x+'px';
		}
		return this;
	},

	leftBy:function(x){
		if (typeof x!='undefined'){
			this.position('absolute');
			var currLeft=$(this).getOffsetLeft();
			this.style.left=currLeft+x+'px';
		}
		return this;
	},

	color:function(x){
		if (typeof x=='undefined'){
			return this.style.color;
		}else if(x=='hex'){
			if (this.style.color.substring(0,1)=='#'){
				return this.style.color;
			}else{
				var rgb=this.style.color.replace(/\s/g,'');
				rgb=rgb.replace(/rgb\(/g,'');
				rgb=rgb.replace(/\)/g,'');
				return '#'+Dec2Hex(rgb.split(',')[0])+Dec2Hex(rgb.split(',')[1])+Dec2Hex(rgb.split(',')[2])
			}
		}else{
			this.style.color=x;
		}
		return this;
	},

	backgroundcolor:function(x){
		if (typeof x=='undefined'){
			return this.style.backgroundColor;
		}else if(x=='hex'){
			if (this.style.backgroundColor.substring(0,1)=='#'){
				return this.style.color;
			}else{
				var rgb=this.style.backgroundColor.replace(/\s/g,'');
				rgb=rgb.replace(/rgb\(/g,'');
				rgb=rgb.replace(/\)/g,'');
				return '#'+Dec2Hex(rgb.split(',')[0])+Dec2Hex(rgb.split(',')[1])+Dec2Hex(rgb.split(',')[2])
			}
		}else{
			this.style.backgroundColor=x;
		}
		return this;
	},

	backgroundColor:function(x){
		if (typeof x=='undefined'){
			return this.style.backgroundColor;
		}else if(x=='hex'){
			if (this.style.backgroundColor.substring(0,1)=='#'){
				return this.style.color;
			}else{
				var rgb=this.style.backgroundColor.replace(/\s/g,'');
				rgb=rgb.replace(/rgb\(/g,'');
				rgb=rgb.replace(/\)/g,'');
				return '#'+Dec2Hex(rgb.split(',')[0])+Dec2Hex(rgb.split(',')[1])+Dec2Hex(rgb.split(',')[2])
			}
		}else{
			this.style.backgroundColor=x;
		}
		return this;
	},

	background:function(x){
		if (typeof x=='undefined'){
			return this.style.background;
		}else{
			this.style.background=x;
		}
		return this;
	},

	position:function(x){
		if (typeof x=='undefined'){
			return this.style.position;
		}else{
			this.style.position=x;
		}
		return this;
	},

	ZIndex:function(x){
		if (typeof x=='undefined'){
			return this.style.zIndex;
		}else{
			this.style.zIndex=x;
		}
		return this;
	},

	setClass:function(class_Name){
		if(typeof class_Name=='undefined'){
			this.className=class_Name;
		}

		return this;
	},

	getClass:function(){
		return this.className;
	},

	display:function(method){

		if(typeof method=='undefined'){
			return this.style.display;
		}

		if (method=='auto'){
			method=(this.style.display=='inline')?'hide':'show';
		}

		if (method=='show'){method='inline';}
		if (method=='hide'){method='none';}

		this.style.display=method;

		return this;
	},

	//Return Property
	Height:function(){
		comment='取得物件含 margin, padding, border 高度';
		var dis=this.style.display;
		var h;
		this.style.display='';
		if (!isNaN(this.offsetHeight)){
			h=this.offsetHeight;
		}else{
			h=this.clientHeight;
		}
		this.style.display=dis;
		return h;
	},

	Width:function(){
		comment='取得物件含 margin, padding, border 寬度';
		var dis=this.style.display;
		var w;
		this.style.display='';
		if (!isNaN(this.offsetWidth)){
			w=this.offsetWidth;
		}else{
			w=this.clientWidth;
		}
		this.style.display=dis;
		return w;

	},

	getOffsetTop:function(){
		comment='取得物件距離視窗左側距離';
		var dis=this.style.display;
		this.style.display='';
		var oDiv=this;
		var oTop=oDiv.offsetTop;
		while (oDiv.offsetParent){
			oDiv=oDiv.offsetParent;
			oTop+=oDiv.offsetTop;
		}
		this.style.display=dis;
		return oTop;
	},

	getOffsetLeft:function(){
		comment='取得物件距離視窗頂端距離';
		var dis=this.style.display;
		this.style.display='';
		var oDiv=this;
		var oLeft=oDiv.offsetLeft;
		while (oDiv.offsetParent){
			oDiv=oDiv.offsetParent;
			oLeft+=oDiv.offsetLeft;
		}
		this.style.display=dis;
		return oLeft;
	},

	getTop:function(x){
		comment='取得物件相對於指定上層物件左側距離';
		if (typeof x!='object'){
			alert('getTop(obj) method:obj must be \'OBJECT\' type');
			return false;
		}
		var dis=this.style.display;
		this.style.display='';
		var oDiv=this;
		var oTop=oDiv.offsetTop;
		while (oDiv.offsetParent!=x){
			oDiv=oDiv.offsetParent;
			oTop+=oDiv.offsetTop;
		}
		this.style.display=dis;
		return oTop;
	},

	getLeft:function(x){
		comment='取得物件相對於指定上層物件頂端距離';
		if (typeof x!='object'){
			alert('getLeft(obj) method:obj must be \'OBJECT\' type');
			return false;
		}
		var dis=this.style.display;
		this.style.display='';
		var oDiv=this;
		var oLeft=oDiv.offsetLeft;
		while (oDiv.offsetParent!=x){
			oDiv=oDiv.offsetParent;
			oLeft+=oDiv.offsetLeft;
		}
		this.style.display=dis;
		return oLeft;
	},

	getCSSValue:function(property){
		return window.getComputedStyle(this,null).getPropertyValue(property);
	},

	getWidthMargin:function(){
		//取得水平方向所有邊界,留白,邊框寬度總和
		var wm=0,temp;
		if (this.currentStyle){
			temp=parseInt(this.currentStyle['borderRightWidth']);
			wm+=(isNaN(temp))?0:temp;
			temp=parseInt(this.currentStyle['borderLeftWidth']);
			wm+=(isNaN(temp))?0:temp;
			temp=parseInt(this.currentStyle['marginRight']);
			wm+=(isNaN(temp))?0:temp;
			temp=parseInt(this.currentStyle['marginLeft']);
			wm+=(isNaN(temp))?0:temp;
			temp=parseInt(this.currentStyle['paddingRight']);
			wm+=(isNaN(temp))?0:temp;
			temp=parseInt(this.currentStyle['paddingLeft']);
			wm+=(isNaN(temp))?0:temp;
		}else{
			wm+=parseInt(window.getComputedStyle(this,null).getPropertyValue('border-right-width'));
			wm+=parseInt(window.getComputedStyle(this,null).getPropertyValue('border-left-width'));
			wm+=parseInt(window.getComputedStyle(this,null).getPropertyValue('margin-right'));
			wm+=parseInt(window.getComputedStyle(this,null).getPropertyValue('margin-left'));
			wm+=parseInt(window.getComputedStyle(this,null).getPropertyValue('padding-right'));
			wm+=parseInt(window.getComputedStyle(this,null).getPropertyValue('padding-left'));
		}

		return wm;
	},

	getHeightMargin:function(){
		//取得垂直方向所有邊界,留白,邊框寬度總和
		var wm=0,temp;
		if (this.currentStyle){
			temp=parseInt(this.currentStyle['borderTopWidth']);
			wm+=(isNaN(temp))?0:temp;
			temp=parseInt(this.currentStyle['borderBottomWidth']);
			wm+=(isNaN(temp))?0:temp;
			temp=parseInt(this.currentStyle['marginTop']);
			wm+=(isNaN(temp))?0:temp;
			temp=parseInt(this.currentStyle['marginBottom']);
			wm+=(isNaN(temp))?0:temp;
			temp=parseInt(this.currentStyle['paddingTop']);
			wm+=(isNaN(temp))?0:temp;
			temp=parseInt(this.currentStyle['paddingBottom']);
			wm+=(isNaN(temp))?0:temp;
		}else{
			wm+=parseInt(window.getComputedStyle(this,null).getPropertyValue('border-top-width'));
			wm+=parseInt(window.getComputedStyle(this,null).getPropertyValue('border-bottom-width'));
			wm+=parseInt(window.getComputedStyle(this,null).getPropertyValue('margin-top'));
			wm+=parseInt(window.getComputedStyle(this,null).getPropertyValue('margin-bottom'));
			wm+=parseInt(window.getComputedStyle(this,null).getPropertyValue('padding-top'));
			wm+=parseInt(window.getComputedStyle(this,null).getPropertyValue('padding-bottom'));
		}

		return wm;
	},

	//Methods
	center:function(x){
		//var w=(this.clientWidth)?this.clientWidth:this.offsetWidth;
		//var w=parseInt(this.style.width);
		x=(isNaN(x))?0:x;
		var w=$(this).Width();
		var bWidth=(this.ie)?window.document.documentElement.clientWidth:window.innerWidth;
		this.style.left=((bWidth-w)/2+x)+'px';

		return this;
	},

	middle:function(x){
		//var h=(this.clientHeight)?this.clientHeight:this.offsetHeight;
		//var w=parseInt(this.style.height);
		x=(isNaN(x))?0:x;
		var h=$(this).Height();
		var bHeight=(this.ie)?window.document.documentElement.clientHeight:window.innerHeight;
		this.style.top=((bHeight-h)/2+x)+'px';

		return this;
	},

	absmiddle:function(x){
		//var h=(this.clientHeight)?this.clientHeight:this.offsetHeight;
		//var w=parseInt(this.style.height);
		x=(isNaN(x))?0:x;
		var h=$(this).Height();
		var bHeight=(this.ie)?window.document.documentElement.clientHeight:window.innerHeight;
		this.style.top=Math.max((screen.availHeight-h)/2-(screen.availHeight-bHeight),0)+'px';

		return this;
	},

	show:function(){
		this.style.visibility='visible';

		return this;
	},

	hide:function(){
		this.style.visibility='hidden';

		return this;
	},


	move:function(top,left){
		this.style.top=top+'px';
		this.style.left=left+'px';

		return this;
	},

	moveto:function(top,left){
		this.style.top=top+'px';
		this.style.left=left+'px';

		return this;
	},

	fullscreen:function(){
		var o=this;
		var scrollY = (this.ie)?document.documentElement.scrollTop:self.pageYOffset;
		this.width('100%');
		this.height('100%');
		this.move(scrollY,0);
		return this;
	},

	floatMark:function(scrollSpeed,intervalTime,stopAt){

		this.s=(typeof scrollSpeed=='undefined')?10:scrollSpeed;
		this.iT=(typeof intervalTime=='undefined')?1:intervalTime;
		this.t=(typeof stopAt=='undefined')?this.getOffsetTop():stopAt;
		//var keepAt=(typeof stopAt=='undefined')?0:this.getOffsetTop();

		this.position('absolute');
		this.top(this.t);

		this.keepAt=0;
		this.scrollY=0;
		this.newY=0;
		this.percent=0;

		var o=this;

		clearInterval(this.intervalOBJ);
		this.intervalOBJ=setInterval(function(){
			o.scrollY = (o.ie)?document.documentElement.scrollTop:self.pageYOffset;
			if (o.style.visibility!='hidden'){
				if(o.scrollY != o.keepAt){
					o.percent = 1 * (o.scrollY - o.keepAt) / o.s;
					o.percent=(o.percent>0)?Math.ceil(o.percent):Math.floor(o.percent);

					o.newY=o.top();
					o.newY+=o.percent;
					o.top(o.newY);

					//keepAt+=percent;
					o.keepAt+=o.percent;
				}
			}

		},o.iT);

		return this;
	},

	float:function(scrollSpeed,intervalTime,stopAt){

		this.s=(typeof scrollSpeed=='undefined')?10:scrollSpeed;
		this.iT=(typeof intervalTime=='undefined')?1:intervalTime;
		this.t=(typeof stopAt=='undefined')?this.getOffsetTop():stopAt;
		//var keepAt=(typeof stopAt=='undefined')?0:this.getOffsetTop();

		this.position('absolute');
		this.top(this.t);

		this.keepAt=0;
		this.scrollY=0;
		this.newY=0;
		this.percent=0;

		var o=this;

		clearInterval(this.intervalOBJ);
		this.intervalOBJ=setInterval(function(){
			o.scrollY = (o.ie)?document.documentElement.scrollTop:self.pageYOffset;
			if (o.style.visibility!='hidden'){
				if(o.scrollY != o.keepAt){
					o.percent = 1 * (o.scrollY - o.keepAt) / o.s;
					o.percent=(o.percent>0)?Math.ceil(o.percent):Math.floor(o.percent);

					o.newY=o.top();
					o.newY+=o.percent;
					o.top(o.newY);

					//keepAt+=percent;
					o.keepAt+=o.percent;
				}
			}

		},o.iT);

		return this;
	},

	slide:function(startPos,endPos,direc,interval){
		if (typeof startPos=='object'){
			if (startPos==[0,0]){
				this.s=[this.getOffsetTop(),this.getOffsetLeft()];
				this.e=[this.getOffsetTop()+endPos[0],this.getOffsetLeft()+endPos[1]];
			}else{
				this.s=startPos;
				this.e=endPos;
			}

		}else{
			this.s=[this.getOffsetTop(),this.getOffsetLeft()];
			this.e=endPos;
		}

		this.operator=[];
		this.expression=[];
		this.mathOperator=[];
		this.direction=[];

		for (var i=0;i<this.s.length;i++){
			this.operator[i]=(this.s[i]<this.e[i])?'+':'-';
			this.expression[i]=(this.s[i]<this.e[i])?'<':'>';
			this.mathOperator[i]=(this.s[i]<this.e[i])?'Math.min':'Math.max';
		}

		this.style.position='absolute';

		if (typeof interval=='undefined'){
			interval=120;
		}

		this.direction[0]='top';
		this.direction[1]='left';
		this.style.top=this.s[0]+'px';
		this.style.left=this.s[1]+'px';

		this.stepY=Math.abs(this.s[0]-this.e[0])/interval;
		this.stepX=Math.abs(this.s[1]-this.e[1])/interval;

		var o=this;

		if (typeof interval!='undefined'){
			switch(interval){
				case 'fast':
					interval-=20;
					break;
				case 'faster':
					interval-=40;
					break;
				case 'slow':
					interval+=20;
					break;
				case 'slower':
					interval+=40;
					break;
				default:
					break;
			}
		}
		clearInterval(this.intervalOBJ);
		this.intervalOBJ=setInterval(function(){

				o.stepY*=1.05;
				o.stepX*=1.05;


				if (eval('o.s[0]'+o.expression[0]+'o.e[0]')){
					eval('o.s[0]'+o.operator[0]+'=o.stepY');
					eval('o.style.'+o.direction[0]+'='+o.mathOperator[0]+'('+o.e[0]+','+o.s[0]+')+\'px\'');
				}
				if (eval('o.s[1]'+o.expression[1]+'o.e[1]')){
					eval('o.s[1]'+o.operator[1]+'=o.stepX');
					eval('o.style.'+o.direction[1]+'='+o.mathOperator[1]+'('+o.e[1]+','+o.s[1]+')+\'px\'');
				}
		},1);

		return this;
	},

	marquee:function(paras){
		if (typeof paras=='undefined'){
			paras={
				type:'smooth',
				direct:'left',
				width:this.Width(),
				height:this.Height(),
				speed:1,
				delay:3,
				step:this.Width()
			}
		}else{
			paras.type=(typeof paras.type=='undefined')?'smooth':paras.type;
			paras.direct=(typeof paras.direct=='undefined')?'left':paras.direct;
			paras.width=(typeof paras.width=='undefined')?this.Width():paras.width;
			paras.height=(typeof paras.height=='undefined')?this.Height():paras.height;
			paras.speed=(typeof paras.speed=='undefined')?1:Math.abs(parseInt(paras.speed));
			paras.delay=(typeof paras.delay=='undefined')?3:Math.abs(parseInt(paras.delay));
			paras.step=(typeof paras.step=='undefined')?this.Width():Math.abs(parseInt(paras.step));
		}

		//alert(paras.direct);
		//alert(paras.width);
		//alert(paras.height);
		var o=this;

		this.height(paras.height);
		this.width(paras.width);
		this.style.position='relative';
		this.style.overflow='hidden';
		this.onmouseover=function(){this.pause();};
		this.onmouseout=function(){this.start();};
		this.motion=false;

		this.marquee_iHTML=this.innerHTML;
		this.innerHTML='';
		this.marquee_iID='marquee_'+new Date().getTime();
		//算一下, marquee 的寬高夠不夠擺滿指定畫面, 不夠的話, 重複
		//先建一個虛的 layer 在很遠的地方

		this.marquee_virtualLayer=document.createElement('div');
		this.marquee_virtualLayer.innerHTML=this.marquee_iHTML;
		document.getElementsByTagName('body')[0].appendChild(this.marquee_virtualLayer);
		this.marquee_virtualLayer.position('absolute');
		this.marquee_virtualLayer.left(-10000);
		this.marquee_virtualLayer.top(-10000);

		//產生兩個 div 放內容, for continous
		this.marquee_iDIVa=document.createElement('div');
		this.marquee_iDIVb=document.createElement('div');
		this.appendChild(this.marquee_iDIVa);
		this.appendChild(this.marquee_iDIVb);
		//

		switch(paras.direct){
			case 'left':
				this.repeat_html_times=Math.ceil(parseInt(paras.width)/this.marquee_virtualLayer.Width());
				for (var i=0;i<this.repeat_html_times;i++){
					this.marquee_iDIVa.innerHTML+=this.marquee_iHTML;
					this.marquee_iDIVb.innerHTML+=this.marquee_iHTML;
				}
				this.marquee_size=this.marquee_virtualLayer.Width()*this.repeat_html_times;
				this.marquee_funs='left';
				this.marquee_op='<';
				this.marquee_iDIVa.left(0);
				this.marquee_iDIVa.height(paras.height);
				this.marquee_iDIVa.width(this.marquee_size);
				this.marquee_iDIVb.left(this.marquee_size);
				this.marquee_iDIVb.height(paras.height);
				this.marquee_iDIVb.width(this.marquee_size);

				paras.step_array=[0,0-paras.step];
				break;
			case 'right':
				this.repeat_html_times=Math.ceil(parseInt(paras.width)/this.marquee_virtualLayer.Width())
				for (var i=0;i<this.repeat_html_times;i++){
					this.marquee_iDIVa.innerHTML+=this.marquee_iHTML;
					this.marquee_iDIVb.innerHTML+=this.marquee_iHTML;
				}
				this.marquee_size=0-this.marquee_virtualLayer.Width()*this.repeat_html_times;
				this.marquee_funs='left';
				this.marquee_op='>';
				this.marquee_iDIVa.left(0);
				this.marquee_iDIVa.height(paras.height);
				this.marquee_iDIVa.width(0-this.marquee_size);
				this.marquee_iDIVb.left(this.marquee_size);
				this.marquee_iDIVb.height(paras.height);
				this.marquee_iDIVb.width(0-this.marquee_size);

				paras.speed=0-paras.speed;
				paras.step_array=[0,paras.step];
				break;
			case 'up':
				this.repeat_html_times=Math.ceil(parseInt(paras.height)/this.marquee_virtualLayer.Height());
				for (var i=0;i<this.repeat_html_times;i++){
					this.marquee_iDIVa.innerHTML+=this.marquee_iHTML;
					this.marquee_iDIVb.innerHTML+=this.marquee_iHTML;
				}
				this.marquee_size=this.marquee_virtualLayer.Height()*this.repeat_html_times;
				this.marquee_funs='top';
				this.marquee_op='<';
				this.marquee_iDIVa.top(0);
				this.marquee_iDIVa.width(paras.width);
				this.marquee_iDIVa.height(this.marquee_size);
				this.marquee_iDIVb.top(this.marquee_size);
				this.marquee_iDIVb.width(paras.width);
				this.marquee_iDIVb.height(this.marquee_size);

				paras.step=0-paras.step;
				paras.step_array=[0-paras.step,0];
				break;
			case 'down':
				this.repeat_html_times=Math.ceil(parseInt(paras.height)/this.marquee_virtualLayer.Height());
				for (var i=0;i<this.repeat_html_times;i++){
					this.marquee_iDIVa.innerHTML+=this.marquee_iHTML;
					this.marquee_iDIVb.innerHTML+=this.marquee_iHTML;
				}
				this.marquee_size=0-this.marquee_virtualLayer.Height()*this.repeat_html_times;
				this.marquee_funs='top';
				this.marquee_op='>';
				this.marquee_iDIVa.top(0);
				this.marquee_iDIVa.width(paras.width);
				this.marquee_iDIVa.height(0-this.marquee_size);
				this.marquee_iDIVb.top(this.marquee_size);
				this.marquee_iDIVb.width(paras.width);
				this.marquee_iDIVb.height(0-this.marquee_size);

				paras.speed=0-paras.speed;
				paras.step_array=[paras.step,0];
				break;
			default:
				this.repeat_html_times=Math.floor(parseInt(paras.width)/this.marquee_virtualLayer.Width());
				for (var i=0;i<this.repeat_html_times;i++){
					this.marquee_iDIVa.innerHTML+=this.marquee_iHTML;
					this.marquee_iDIVb.innerHTML+=this.marquee_iHTML;
				}
				this.marquee_size=this.marquee_virtualLayer.Width()*this.repeat_html_times;
				this.marquee_funs='left';
				this.marquee_op='<';
				this.marquee_iDIVa.left(0);
				this.marquee_iDIVa.height(paras.height);
				this.marquee_iDIVa.width(this.marquee_size);
				this.marquee_iDIVb.left(this.marquee_size);
				this.marquee_iDIVb.height(paras.height);
				this.marquee_iDIVb.width(this.marquee_size);

				paras.step_array=[0,0-paras.step];
				break;
		}

		//this.marquee_iDIV.style.position='absolute';
		this.marquee_iDIVa.style.overflow='hidden';
		this.marquee_iDIVb.style.overflow='hidden';
		this.flow_switch='';

		this.marquee_click=0;
		this.stopControl=setInterval(function(){
			if (paras.type=='sliding'){
				o.marquee_click++;
				if (paras.delay==o.marquee_click){
					o.motion=true;
					o.marquee_click=0;
				}else{
					o.motion=false;
				}
				paras.speed=30;
			}
			if (paras.type=='smooth'){
				o.motion=true;
			}
		},1000);

		this.marquee_interval_str='function(){'+
			'if (o.motion){'+
			'	if (o.marquee_iDIVa.'+o.marquee_funs+'()'+o.marquee_op+'o.marquee_iDIVb.'+o.marquee_funs+'()){'+
			'		o.flow_switch=\'b\';'+
			'	}else{'+
			'		o.flow_switch=\'a\';'+
			'	}'+
			'	if ((o.flow_switch==\'b\')&&(o.marquee_iDIVb.'+o.marquee_funs+'()'+this.marquee_op+'0)){'+
			'			o.marquee_iDIVa.'+o.marquee_funs+'('+o.marquee_size+');'+
			'	}'+
			'	if ((o.flow_switch==\'a\')&&(o.marquee_iDIVa.'+o.marquee_funs+'()'+this.marquee_op+'0)){'+
			'		o.marquee_iDIVb.'+o.marquee_funs+'('+o.marquee_size+');'+
			'	}'+

			'	o.marquee_varoffset=o.marquee_iDIVa.'+o.marquee_funs+'();'+
			'	o.marquee_varoffset-=paras.speed;'+
			'	o.marquee_iDIVa.'+o.marquee_funs+'(o.marquee_varoffset);'+

			'	o.marquee_varoffset=o.marquee_iDIVb.'+o.marquee_funs+'();'+
			'	o.marquee_varoffset-=paras.speed;'+
			'	o.marquee_iDIVb.'+o.marquee_funs+'(o.marquee_varoffset);'+
			'}'+
			''+
		'}';

		eval('this.marquee_interval='+this.marquee_interval_str);

		this.marquee_timeout=setTimeout(function(){
			o.marquee_intervalOBJ=setInterval(o.marquee_interval,1);
		},paras.delay*1000);

		this.pause=function(){
			clearInterval(this.marquee_intervalOBJ);
		};

		this.start=function(){
			this.marquee_intervalOBJ=setInterval(this.marquee_interval,1);
		};

	},

	draggable:function(dragHandler){
		if (typeof dragHandler!='undefined'){
			this.setAttribute('dragHandler',dragHandler);
			$id(dragHandler).setAttribute('draggable','draggable');
			$id(dragHandler).onmouseover=function(){isDraggable(this);return false;};
			$id(dragHandler).onmousedown=function(){startDrag(this);return false;};
			if ($id(dragHandler).getAttribute('parentDiv')==null){
				$id(dragHandler).setAttribute('parentDiv',this.id);
			}else{
				var dH=$id(dragHandler).getAttribute('parentDiv')
				$id(dragHandler).setAttribute('parentDiv',dH+','+this.id);
			}
		}else{
			this.setAttribute('draggable','draggable');
			this.onmouseover=function(){isDraggable(this);return false;};
			this.onmousedown=function(){startDrag(this);return false;};
		}

		return this;
	},

	drag:function(dragHandler){
		if (typeof dragHandler!='undefined'){
			this.setAttribute('dragHandler',dragHandler);
			$id(dragHandler).setAttribute('draggable','draggable');
			$id(dragHandler).onmouseover=function(){isDraggable(this);return false;};
			$id(dragHandler).onmousedown=function(){startDrag(this);return false;};
			if ($id(dragHandler).getAttribute('parentDiv')==null){
				$id(dragHandler).setAttribute('parentDiv',this.id);
			}else{
				var dH=$id(dragHandler).getAttribute('parentDiv')
				$id(dragHandler).setAttribute('parentDiv',dH+','+this.id);
			}
		}else{
			this.setAttribute('draggable','draggable');
			this.onmouseover=function(){isDraggable(this);return false;};
			this.onmousedown=function(){startDrag(this);return false;};

		}

		return this;
	},

	dragResize:function(dragHandler){
		if (typeof dragHandler!='undefined'){
			this.setAttribute('dragHandler',dragHandler);
			$id(dragHandler).setAttribute('draggable','draggable');
			$id(dragHandler).onmouseover=function(){isDraggable(this);return false;};
			$id(dragHandler).onmousedown=function(){startDrag(this);return false;};
			if ($id(dragHandler).getAttribute('parentDiv')==null){
				$id(dragHandler).setAttribute('parentDiv',this.id);
			}else{
				var dH=$id(dragHandler).getAttribute('parentDiv')
				$id(dragHandler).setAttribute('parentDiv',dH+','+this.id);
			}
		}else{
			this.setAttribute('draggable','draggable');
			this.onmouseover=function(){isDraggable(this);return false;};
			this.onmousedown=function(){startDrag(this,false);return false;};
		}

		if (this.currentStyle){
			var bt=parseInt(this.currentStyle['borderTopWidth']);
			var br=parseInt(this.currentStyle['borderRightWidth']);
			var bb=parseInt(this.currentStyle['borderBottomWidth']);
			var bl=parseInt(this.currentStyle['borderLeftWidth']);
		}else{
			var bt=parseInt(window.getComputedStyle(this,null).getPropertyValue('border-top-width'));
			var br=parseInt(window.getComputedStyle(this,null).getPropertyValue('border-right-width'));
			var bb=parseInt(window.getComputedStyle(this,null).getPropertyValue('border-bottom-width'));
			var bl=parseInt(window.getComputedStyle(this,null).getPropertyValue('border-left-width'));
		}
		bt=(bt==0)?4:bt;br=(br==0)?4:br;bb=(bb==0)?4:bb;bl=(bl==0)?4:bl;


		////左上角
		//var div=document.createElement('div');
		//div.style.position='absolute';
		//div.style.cursor='nw-resize';
		//div.style.backgroundColor='#000';
		//$(div).width(bl).height(bt).move(0-bt,0-bl);
		//div.onmousedown=function(){startDrag(this.parentNode,true);return false;};
		//this.appendChild(div);

		//右下角
		//var div=document.createElement('div');
		//div.style.position='absolute';
		//div.style.cursor='nw-resize';
		//div.style.backgroundColor='#000';
		//$(div).width(br).height(bb).move(this.height(),this.width());
		//div.onmouseover=function(){this.parentNode.onmousedown=function(){startDrag(this,true);return false;}};
		//div.onmouseout=function(){this.parentNode.onmousedown=function(){startDrag(this,false);return false;}};
		//this.appendChild(div);

		//右上角
		//var div=document.createElement('div');
		//div.style.position='absolute';
		//div.style.cursor='sw-resize';
		//div.style.backgroundColor='#000';
		//$(div).width(br).height(bt).move(0-bt,this.width());
		//div.onmousedown=function(){startDrag(this.parentNode,true);return false;};
		//this.appendChild(div);

		//左下角
		//var div=document.createElement('div');
		//div.style.position='absolute';
		//div.style.cursor='sw-resize';
		//div.style.backgroundColor='#000';
		//$(div).width(bl).height(bb).move(this.height(),0-bl);
		//div.onmousedown=function(){startDrag(this.parentNode,true);return false;};
		//this.appendChild(div);

		//上
		//var div=document.createElement('div');
		//div.style.position='absolute';
		//div.style.cursor='n-resize';
		//div.style.backgroundColor='#000';
		//$(div).width('100%').height(bt).move(0-bt,0);
		//div.onmousedown=function(){startDrag(this.parentNode,true);return false;};
		//this.appendChild(div);

		//下
		//var div=document.createElement('div');
		//div.style.position='absolute';
		//div.style.cursor='n-resize';
		//div.style.backgroundColor='#000';
		//$(div).width('100%').height(bb).move(this.height(),0);
		//div.onmousedown=function(){startDrag(this.parentNode,true);return false;};
		//this.appendChild(div);

		//左
		//var div=document.createElement('div');
		//div.style.position='absolute';
		//div.style.cursor='w-resize';
		//div.style.backgroundColor='#000';
		//$(div).width(bl).height('100%').move(0,0-bl);
		//div.onmousedown=function(){startDrag(this.parentNode,true);return false;};
		//this.appendChild(div);

		//右
		//var div=document.createElement('div');
		//div.style.position='absolute';
		//div.style.cursor='w-resize';
		//div.style.backgroundColor='#000';
		//$(div).width(br).height('100%').move(0,this.width());
		//div.onmousedown=function(){startDrag(this.parentNode,true);return false;};
		//this.appendChild(div);



		return this;
	},

	fixed:function(){
		var o=this;
		if (o.ie){
			this.floatMark();
		}else{
			this.style.position='fixed';
		}
		this.setAttribute('draggable','fixed');
		this.onmouseover=null;
		this.onmousedown=null;

		return this;
	},

	fixedTop:function(){
		var o=this;
		if (o.ie){
			this.top(document.documentElement.scrollTop);
			this.floatMark(10,1,0);
		}else{
			this.style.top='0px';
			this.style.position='fixed';
		}
		this.setAttribute('draggable','fixed');
		this.onmouseover=null;
		this.onmousedown=null;

		return this;
	},

	fixedBottom:function(){
		var o=this;
		if (o.ie){
			var bH=document.documentElement.scrollTop;
			this.top(bH-this.Height());
			this.floatMark(10,1,this.bHeight-this.Height());
		}else{
			var bH=window.innerHeight;
			var divHeight=o.Height();
			this.top(bH-divHeight);
			this.style.position='fixed';
		}
		this.setAttribute('draggable','fixed');
		this.onmouseover=null;
		this.onmousedown=null;

		return this;
	}
}


function __addMethod(elm,obj,overwrite){
	for (var key in obj) {
		//eval(elm+'.'+key+'='+obj[key]);
		if (overwrite){
			elm[key]=obj[key];
		}else{
			if (typeof elm[key]=='undefined'){
				elm[key]=obj[key];
			}
		}
   	}
}


window.$=function (node){
	if (typeof node == 'string'){
		//ref. http://www.vbforums.com/archive/index.php/t-478634.html
		node=document.getElementById(node);
	}

	if(node!=null && !node.test){
		//自訂 property 'test'=true, 如果物件已經存在, 且已繼承屬性方法, 就不再多此一舉
		//IE 不支援對 prototype object 的自訂方法及屬性, 所以只好針對宣告成 document.getElementById 的物件加上自定的方法和屬性
		//這種方式,當頁面中大量使用這些物件語法時, 一個 $(layer) 就要跑一遍, IE 會累死
		//所以測一下是不是已經存在且處理過, 才決定要不要宣告自訂的方法及屬性
		//以下作法可行 8/29 09'
		if (!window.Element) {
			__addMethod(node,__methods,false);
		}
	}

	return node;
}


function $id(id) { return $(document.getElementById(id)); };




if (window.Element) {
	__addMethod(Element.prototype,__methods);

}


function $$(node){
	if (typeof node == 'string'){
		node = document.getElementsByTagName(node);
	}

	return node;
}
//********************************************************************************
//String
//

var __str_methods={
	atrim:function(){
		return this.replace(/\s/g,'');
	},

	right:function(n){
		var start=this.length-n;
		return this.substr(start,n);
	},

	left:function(n){
		return this.substr(0,n);
	},

	cs:function(n){
		if (typeof n=='number'){
			return this.replace(/[^\d.-]/g,'');
		}else{
			return this.replace(/[\$&%<>\+,\/:\'\";=\?\\]/g,'');
		}
	},

	dateAdd:function(interval,number,format){
		//AS VB DateAdd
		number = parseInt(number);
		var date = new Date(this.toString());

		switch(interval){
			case "y": date.setFullYear(date.getFullYear()+number); break;
			case "m": date.setMonth(date.getMonth()+number); break;
			case "d": date.setDate(date.getDate()+number); break;
			case "w": date.setDate(date.getDate()+7*number); break;
			case "h": date.setHours(date.getHour()+number); break;
			case "n": date.setMinutes(date.getMinutes()+number); break;
			case "s": date.setSeconds(date.getSeconds()+number); break;
			case "l": date.setMilliseconds(date.getMilliseconds()+number); break;
		}

		switch(format){
			case 'full':
				break;
			default:
				return date.getFullYear()+'/'+(date.getMonth()+1)+'/'+date.getDate();

		}
	}
};

__addMethod(String.prototype,__str_methods,false);
//********************************************************************************
//Array
//
var __array_methods={
	indexOf:function(v,b,s){
		for(var i=+b || 0,l=this.length;i<l;i++){
			if(this[i]===v || s && this[i]==v){
				return i;
			}
		}
		return -1;
	},

	unique:function(b){
		var a=[],i,l=this.length;
		for(i=0;i<l;i++){
			if(a.indexOf(this[i],0,b)<0){
				a.push(this[i]);
			}
		}
		return a;
	},

	sum:function(){
		var i=this.length,k=0;
		while(i--){
			k+=parseFloat(this[i]);
		}
		return k;
	}
};

__addMethod(Array.prototype,__array_methods,false);


//********************************************************************************
//
//

Ajax=function(args){
	this.createXHR=function(){
		var xmlhttp;
		if (window.XMLHttpRequest) {
			xmlhttp = new XMLHttpRequest();
		}else if (window.ActiveXObject) {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}

		if (!xmlhttp) {
			return false;
		}else{
			return xmlhttp;
		}
	}


	if (typeof args.method=='undifined'){args.method='get';}

	this.url=args.url;
	this.method=args.method.toLowerCase();
	this.form=args.form;

	this.xmlhttp=this.createXHR();

	var o=this;

	this.xmlhttp.open(this.method,this.url,true);
	this.xmlhttp.onreadystatechange=function(){
		if (o.xmlhttp.readyState==4){
			if (o.xmlhttp.status == 200) {
				args.success(o.xmlhttp,o.form);
			}else{
				args.failure(o.xmlhttp,o.form);
			}
		}
	};

	if (this.method=='get'){
		this.xmlhttp.send(null);
	};
	if (this.method=='post'){
		this.xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		this.xmlhttp.send(getFormValue(this.form));
	}

	this.xmlhttp.xmltojson=function(){
		return true;
	}
}
//********************************************************************************
//
//
function readClone(url){
	var xmlhttp=createXHR();
	var form=document.anne;

	xmlhttp.open('GET',url,true);
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4){
			if (xmlhttp.status == 200) {
				var xml=xmlhttp.responseXML;
				restoreData(xml,false);
				setSummery();
			}else{
				alert(alert_11+'[readClone] '+xmlhttp.status+' \('+xmlhttp.statusText+'\)');
			}
		}
	};
	//xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlhttp.send(null);
}

//********************************************************************************
//Document
//
if (document.getElementsByClassName=='undefined'){
	Document.prototype.getElementsByClassName = function(){
	var tTagName ="*";
	if(arguments.length > 1){
		tTagName = arguments[1];
	}
	if(arguments.length > 2){
		var pObj = arguments[2]
	}
	else{
		var pObj = document;
	}
	var objArr = pObj.getElementsByTagName(tTagName);
	var tRObj = new Array();
	for(var i=0; i<objArr.length; i++){
		if(objArr[i].className == arguments[0]){
			tRObj.push(objArr[i]);
		}
	}
	return tRObj;
	}
}

//********************************************************************************
//Date
//

Date.prototype.dateAdd=function(interval,number){
	//AS VB DateAdd
	number = parseInt(number);
	var date = this;

	switch(interval){
		case "y": date.setFullYear(date.getFullYear()+number); break;
		case "m": date.setMonth(date.getMonth()+number); break;
		case "d": date.setDate(date.getDate()+number); break;
		case "w": date.setDate(date.getDate()+7*number); break;
		case "h": date.setHours(date.getHour()+number); break;
		case "n": date.setMinutes(date.getMinutes()+number); break;
		case "s": date.setSeconds(date.getSeconds()+number); break;
		case "l": date.setMilliseconds(date.getMilliseconds()+number); break;
	}
	return date.toString();
}
//********************************************************************************
//
//

function getScrollerWidth() {
	var scr = null;
	var inn = null;
	var wNoScroll = 0;
	var wScroll = 0;

	// Outer scrolling div
	scr = document.createElement('div');
	scr.style.position = 'absolute';
	scr.style.top = '-1000px';
	scr.style.left = '-1000px';
	scr.style.width = '100px';
	scr.style.height = '50px';
	scr.padding='0px';
	scr.margin='0px';
	// Start with no scrollbar
	scr.style.overflow = 'hidden';

	// Inner content div
	inn = document.createElement('div');
	inn.style.width = '100%';
	inn.style.height = '200px';
	inn.padding='0px';
	inn.margin='0px';

	// Put the inner div in the scrolling div
	scr.appendChild(inn);
	// Append the scrolling div to the doc
	document.body.appendChild(scr);

	// Width of the inner div sans scrollbar
	wNoScroll = inn.offsetWidth;
	// Add the scrollbar
	scr.style.overflow = 'auto';
	// Width of the inner div width scrollbar
	wScroll = inn.offsetWidth;

	// Remove the scrolling div from the doc
	document.body.removeChild(document.body.lastChild);

	// Pixel width of the scroller
	return (wNoScroll - wScroll);
}



function autoExpand(textarea){
	//create div
	if (!$('div_'+textarea.name)){
		var cDiv=document.createElement('div');
		cDiv.id='div_'+textarea.name;
		cDiv.style.width=$(textarea).Width()+'px';
		cDiv.style.border='#000 1px solid';
		cDiv.style.position='absolute';
		cDiv.style.top='-3000px';
		cDiv.style.left='-3000px';
		document.getElementsByTagName('body')[0].appendChild(cDiv);

		var iText=document.createElement('input');
		iText.type='text';
		iText.id='text_'+textarea.name;
		iText.style.position='absolute';
		iText.style.top='-3000px';
		iText.style.left='-3000px';
		document.getElementsByTagName('body')[0].appendChild(iText);
	}

	//
	var div=$('div_'+textarea.name);
	var obj=$(textarea);
	$('text_'+textarea.name).style.lineHeight='1.3em';
	var minHeight=$('text_'+textarea.name).Height();

	obj.style.overflow='hidden';
	div.style.fontSize='80%';
	div.innerHTML=obj.value.replace(/\n/g,'<br/>');
	if (div.Height()>minHeight){
		obj.height(div.Height()+minHeight);
		//scrollBy(0,obj.scrollHeight);
	}else{
		obj.height(minHeight);
	}
}

//********************************************************************************
// Form Validation function set
//
function cs(form){
	re=/[\$&%<>\+,\/:\'\";=\?\\]/g;
	if (re.test(form.value)){
		form.value=form.value.replace(/[\$&%<>\+,\/:\'\";=\?\\]/g,'');
	}
}

function checkString(form){
	re=/[\$&%<>\+\/:\'\";=\?\\@]/g;
	if (re.test(form.value)){
		form.value=form.value.replace(/[\$&%<>\+,\/:\'\";=\?\\]/g,'');
	}
}

function checkNum(obj){
	obj.value=obj.value.replace(/[^\d.-]/g,'');
	while(isNaN(obj.value)){
		obj.value=obj.value.substring(0,obj.value.length-1);
	}
}

function Dec2Hex(dec){
    var hexChars = "0123456789ABCDEF";
    var a=dec%16;
    var b=(dec-a)/16;
    var hex=""+hexChars.charAt(b)+hexChars.charAt(a);
    return hex;
}

function Hex2Dec(hex) {
    return parseInt(hex,16);
}

function openWindow(strURL,winName,winWidth,winHeight){

	var objWindow,blnlongcall=false;
	var winHeightBrowserShell=0;

	//center window
	var screenMarginL=0;
	var screenMarginTop=0;

	winWidth=(winWidth<=1)?screen.width*winWidth:winWidth;
	winHeight=(winHeight<=1)?screen.height*winHeight:winHeight;

	if(winWidth>0 && winHeight>0){
		screenMarginL=(screen.width - winWidth)/2;
		screenMarginTop=(screen.height - winHeight - winHeightBrowserShell)/2;
	}

	if(blnlongcall==true){
		window.open(strURL,winName,'width='+winWidth+',height='+winHeight+',left=' + screenMarginL + ',top=' + screenMarginTop + ',toolbar=no,location=no,directories=no,status=no,menubar=no,titlebar=no,scrollbars=no,resizable=yes,copyhistory=no');
	}else{
		objWindow=window.open(strURL,winName,'scrollbars,resizable,width='+winWidth+',height='+winHeight+',left=' + screenMarginL + ',top=' + screenMarginTop);
	}
}

function changeDays(mIndex,daySelect){
	var MonthDay=new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

	if (daySelect.length!=MonthDay[mIndex]){
		daySelect.length=MonthDay[mIndex];
		for (var i=1;i<=MonthDay[mIndex];i++){
			daySelect.options[i-1].text=i;
			daySelect.options[i-1].value=i;
		}
	}
}

function dF(s){
	var s1=unescape(s.substr(0,s.length-1)); var t='';
	for(i=0;i<s1.length;i++)t+=String.fromCharCode(s1.charCodeAt(i)-s.substr(s.length-1,1));
		document.write(unescape(t));
}

function centerDiv(layer){
	var w=$(layer).width();
	$(layer).left((bWidth-w)/2);
}

function clearLinkDot() {
	var i, a, main;
	for(i=0; (a = document.getElementsByTagName("a")[i]); i++) {
		if(a.getAttribute("onFocus")==null) {
			a.setAttribute("onFocus","this.blur();");
		}else{
			a.setAttribute("onFocus",a.getAttribute("onFocus")+";this.blur();");
		}
		a.setAttribute("hideFocus","hidefocus");

		if (a.getAttribute("href") && a.getAttribute("rel") == "external"){
			a.target = "_blank";
		}
	}



	for(i=0; (a = document.getElementsByTagName("input")[i]); i++) {
		if (a.type=='button' || a.type=='submit' || a.type=='reset'){
			if(a.getAttribute("onFocus")==null) {
				a.setAttribute("onFocus","this.blur();");
			}else{
				a.setAttribute("onFocus",a.getAttribute("onFocus")+";this.blur();");
			}
			a.setAttribute("hideFocus","hidefocus");
		}
	}
}

function wait(x){
	if (typeof x!='undefined')
		alert(x);
	else
		alert('wait');
}