/*
		dw_core.js
		version date: April 2003
				
		This code is from Dynamic Web Coding 
    at http://www.dyn-web.com/
    Copyright 2001-3 by Sharon Paine 
    See Terms of Use at http://www.dyn-web.com/bus/terms.html
    Permission granted to use this code 
    as long as this entire notice is included.
*/

/////////////////////////////////////////////////////////////////////
//  _dynObj constructor
//		arguments: id (required): id of positioned div.
//		left,top,width,height optional arguments.
/////////////////////////////////////////////////////////////////////
function _dynObj(id,x,y,w,h) {
	this.el = (document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? _getLyrRef(id,document): null;
	if (!this.el) return null;
	this.doc = (document.layers)? this.el.document: this.el;
	this.css = (this.el.style)? this.el.style: this.el;
	var px = (document.layers||window.opera)? "": "px";
	this.x = x || 0;	if (x) this.css.left = this.x+px;
	this.y = y || 0;	if (y) this.css.top = this.y+px;
	this.width = w? w: (this.el.offsetWidth)? this.el.offsetWidth: (this.css.clip.width)? this.css.clip.width: 0;
	this.height = h? h: (this.el.offsetHeight)? this.el.offsetHeight: (this.css.clip.height)? this.css.clip.height: 0;
	// if w/h passed, set style width/height
	if (w){ (document.layers)? this.css.clip.width=w+px: this.css.width=w+px;}
	if (h){ (document.layers)? this.css.clip.height=h+px: this.css.height=h+px;}
	this.obj = id + "__dynObj"; 	eval(this.obj + "=this");
}

_dynObj.prototype.show = function () { this.css.visibility = "visible"; }
_dynObj.prototype.hide = function () { this.css.visibility = "hidden"; }

_dynObj.prototype.shiftTo = function (x,y) {
	if (x!=null) this.x=x; if (y!=null) this.y=y;	
	// rounded below (this.x/y can hold decimals)
	if (this.css.moveTo) { 
		this.css.moveTo(Math.round(this.x),Math.round(this.y)); 
	} else { 
		this.css.left=Math.round(this.x)+"px"; 
		this.css.top=Math.round(this.y)+"px"; 
	}
}

_dynObj.prototype.shiftBy = function (x,y) {
 
	this.shiftTo(this.x+x,this.y+y);
}

_dynObj.prototype.writeLyr = function (cntnt) {
	if (typeof this.doc.innerHTML!="undefined") {
      this.doc.innerHTML = cntnt;
  } else if (document.layers) {
			this.doc.write(cntnt);
			this.doc.close();
  }
}

_dynObj.prototype.setBgClr = function (bg) {
	if (document.layers) this.doc.bgColor=bg;
	else this.css.backgroundColor=bg;
}

// get reference to nested layer for ns4
// from dhtmllib.js by Mike Hall of www.brainjar.com
function _getLyrRef(lyr,doc) {
	if (document.layers) {
		var theLyr;
		for (var i=0; i<doc.layers.length; i++) {
	  	theLyr = doc.layers[i];
			if (theLyr.name == lyr) return theLyr;
			else if (theLyr.document.layers.length > 0) 
	    	if ((theLyr = _getLyrRef(lyr,theLyr.document)) != null)
					return theLyr;
	  }
		return null;
  }
}

/*
  dw_scroller.js
  Pausing Vertical Scroller v 2.0
  version date April 2003
  requires dw_core.js
    
  This code is from Dynamic Web Coding 
  at http://www.dyn-web.com/
  Copyright 2001-3 by Sharon Paine 
  See Terms of Use at http://www.dyn-web.com/bus/terms.html
  Permission granted to use this code 
  as long as this entire notice is included.
*/

_scrollerObj.ar = new Array();

// left, top, width, height, alignment of content, id of container (if rel-pos)
function _scrollerObj(x,y,w,h,al,hld) {
  this.x=x||0; this.y=y||0; this.w=w; this.h=h; 
  this.al = al || "left"; this.hld = hld;
  this.ctr=1; this.items=new Array(); this.timerId=0;
  
  // defaults
	this.pause 	= 4000;	// how long to pause on messages
	this.spd 		= 55;		// frequency of calls to scroll
	this.inc 		= 3;		// how much to scroll per call
	this.fontFam = "verdana, helvetica, arial, sans-serif";
	this.fontSz 	= "12px";
	this.change     =-13.5;
	this.fontClr  = "#000000";
	this.per_page = 1; //bearcrazy 2007-02-09 ADD
	
	if(hld=="holderone" || hld=="holderone2")
	   this.control=0;
	else
	   this.control=1;
	
	
}

function _addScrollerItem(txt,url) {
	this.items[this.items.length] = new Array(txt,url);
}

function _setScrollerFont(fam,sz,clr) {
	this.fontFam=fam; this.fontSz=sz; this.fontClr=clr;
}

function _setScrollerTiming(pause,spd,inc) {
	this.pause=pause; this.spd=spd; this.inc=inc;
}

function _createScroller() {
  if (this.created) return;
  // rewrite 1st item to last
     //bearcrazy 2007-02-09 START | if(this.control==1)this.items[this.items.length] = this.items[0];
     if(this.control==1) {
     	for (var i=0; i<this.per_page; i++) {
	       this.items[this.items.length] = this.items[i];
        }
     }
     //bearcrazy 2007-02-09 EOF
	_scrollerObj.ar[_scrollerObj.ar.length] = this;	// add it to global list of scrollers
  this.obj = "_scrollerObj"+_scrollerObj.ar.length; eval(this.obj + "=this"); 
	// separate functions for assembling content
	if (document.layers) this.buildN4();
	else this.build();
  this.created = true;
}

function _buildScroller() {
  var elem, str;
  // _scrWndo
  if (document.getElementById && document.createElement) {
    elem = document.createElement("div");
    // if rel-pos
    if (typeof this.hld != "undefined") {
      this.holder = document.getElementById(this.hld);
      this._scrWndo = this.holder.appendChild(elem);
    } else {
		  this._scrWndo = document.body.appendChild(elem);
    }
    this._scrWndo.id = "_scrWndo"+_scrollerObj.ar.length;
		this._scrWndo.style.position = "absolute";
    this._scrWndo.style.visibility = "hidden";
  } else if (document.all) {
    str = '<div id="_scrWndo'+_scrollerObj.ar.length+'" style="position:absolute; visibility:hidden; "></div>';
		// if rel-pos
    if (typeof this.hld != "undefined") {
      this.holder = document.all[this.hld];
      if (typeof this.holder.innerHTML != "undefined")
        this.holder.innerHTML = str;
    } else {
      document.body.insertAdjacentHTML("beforeEnd",str);
    }
  }
  this._scrWndo = new _dynObj("_scrWndo"+_scrollerObj.ar.length,this.x,this.y,this.w,this.h);
  with (this._scrWndo.css) {
  	clip = "rect(0px, "+this.w+"px, "+this.h+"px, 0px)";
		overflow = "hidden"; zIndex=20;	
	} 
  // set up scrolling content layer (_scrCont)
  if (document.getElementById && document.createElement) {
    elem = document.createElement("div");
    this._scrCont = this._scrWndo.el.appendChild(elem);
    this._scrCont.id = "_scrCont" + _scrollerObj.ar.length;
    this._scrCont.style.position = "absolute";
  } else if (document.all) {
    var str = '<div id="_scrCont'+_scrollerObj.ar.length+'" style="position:absolute"></div>';
    this._scrWndo.writeLyr(str);
  }
  this._scrCont = new _dynObj("_scrCont"+_scrollerObj.ar.length);
  this._scrCont.css.visibility = "inherit"; 
  this._scrCont.css.zIndex=5;
  this._scrCont.shiftTo(0,0);
  this._wrapItems();
  this._scrWndo.show();
  this.timerId = setTimeout(this.obj + "._controlScroll()",this.pause);
}

// assemble and write scroller content html 
function _wrapItems() {
   var itemStart, itemEnd, str = "";
  // to format items centered vertically and horizontally
  if (this.al == "center") {
    //itemStart = '<table width="' + this.w + '" cellpadding="0" cellspacing="0" border="0"><tr><td style="text-align:center; height:' + this.h + 'px" valign="middle">';
		itemStart = '<span style="width:' + this.w + '">';
    //itemEnd = '</td></tr></table>';
		itemEnd = '</span>';
  // to format left aligned content
  } else if (this.al == "left") {
    itemStart = '<div style="height:' + this.h + 'px">';
    itemEnd = '</div>';
  }
  for (var i=0; i<this.items.length; i++) {
    if (typeof this.items[i][1] != "undefined") { // if item has url
      str += itemStart + '<a style="text-decoration:none; font-family:'+this.fontFam+'; font-size:'+this.fontSz+'; color:'+this.fontClr+'" href="'+ this.items[i][1] + '">' + this.items[i][0] + '</a>' + itemEnd;
    } else {  // no url, wrap in span with styles attached
      //str += itemStart + '<div style="font-family:'+this.fontFam+'; font-size:'+this.fontSz+'; color:'+this.fontClr+'">' + this.items[i][0] + '</div>' + itemEnd;
      str += itemStart + '<span style="font-family:'+this.fontFam+'; font-size:'+this.fontSz+'; color:'+this.fontClr+'">' + this.items[i][0] + '</span>' + itemEnd;
    }    
  }
  this._scrCont.writeLyr(str);  
}

function _buildScrollerNS4() {
  // create wndo layer  
  if (typeof this.hld != "undefined") {
    this.holder = _getLyrRef(this.hld,document);
    this._scrWndo = new Layer(this.w,this.holder);
  }
	else this._scrWndo = new Layer(this.w);
	this._scrWndo.resizeTo(this.w,this.h);
	this._scrWndo.moveTo(this.x,this.y);

	// create the scrolling content layer 
	var str = '<div id="_scrCont'+_scrollerObj.ar.length+'" style="position:absolute"></div>';
	this._scrWndo.document.write(str);
	this._scrWndo.document.close();
	this._scrCont = new _dynObj("_scrCont"+_scrollerObj.ar.length);
	this._scrCont.css.visibility = "inherit"; 
  this._scrCont.css.zIndex=1;
  this._scrCont.shiftTo(0,0);
  this._wrapNS4Items();
	this._scrWndo.visibility = "show";
  this.timerId = setTimeout(this.obj + "._controlScroll()",this.pause);
}

function _wrapNS4Items() {
	var itemStart, itemEnd, str = "";
	if (this.al=="center") this.v = "middle";
	else this.v = "top";
  itemStart = '<table width="' + this.w + '" cellpadding="0" cellspacing="0" border="0"><tr><td align="'+this.al+'" height="' + this.h + '" valign="'+this.v+'">';
  itemEnd = '</td></tr></table>';
  for (var i=0; i<this.items.length; i++) {
    if (typeof this.items[i][1] != "undefined") { // if item has url
      str += itemStart + '<a style="text-decoration:none; font-family:'+this.fontFam+'; font-size:'+this.fontSz+'; color:'+this.fontClr+'" href="'+ this.items[i][1] + '">' + this.items[i][0] + '</a>' + itemEnd;
    } else {  // no url, wrap in span with styles attached
      str += itemStart + '<div style="font-family:'+this.fontFam+'; font-size:'+this.fontSz+'; color:'+this.fontClr+'">' + this.items[i][0] + '</div>' + itemEnd;
    }
  }
  this._scrCont.writeLyr(str);
}

function _controlScroll() {
	if (this.ctr>this.items.length-this.per_page) this._startOver(); //bearcrazy 2007-02-09 | if (this.ctr>this.items.length-1) this._startOver();
	else {
		var y = parseInt(this._scrCont.css.top);
//更改這裡啦		 
		if (y > this.change * this.ctr) { 
			this._scrCont.shiftBy(0,-this.inc);	
			this.timerId = setTimeout(this.obj+"._controlScroll()",this.spd);	
		} else {
				this.ctr++;
				this.timerId = setTimeout(this.obj+"._controlScroll()",this.pause);	
		}

	}
}

// restore scroller top to 0 and counter variable to 1
function _startOver() {
	//this.ctr = 0;
	this.ctr = this.control;
	this._scrCont.shiftTo(0,0);
	this._controlScroll();	
}

_scrollerObj.prototype.addItem = _addScrollerItem;
_scrollerObj.prototype.create = _createScroller;
_scrollerObj.prototype.setFont = _setScrollerFont; 
_scrollerObj.prototype.setTiming = _setScrollerTiming;
_scrollerObj.prototype.buildN4 = _buildScrollerNS4; 
_scrollerObj.prototype.build = _buildScroller;
_scrollerObj.prototype._wrapItems = _wrapItems;
_scrollerObj.prototype._wrapNS4Items = _wrapNS4Items;
_scrollerObj.prototype._controlScroll = _controlScroll;
_scrollerObj.prototype._startOver = _startOver;

// remove layers from table for ns6+/mozilla (overflow/clip bug?)
function _positionGecko() {
	if (navigator.userAgent.indexOf("Gecko")>-1) {
    for (var i=0; i<_scrollerObj.ar.length; i++) {
			if (_scrollerObj.ar[i].holder) {
				_scrollerObj.ar[i].holder.removeChild(_scrollerObj.ar[i]._scrWndo.el);
				document.body.appendChild(_scrollerObj.ar[i]._scrWndo.el);
				_scrollerObj.ar[i]._scrWndo.css.zIndex = 1000;
        var x = _scrollerObj.ar[i].holder.offsetLeft + _scrollerObj.ar[i].x;
				var y = _scrollerObj.ar[i].holder.offsetTop + _scrollerObj.ar[i].y;
				_scrollerObj.ar[i]._scrWndo.shiftTo(x,y);
			}
  	}
  }
}

// ns6+/mozilla need to reposition layers onresize
function _rePosGecko() {
  for (var i=0; i<_scrollerObj.ar.length; i++) {
		var x = _scrollerObj.ar[i].holder.offsetLeft + _scrollerObj.ar[i].x;
		var y = _scrollerObj.ar[i].holder.offsetTop + _scrollerObj.ar[i].y;
		_scrollerObj.ar[i]._scrWndo.shiftTo(x,y);
  }
}

function _setMouseEvents() {
  for (var i=0; i<_scrollerObj.ar.length; i++) {
    _scrollerObj.ar[i]._scrCont.el.onmouseover = new Function("_haltScroll("+i+")")
    _scrollerObj.ar[i]._scrCont.el.onmouseout = _restartScroll;
  }
}

function _haltScroll(num) {
  clearTimeout(_scrollerObj.ar[num].timerId);
}

function _restartScroll(e) {
  // get numeric portion of id (after _scrCont)
  var num = parseInt(this.id.slice(8)) - 1;
  e = e? e: window.event? window.event: "";
  if (e) {
    var current = this;
    var related =  e.relatedTarget? e.relatedTarget: e.toElement? e.toElement: "";
  		if (related) {
        if (current != related && !_contains(current, related)) 
          _scrollerObj.ar[num]._controlScroll();
      } else _scrollerObj.ar[num]._controlScroll(); // ns4
  }
}

// adapted from http://www.brainjar.com/dhtml/events/default6.asp
function _contains(a, b) {
	// extra checks in case alt-tab away while over menu
	if (b && b.parentNode) {	
	  // Return true if node a _contains node b.
	  while (b.parentNode)
	    if ((b = b.parentNode) == a)
	      return true;
	  return false;
	} else if (b && b.parentElement) {
		while (b.parentElement)
		    if ((b = b.parentElement) == a)
		      return true;
		  return false;
	}
}