var fadeSpeed = 50;
var stopSpeed = 5000;
var thumbsrc = new Array("","images/fade1/", "images/fade2/", "images/fade3/");
var totalCnt = new Array(0,4,5,2);


function initImage(theId) {
  outerId = 'fade'+theId+'_outer';
  innerId = 'fade'+theId+'_inner';
  //changeimg(outerId, innerId, theId, 0);
  imageId = innerId;
  image = document.getElementById(imageId);
  setOpacity(image, 0);
  image.style.visibility = 'visible';
  changeimg(outerId, innerId, theId, 0,1);
}

function setOpacity(obj, opacity) {
  opacity = (opacity == 100)?99.999:opacity;
  opacity = (opacity == 0)?1:opacity;
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
  
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;
  
  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;
  
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}

function fadeIn(outerId,innerId,opacity,isIn, theid, igoredefault) {
/*alert(outerId);
alert(innerId);
alert(opacity);
alert(isIn);*/

  /*if (theid!=staffno){
	gofade = true;
  }else if (igoredefault){
	gofade = true;
  }else{  
	if 
	gofade = false;
  }*/
  
  if (staffinfo[theid][4]){
	staffinfo[theid][4] = false;	
  }
  
  gofade = true;
  if (gofade){
	  nextfade = fadeSpeed;
	  if (document.getElementById) {
	    obj = document.getElementById(innerId);
		if (isIn==1){
			if (opacity <= thumbop) {
				setOpacity(obj, opacity);
				opacity += 5;
				isIn = 1;
				window.setTimeout("fadeIn('"+outerId+"','"+innerId+"',"+opacity+","+isIn+", "+theid+", "+igoredefault+")", nextfade);
			}else{
				opacity -= 5;
				isIn = 0;
				staffinfo[theid][4] = true;				
				staffinfo[theid][5] = false;				
			}			
		}else{
			if (opacity >= 0) {
				setOpacity(obj, opacity);
				opacity -= 5;
				isIn = 0;
				window.setTimeout("fadeIn('"+outerId+"','"+innerId+"',"+opacity+","+isIn+","+theid+", "+igoredefault+")", nextfade);
			}else{
				opacity += 5;
				isIn = 1;
				staffinfo[theid][4] = true;
				if (staffinfo[theid][5]){
					staffinfo[theid][5] = false;
					staffinfo[theid][4] = false;
					nextfade = 1;
					window.setTimeout("fadeIn('"+outerId+"','"+innerId+"',"+opacity+","+isIn+", "+theid+", "+igoredefault+")", nextfade);
				}
			}
		}
		//window.setTimeout("fadeIn('"+outerId+"','"+innerId+"',"+opacity+","+isIn+")", nextfade);
	  }
	}
}

function changeimg(objId, objId1, theid, isIn){
	obj = document.getElementById(objId);
	obj1 = document.getElementById(objId1);
	if (isIn){
		newinner = obj1.src;
		skipid = newinner.substr(newinner.lastIndexOf('/')+1,1);
		newouter = thumbsrc[theid]+ranNumber(theid, skipid)+".jpg";
		
	}else{
		newouter = obj.style.backgroundImage;
		newouter = newouter.replace(')', '');
		newouter = newouter.substring(4);
		skipid = newouter.substr(newouter.lastIndexOf('/')+1,1);
		newinner = thumbsrc[theid]+ranNumber(theid, skipid)+".jpg";
		
	}
	
	obj.style.background="url("+newouter+")";
	obj1.src=newinner;
	
}

function ranNumber(theid, skipid){
	ran_number = -1;
	do{
		ran_unrounded=Math.random()*totalCnt[theid];
		ran_number=Math.floor(ran_unrounded);
		ran_number++;
	}while(ran_number == skipid);
	return ran_number;	
}

function goloop(){
	/*changeimg('fade1_outer', 'fade1_inner', 1, 0);
	changeimg('fade2_outer', 'fade2_inner', 2, 0);
//	changeimg('fade3_outer', 'fade3_inner', 3, 0);
	changeimg('fade1_outer', 'fade1_inner', 1, 1);
	changeimg('fade2_outer', 'fade2_inner', 2, 1);
	//changeimg('fade3_outer', 'fade3_inner', 3, 1);
	fadeIn('fade1_outer', 'fade1_inner',1,100,0);
	window.setTimeout("fadeIn('fade2_outer', 'fade2_inner',2,100,0);", 5000);
	//window.setTimeout("fadeIn('fade3_outer', 'fade3_inner',3,100,0);", 10000);*/
}

function swapimg(theid, isIn){
	
}
