var ibc = {
  // These are parameters that can be adjusted
  initialDelay: 4000, // Milliseconds to wait before starting animation
  restartDelay: 4000, // Milliseconds pause between repetitions
  numLoops: 1000,        // How many times to loop through the headlines
  frameLength: 50,    // Milliseconds per frame
  pixelsPerFrame: 2,  // How much to scroll up each frame.
  pauseLength: 4000,  // Milliseconds to pause between individual headlines
  URLprefix:"http://ibc.surfaceeffect.com/IBC/",

  headlineFile:"http://www.iraqbodycount.net/counters/headlines.js",
  textStyle:'font-family: Helvetica,Arial,sans-serif; font-size: 12px; color: #0000; vertical-align: middle; text-align: center; overflow: hidden; width: 100px; height: 63px; line-height:12px;',
  repetitions:0,
  pageText:"",
  viewport:null,
  page:null,
  viewportHeight:0,
  pageHeight:0,
  curpos:0,
  headlines:null,
  checked:false,
  headlineNumber:0,
  paused:false,
  timeoutid:null,
  nocache:"?"+Math.floor((new Date()).getTime()/900000),
  checkCapabilities:function() {
    if(!document.getElementById)return false;
    var m=document.getElementById('IBCViewport');
    if(m==null||m["offsetHeight"]==null||m["offsetTop"]==null||m["style"]==null||
       m["innerHTML"]==null||m["getElementsByTagName"]==null||window["setTimeout"]==null)return false;
    return true;
  },

  headlines:function() {
    this.pageText="";
    for (var i=2;i<arguments.length;i++) {
      this.pageText+="<div style='padding: 9px 3px 9px 3px;'>"+arguments[i]+"</div>";
    }
    setTimeout("ibc.animate()",this.initialDelay);
  },
  
  restart:function(){
    setTimeout("ibc.animate()",this.restartDelay);
  },
  
  animate:function(){
    if(!this.checked) {
      if(!this.checkCapabilities())return;
      this.checked=true;
      this.viewport=document.getElementById('IBCViewport');
      this.page=document.getElementById('IBCPage');
      this.viewportHeight=this.viewport.offsetHeight;
      this.page.style.position="relative";
    }
    this.curpos=this.viewportHeight;
    this.page.style.top=this.curpos+"px";
    this.page.innerHTML=this.pageText;
    this.pageHeight=this.page.offsetHeight;
    this.headlines=this.page.getElementsByTagName("DIV");
    this.headlineHeights=new Array(this.headlines.length);
    this.headlinePositions=new Array(this.headlines.length);
    for(var i=0;i<this.headlines.length;i++){
      this.headlineHeights[i]=this.headlines[i].offsetHeight;
      this.headlinePositions[i]=this.headlines[i].offsetTop;
    }
    this.headlineNumber=0;
    this.targetPos=-this.headlinePositions[0]+(this.viewportHeight-this.headlineHeights[0])/2;
    ibc.nextFrame();
  },
  
  nextFrame:function(){
    if(this.paused)return;
    this.curpos-=this.pixelsPerFrame;
    if(this.curpos<this.targetPos)this.curpos=this.targetPos;
    this.page.style.top=this.curpos+"px";if(this.curpos>this.targetPos){this.timeoutid=setTimeout("ibc.nextFrame()",this.frameLength);}
else{this.headlineNumber++;if(this.headlineNumber<this.headlines.length){this.targetPos=-this.headlinePositions[this.headlineNumber]+
(this.viewportHeight-this.headlineHeights[this.headlineNumber])/2;this.timeoutid=setTimeout("ibc.nextFrame()",this.pauseLength);return;}
else if(this.headlineNumber==this.headlines.length){this.targetPos=-this.pageHeight;this.timeoutid=setTimeout("ibc.nextFrame()",this.pauseLength);return;}
else{this.repetitions++;this.page.innerHTML=this.defaultText;this.page.style.top="0px";if(this.repetitions<this.numLoops)this.restart();return;}}},pause:function(){if(this.timeoutid!=null){this.paused=true;clearTimeout(this.timeoutid);this.timeoutid=null;}},resume:function(){if(this.paused){this.paused=false;this.nextFrame();}}}

ibc.defaultText='<a href="http://www.iraqbodycount.org/"><img src="'+ibc.URLprefix+'ibc100_2.gif" width="100" height="63" border="0" alt="Reported Civilian Deaths"></a>';

document.write('<table width="100" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td><a href="http://www.iraqbodycount.org/"><img src="'+ibc.URLprefix+'ibc100_1.gif" alt="www.iraqbodycount.org" width="100" height="36" border="0"></a></td></tr><tr><td width="100" height="63" background="'+ibc.URLprefix+'ibc100_4.gif"><div id="IBCViewport" align="center" onmouseover="ibc.pause()" onmouseout="ibc.resume()" style="'+ibc.textStyle+'"><div id="IBCPage" style="width:100px; height:63px;">');

document.write(ibc.defaultText);
document.write('</div></div></td></tr><tr><td><a href="http://www.iraqbodycount.org/"><img src="'+ibc.URLprefix+'ibc100_3.gif" alt="" width="100" height="15" border="0"></a></td></tr><tr><td width="100" height="22" align="center" valign="top" background="'+ibc.URLprefix+'ibc100_5.gif" border="0" alt=""><a href="http://www.iraqbodycount.org/">');
document.write("<img src='http://www.iraqbodycount.net/counters/ibc_b.gif"+
ibc.nocache+"' "+"width='94' height='19' border='0' "+"onerror='this.src=\"http://www.iraqbodycount.org/counters/ibc_b.gif"+ibc.nocache+"\"; this.style.display=\"inline\";'>");document.write("</a></td></tr></tbody></table>");if(ibc.numLoops>0&&(navigator.appName!="Netscape"||parseInt(navigator.appVersion)>4))
document.write('<script src="'+ibc.headlineFile+ibc.nocache+'"></'+'script>');

