/*<![CDATA[*/
function zxcMouseOverCarousel(o){
 var obj=document.getElementById(o.ID);
 if (obj&&obj.getElementsByTagName('DIV')[0]){
  var slide=obj.getElementsByTagName('DIV')[0],slider=document.createElement('DIV'),mde=typeof(o.Mode)=='string'?o.Mode:'H',clds=slide.childNodes,lst=clds[clds.length-1],max,ud=o.Direction,minspd=o.MinSpeed,maxspd=o.MaxSpeed,ar=o.AutoRotate,lft=0,z0=0;
  obj.style.overflow='hidden';
  mde=mde.charAt(0).toUpperCase()=='V'?['top','height',1,'offsetTop','offsetHeight','left']:['left','width',0,'offsetLeft','offsetWidth','top'];
  slide.style.position='absolute';
  slide.style[mde[1]]='10000px';
  lst=lst.nodeType!=1?lst.previousSibling:lst;
  lst=lst.nodeName.toUpperCase()=='A'?lst.getElementsByTagName('*')[0]:lst;
  max=lst[mde[3]]+lst[mde[4]];
  slider.style.position='absolute';
  slider.style[mde[0]]=-max+'px';
  slider.style[mde[5]]='0px';
  var nu=Math.max(Math.ceil(obj[mde[4]]/max)+1,3);
  for (var z1=0;z1<nu;z1++){
   slide=z1>0?slide.cloneNode(true):slide;
   slide.style[mde[0]]=z1*max+'px';
   slider.appendChild(slide);
  }
  obj.appendChild(slider);
  this.obj=obj;
  this.slider=[slider,-max];
  this.mde=mde;
  this.max=max;
  this.ud=typeof(ud)=='number'?ud>0?1:-1:1;
  this.minspd=Math.min(typeof(minspd)=='number'?minspd:1,0);
  this.maxspd=typeof(maxspd)=='number'?maxspd:10;
  this.autospd=Math.max(Math.min(typeof(ar)=='number'?ar:0,this.maxspd),this.minspd);
  this.inc=this.autospd;
  this.run=true;
  this.scroll();
  this.mS=2000;
  this.to1=null;
  this.to2=null;
  if (o.PanEnds){
   this.MouseOverEnds(o.PanEnds);
  }
  if (o.AddEvents){
   this.AddEvents(o.AddEvents);
  }
 }
}

