// ================ from libCrossBrowser.js ====================
// variables
// version of library
LCB_version = 2.81; // 2.8 + Mac OS X版 IE5.12対応版
// _mac : true = macintosh, false = other os
_mac=navigator.userAgent.indexOf('Mac')!=-1;
// _ie512 : true = MSIE 5.12(mac), false = others
_ie512=navigator.userAgent.indexOf('MSIE 5.12')!=-1;
// _dom : kind of DOM.
//        IE4 = 1, IE5+ = 2, NN4 = 3, NN6+ = 4, others = 0
_dom = document.all?(document.getElementById?2:1)
                   :(document.getElementById?4:(document.layers?3:0));

//
function getWindowWidth (){
  if(_dom==4 || _dom==3) return window.innerWidth;
  if(_dom==2 || _dom==1) return (_mac&&_ie512)?document.body.offsetWidth:document.body.clientWidth;
  return 0;
}
function getDivWidth (div){
  if(_dom==4 || _dom==2) return div.offsetWidth;
  if(_dom==1)            return div.style.pixelWidth;
  if(_dom==3)            return div.clip.width;
  return 0;
}
function getDivTop(div){
  if(_dom==4 || _dom==2) return div.offsetTop;
  if(_dom==1)            return div.style.pixelTop;
  if(_dom==3)            return div.top;
  return 0;
}
function moveDivTo(div,left,top){
  if(_dom==4){
    div.style.left=left+'px';
    div.style.top =top +'px';
    return;
  }
  if(_dom==2 || _dom==1){
    div.style.pixelLeft=left;
    div.style.pixelTop =top;
    return;
  }
  if(_dom==3){
    div.moveTo(left,top);
    return;
  }
}
// ============================ main =============================
ww=0;
x=0; y=0; w=0;
deltaX=5;
tid=null;
ctrls = new Array(
  new Ctrl('OUT_COUNT', 0,''),
  new Ctrl('OUT_MAIN',1,'')
  );
function Ctrl(nm,id,bgc){
  this.name    = nm;
  this.frameId = id;
  this.bgColor = bgc;
  this.init    = false;
  this.div     = null;
  this.left    = 0;
  this.width   = 0;
  return this;
}
Ctrl.prototype.moveTo = function(x,y){
  var act=false;
  if(this.init){
    moveDivTo(this.div,x - this.left,y);
    act=true;
  }
  return act;
}
function winName2Id(nm){
  for(var i=0; i<ctrls.length; i++){
    if(ctrls[i].name==nm) return i;
  }
  return 0;
}
function getBgColor(id){ return ctrls[id].bgColor; }
function initPage(id,div,width){
  var ctrl = ctrls[id];
  ctrl.div   = div;
  ctrl.width = width;
  if(ww==0){
    ww=getWindowWidth();
    w =getDivWidth(div);
    x =0;
    y =0;
  }
  ctrl.init  = true;
  var left=0;
  for(var i=0; i<ctrls.length; i++){
    ctrl = ctrls[i];
    ctrl.left = left;
    left+=ctrl.width;
    ctrl.moveTo(x,y);
  }
}

function manage(){
  if(deltaX>0){ if((x+deltaX+w)>getWindowWidth()) deltaX=-deltaX; }
  else        { if((x+deltaX  )<0               ) deltaX=-deltaX; }
  var nx=x+deltaX, act=false;
  for(var i=0; i<ctrls.length; i++)
    if(ctrls[i].moveTo(nx,y)) act=true;
  if(act) x=nx;
  tid=setTimeout('manage()',interval);
}
function cancel(id){
  if(arguments.length>0){
    ctrls[id].init=false;
  }
  else 
  	if(tid)
  	{ 
  		clearTimeout(tid); 
  		tid=null; 
  	}
}
/*
onunload=cancel()	
をBody内に挿入
*/