// autogenerated on Mar 10th, 2010 at 5:29 pm

if (!window.horus) window.horus={ window: window };
horus.cspot={};
horus.sitetag='castweb';
horus.sitedata=window.castweb={};


castweb.castingimage=
  function () {
    var self=castweb.castingimage;
    var next=self.images[self.last].next;
    var now=new Date().getTime();

    if (next && now-self.refreshed>self.refresh) {
      for (next in self.images) delete self.images.next;
      next=false;
    }

    if (next)
      image=self.images[next];
    else {
      var response=horus.ajax('/localaction/bodyhead.cfm', 'castingimage');

      if (response) {
	self.refreshed=now;
	next=self.images[self.last].next=response.getAttribute(null, 'ordering');
	image=self.images[next];
	if (!image) image=self.images[next]={};
	image.filename=response.getAttribute(null, 'filename');
	image.alt=image.title=response.getAttribute(null, 'title');
      }
    }

    if (next) {
      self.image.src='/castingimages/rightcol/'+image.filename;
      self.image.title=image.title;
      horus.childText(self.text, image.title);
      self.last=next;
      setTimeout(self.fadein, 500);
    }

    setTimeout(self.fadeout, self.hold);
  };


castweb.castingimage.fadein=
  function () {
    var self=castweb.castingimage;
    if (!self.image.complete) setTimeout(self.fadein, 100);

    if (!self.instep)
      self.$opacity=horus.opacity([ self.image, self.text ], 1);
    else {
      self.$opacity=horus.opacity([ self.image, self.text ], self.$opacity+0.04);
      if (self.$opacity<1) setTimeout(self.fadein, self.instep);
    }
  };


castweb.castingimage.fadeout=
  function () {
    var self=castweb.castingimage;

    if (!self.outstep) {
      self.$opacity=horus.opacity([ self.image, self.text ], 0);
      self();
    } else {
      self.$opacity=horus.opacity([ self.image, self.text ], self.$opacity-0.04);

      if (self.$opacity>0)
        setTimeout(self.fadeout, self.outstep);
      else
        self();

    }
  };


castweb.castingimage.init=
  function () {
    var self=castweb.castingimage;
    self.image=document.getElementById('castimage');
    self.text=document.getElementById('casttext');
    self.$opacity=1;
    setTimeout(self.fadeout, self.hold);
  };


castweb.ticker=[ '-', '\\', '|', '/' ];
castweb.ticker.tick=-1;


String.prototype.spin=
  function ( target, callback, style ) {
    var ptr=this.cursor;

    if (target || !ptr) {
      if (target) {
        var self=this;
        this.spinner=function () { self.spin() };
        this.callback=callback;
        this.target=target;
        this.wrap=target.parentNode;
        target.className=style;
      }

      this.text=horus.deleteText(this.target);
      ptr=0;
    }

    this.text.appendData(this.charAt(ptr++));
    this.wrap.scrollTop=this.wrap.scrollHeight;

    if (ptr<this.length) {
      horus.childText(this.target.spinner, castweb.ticker[ptr%castweb.ticker.length]);
      this.target.spinner.style.display='';
    } else
      this.target.spinner.style.display='none';

    this.cursor=ptr;

    if (ptr<=this.length)
      setTimeout(this.spinner, castweb.ticker.char_delay);
    else
      setTimeout(this.callback, castweb.ticker.line_delay);

  };


castweb.ticker.back=
  function () {
    var now=new Date().getTime();

    if (now-castweb.ticker.refreshed>castweb.ticker.refresh) {
      var response=horus.ajax
	('/localaction/bodyhead.cfm', 'ticker',
	 { since: castweb.ticker.refreshed, count: castweb.ticker.text.length });

      if (response && response.getAttribute(null, 'changed', false)) {
	castweb.ticker.refreshed=now;
	castweb.ticker.text.length=0;
	var result=response.selectNodes('horus/ticker');

	for (var i=0; i<result.length; i++) {
	  var ticker=result[i];

	  castweb.ticker.text.push
	    ({ style: response.getAttribute(ticker, 'style'),
	       rolling: response.getAttribute(ticker, 'rolling') });

	}
      }
    }

    castweb.ticker.tick=(castweb.ticker.tick+1)%castweb.ticker.text.length;
    var entry=castweb.ticker.text[castweb.ticker.tick];
    entry.rolling.spin(castweb.ticker.area, castweb.ticker.back, entry.style) 
  };


castweb.ticker.init=
  function () {
    castweb.ticker.area=document.getElementById('scrolltext');
    castweb.ticker.area.spinner=document.getElementById('spinner');
    castweb.ticker.refreshed=new Date().getTime();
    castweb.ticker.back();
  };