zxcMouseOverCarousel.prototype={

 Direction:function(ud){
  this.ud=typeof(ud)=='number'?ud>0?1:-1:0;
 },

 Speed:function(spd){
  this.autospd=typeof(spd)=='number'?spd:this.autospd;
  this.inc=this.autospd;
 },

 Pause:function(){
  clearTimeout(this.to1);
  clearTimeout(this.to2);
 },

 scroll:function(){
  clearTimeout(this.to1);
  var oop=this,slider=this.slider,ud=this.ud,max=this.max;
  slider[1]+=this.inc*ud;
  if ((ud<0&&slider[1]<-max)||(ud>0&&slider[1]>0)){
   slider[1]+=max*(ud<0?1:-1);
  }
  slider[0].style[this.mde[0]]=slider[1]+'px';
  this.to1=setTimeout(function(){ oop.scroll(); },20);
 },

 addevt:function(o,t,f,p){
  var oop=this;
  if (o.addEventListener) o.addEventListener(t,function(e){ return oop[f](p,e); }, false);
  else if (o.attachEvent) o.attachEvent('on'+t,function(e){ return oop[f](p,e); });
 },

// Optional Mouseover Ends Code.
 MouseOverEnds:function(o){
  var pan=typeof(o.Distance)=='number'?o.Distance:this.obj[this.mde[3]]/4;
  this.panends=[pan,this.obj[this.mde[4]]-pan];
  this.ends=o.Reverse==true?[-1,1]:[1,-1];
  this.addevt(this.obj,'mousemove','move');
  this.addevt(this.obj,'mouseout',o.Mouseout==true?'AutoRotate':'Pause',this.obj);
 },

 move:function(x,e){
  var x=this.mse(e)[this.mde[2]]-this.pos(this.obj)[this.mde[2]],pends=this.panends;
  this.inc=0;
  if (x<pends[0]){
   this.ud=this.ends[0];
   this.inc=this.maxspd*(1-x/pends[0]);
  }
  else if (x>pends[1]){
   this.ud=this.ends[1];
   this.inc=this.maxspd*((x-pends[1])/pends[0]);
  }
 },

 mse:function(e){
  if (document.all) return [e.clientX+this.docs()[0],e.clientY+this.docs()[1]];
  return [e.pageX,e.pageY];
 },

 docs:function(){
  if (!document.body.scrollTop) return [document.documentElement.scrollLeft,document.documentElement.scrollTop];
  return [document.body.scrollLeft,document.body.scrollTop];
 },

 pos:function(obj){
  var rtn=[0,0];
  while(obj){
   rtn[0]+=obj.offsetLeft;
   rtn[1]+=obj.offsetTop;
   obj=obj.offsetParent;
  }
  return rtn;
 },

// Optional Add Events Code.
 AddEvents:function(ary){
  ary=typeof(ary)=='object'&&ary.constructor==Array?ary:[];
  for (var but,type,z1=0;z1<ary.length;z1++){
   var but=document.getElementById(ary[z1][0]),type=this.evttype(ary[z1][2]);
   if (but&&type&&this[ary[z1][1]]){
    this.addevt(but,type,ary[z1][1],ary[z1][3]);
   }
  }
 },

 evttype:function(et){
  type=(typeof(et)=='string'?et:'').toLowerCase().replace('on','');
  return type=='click'||type=='mousedown'||type=='mouseup'||type=='mouseover'||type=='mouseout'?type:false;
 },

// Optional Auto Rotate Code.
 AutoRotate:function(obj){
  var e=window.event||arguments.callee.caller.arguments[0];
  if (e.type=='mouseout'&&obj){
   var eo=e.relatedTarget?e.relatedTarget:e.toElement;
   if (eo){
    while (eo.parentNode){
     if (eo==obj){
      return false;
     }
     eo=eo.parentNode;
    }
   }
  }
  this.inc=this.autospd;
  this.Pause();
  this.scroll();
 },

// Optional Progressive Code.
 Progressive:function(o){
  var to=o.ToSpeed,from=o.FromSpeed,ms=o.Duration,ud=o.Direction;
  if (typeof(to)=='number'){
   this.Pause();
   this.run=true;
   this.ud=typeof(ud)!='number'?this.ud:ud<0?-1:1;
   this.from=typeof(from)=='number'?from:this.inc;
   this.to=to;
   this.mS=typeof(ms)=='number'?ms:2000;
   this.pi=Math.PI/(2*this.mS);
   this.srt=new Date().getTime();
   this.progress();
   this.scroll();
  }
 },

 progress:function(){
  var oop=this,ms=new Date().getTime()-this.srt;
  this.inc=Math.floor(this.to-(this.to-this.from)*Math.cos(this.pi*ms));
  if (ms<this.mS){
   this.to2=setTimeout(function(){oop.progress()},10);
  }
 }
}

var S;
function Init(){
 S=new zxcMouseOverCarousel({
 ID:'boxslide',           // the unique id name of the DIV to scroll.                                (string)
 Mode:'Horizontal', // the mode, 'Horizontal' or 'Vertical'.                                   (string, default = 'Horizontal')
 Direction:-1,      // (optional) the initial direction, 1 or -1.                              (number, default = 1)
 AutoRotate:1,      // (optional) the auto rotation speed.                                     (number, default = 0)
 MinSpeed:1,        // (optional) the mimimum rotation speed.                                  (number, default = 0)
 MaxSpeed:10,       // (optional) the maximum rotation speed.                                  (number, default = 10)
 PanEnds:{          // (optional) to increase rotation speed on mousemove of th carousel ends. (object, default = no pan ends)
  Distance:160,  // (optional) the distance from the ends to pan.            (number, default = parent node width/4)
  Mouseout:true, // (optional) autorotate onmouseout.                        (boolean, default = false = no autorotate)
  Reverse:true   // (optional) reverse the pan direction of the ends.        (boolean, default = false = no reverse)
 },
 AddEvents:[       // (optional) see Script Functions
   ['B1','Progressive','mouseover',{ToSpeed:10,Duration:2000,Direction:-1}],
   ['B1','Progressive','mouseout',{ToSpeed:0,Duration:2000}],
   ['B2','Progressive','mouseover',{ToSpeed:10,Duration:2000,Direction:1}],
   ['B2','Progressive','mouseout',{ToSpeed:0,Duration:2000}]
  ]
});
}
if (window.addEventListener){
 window.addEventListener('load',Init, false);
}
else if (window.attachEvent){
 window.attachEvent('onload',Init);
}
/*]]>*/
