var detect = navigator.userAgent.toLowerCase();
var browser;
if (detect.indexOf('msie') + 1) browser = "ie";

function ieTransionInit(imgName)
{
    document.images[imgName].style.filter="blendTrans(duration=1)";
    document.images[imgName].filters.blendTrans(duration=2).Apply();
    document.images[imgName].filters.blendTrans.Play();
}
function switchImage(imgName, imgSrc) 
{
  if (document.images)
  {
    if (imgSrc != "none")
    {
      if (browser == "ie") ieTransionInit(imgName);
      document.images[imgName].src = 'images/slides/' + imgSrc;
    }
  }
}

/////////// List & Instance
var slideTopList= ['colorsmile.jpg', 
				   'twoonslide.jpg', 
				   'hanginout-b.jpg', 
				   'hi-everybody!-b.jpg'];
var slideTopShow = new SlideShow(slideTopList, 'slideTop', 7400, "slideTopShow");

/////////// List & Instance
var slideMiddleList= ['twosmiles.jpg', 
				   'kneelsmile.jpg', 
				   'overheadbars.jpg', 
				   'teacherreads.jpg'];
var slideMiddleShow = new SlideShow(slideMiddleList, 'slideMiddle', 6800, "slideMiddleShow");

/////////// List & Instance
var slideBottomList= ['swingsmile.jpg',  
                   'bighug.jpg', 
				   'handprint.jpg',
				   'cycling.jpg'];
var slideBottomShow = new SlideShow(slideBottomList, 'slideBottom', 8700, "slideBottomShow");

/////////// Constructor
function SlideShow(slideList, image, speed, name)          
{
  this.slideList = slideList;
  this.image = image;
  this.speed = speed;
  this.name = name;
  this.current = 0;
  this.timer = 0;
}

////////// Endlessly Swap Slides
SlideShow.prototype.play = SlideShow_play;  
function SlideShow_play()       
{
  with(this)
  {
    if(current++ >= slideList.length) current = 0;
	current = randomNumber(slideList.length);
    switchImage(image, slideList[current]);
    timer = setTimeout(name+'.play()', speed);
  }
}

////////////////////////
function randomNumber(limit){
  return Math.floor(Math.random()*limit); 
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function JI_checkWidth(){ // Pages should be centered except when window is too narrow, then should be right-aligned
	if (document.body.clientWidth < "785") document.getElementById("mainContainer").className="mainContainerL";
	else document.getElementById("mainContainer").className="mainContainerC";
}
function JI_ol() {
	MM_preloadImages(
			'images/nav06-enrollment-hi.jpg',
			'images/nav01-home-hi.jpg',
			'images/nav02-contactus-hi.jpg',
			'images/nav03-aboutus-hi.jpg',
			'images/nav04-program-hi.jpg',
			'images/nav05-schedule-hi.jpg',
			'images/nav07-calendar-hi.jpg',
			'images/nav08-newsletter-hi.jpg',
			'images/nav09-footer-efchb-hi.jpg',
			'images/slides/kneelsmile.jpg',
			'images/slides/swingsmile.jpg',
			'images/slides/bighug.jpg',
			'images/slides/handprint.jpg',
			'images/slides/cycling.jpg',
			'images/slides/twosmiles.jpg',
			'images/slides/overheadbars.jpg',
			'images/slides/teacherreads.jpg',
			'images/slides/colorsmile.jpg',
			'images/slides/twoonslide.jpg',
			'images/slides/hanginout-b.jpg',
			'images/slides/hi-everybody!-b.jpg');
	JI_checkWidth(); 
	setTimeout('slideTopShow.play()',6700);  
	setTimeout('slideMiddleShow.play()',8900);  
	setTimeout('slideBottomShow.play()',3900);
}
