/* homeshow javascript Copyright 2011 Fund for the City of New York, All rights reserved */

document.writeln("<style type='text/css'> div.slide { filter: alpha(opacity=00); opacity: 0.00; -ms-filter:\"progid:DXImageTransform.Microsoft.Alpha(opacity=00)\"; } div.first { filter: alpha(opacity=100); opacity: 1.00; -ms-filter:\"progid:DXImageTransform.Microsoft.Alpha(opacity=100)\"; } </style>");

var homeshow = { "version": "1.0", "ptr": 0, "activeslide": false, "slides": [], "duration": 3000 };

homeshow.next = function() {
  this.ptr++;
  if ( !this.slides[this.ptr] ) {
    this.ptr = 0;
  }
  this.showslide( this.slides[ this.ptr ] );
  if ( this.slides.length > 1 ) {
    window.setTimeout( "homeshow.next()", homeshow.duration );
  }
}

homeshow.showslide = function( slide ) {
  if ( this.activeslide ) {
    Opacity( this.activeslide, { "from": 1.0, "to": 0, "duration": 1.0, "afterFinish": function( eff ){ eff.element.style.display = "none"; } } );
  }
  Opacity( slide, { "from": 0, "to": 1.0, "duration": 1.0, "beforeStart": function( eff ){ eff.element.style.display = "block"; } } );
  this.activeslide = slide;
}

homeshow.init = function() {
  var id = false;
  if ( window.location.hash ) {
    id = window.location.hash.substr(1);
  }
  iterateElementsByTagAndClassName ( "div", "slide", $("Main"), function( elements, i ) {
    homeshow.slides.push( elements[i] );
    if ( id && elements[i].id==id ) {
      homeshow.ptr = i;
      homeshow.showslide( elements[i] );
    }
  });
  if ( id ) {
    connect( window, "onload", function() { window.setTimeout( "homeshow.next()", ( homeshow.duration * 2 ) ); } );
  }
  else {
    window.setTimeout( "homeshow.next()", homeshow.duration );
  }
}

connect( window, "ondomload", homeshow, "init" );
