var wcurrentPhoto = 0;
var wsecondPhoto = 1;
var wtempPhoto = 1;
var webcamimg = "http://ian-hawkins.com/webcamimage.php?";
var wcurrentOpacity = new Array();
var pausew = false;
var loadCount = 1;
var wcit = 100;
var webInterval;
var mwInterval;
var i = 0;
var webcInterval;

function init_webcamThumb() {
      webcInterval = setInterval("init_webcamThumbDelayed()",8000);
}

function init_webcamThumbDelayed() {
   if (webcInterval) { clearInterval(webcInterval); }
	wcurrentOpacity[0]=100;
	for(i=1;i<2;i++)wcurrentOpacity[i]=0;

   var mHTML="";
	mHTML+="<a href=\"/webcam.php\"><div style=\"top: -0px; z-index: 1;\" id=\"wphoto0\" name=\"wphoto\" class=\"wPhoto\"><img src=\""+webcamimg+"\" id=\"wimage1\" style=\"height:87px;width:107px;\"/></div>";
	mHTML+="<div style=\"top: -120px; z-index: 2;\" id=\"wphoto1\" name=\"wphoto\" class=\"wPhoto\"><img src=\""+webcamimg+"\" id=\"wimage2\" style=\"height:87px;width:107px; top: -87px;\"/></div></a>";
	document.getElementById("webcamImage").innerHTML = mHTML;

	if(document.all) {
		document.getElementById("wphoto"+wcurrentPhoto).style.filter="alpha(opacity=100)";
	} else {
		document.getElementById("wphoto"+wcurrentPhoto).style.MozOpacity = "100%";
	}

	mwInterval = setInterval("crossFadeW()",250);
}

function crossFadeW() {
	if(pausew)return;

	wcurrentOpacity[wcurrentPhoto]-=25;
	wcurrentOpacity[wsecondPhoto] +=25;


	if(document.all) {
		document.getElementById("wphoto"+wcurrentPhoto).style.filter = "alpha(opacity=" + wcurrentOpacity[wcurrentPhoto] + ")";
		document.getElementById("wphoto"+wsecondPhoto).style.filter = "alpha(opacity=" + wcurrentOpacity[wsecondPhoto] + ")";
	} else {
      // Moz
		document.getElementById("wphoto"+wcurrentPhoto).style.MozOpacity = wcurrentOpacity[wcurrentPhoto]/100;
		document.getElementById("wphoto"+wsecondPhoto).style.MozOpacity =  wcurrentOpacity[wsecondPhoto]/100;
      // Konq
      document.getElementById("wphoto"+wcurrentPhoto).style.KHTMLOpacity = wcurrentOpacity[wcurrentPhoto]/100;
      document.getElementById("wphoto"+wsecondPhoto).style.KHTMLOpacity =wcurrentOpacity[wsecondPhoto]/100;
      // Generic
      document.getElementById("wphoto"+wcurrentPhoto).style.opacity = wcurrentOpacity[wcurrentPhoto]/100;
      document.getElementById("wphoto"+wsecondPhoto).style.opacity =wcurrentOpacity[wsecondPhoto]/100;
	}

   
   if(wcurrentOpacity[wcurrentPhoto]<=0) {
      wcit--;
      if (wcit < 1) return;
		wtempPhoto = wcurrentPhoto;
      if (wcurrentPhoto == 0) {
        document.getElementById('wimage1').src= webcamimg + Math.random() * 10000;
      } else {
        document.getElementById('wimage2').src= webcamimg + Math.random() * 10000;
      }
      wcurrentPhoto = wsecondPhoto;
		wsecondPhoto = wtempPhoto;
		pausew = true;
		webInterval = setTimeout("pausew=false",17000);
	}

}
