// mass:werk 2002

var thetick='';
var currentTick=0;
var currentScene=0;
var connectionLength=0;
var theTransRate=0;
var green='#007000';
var months= new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
var weekdays= new Array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');

function getClip() {
	return '<TABLE BORDER="0" CELLSPACING="1" CELLPADDING="1">\n<TR>\n<TD ALIGN="center" BGCOLOR="#333333"><TT>live cam '+theCam+'<\/TT><\/TD>\n<\/TR>\n<TR>\n<TD BGCOLOR="'+green+'"><OBJECT CLASSID="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" WIDTH="160"HEIGHT="144" CODEBASE="http:\/\/www.apple.com\/qtactivex\/qtplugin.cab"><PARAM name="SR'+'C" VALUE="cam/'+theMovie+'"><PARAM name="AUTOPLAY" VALUE="true"><PARAM name="CONTROLLER" VALUE="false"><PARAM name="LOOP" VALUE="true"><EMBED SR'+'C="cam/'+theMovie+'" WIDTH="200" HEIGHT="150" AUTOPLAY="true"\nCONTROLLER="false" LOOP="true" PLUGINSPAGE="http:\/\/www.apple.com\/quicktime\/download\/"><\/EMBED><\/OBJECT><\/TD>\n<\/TR>\n<TR>\n<TD ALIGN="center"><TT>&lt;'+theLoc+'&gt;<\/TT><\/TD>\n<\/TR>\n<\/TABLE>';
}

function getTimeStamp() {
	// trad. GMT timestamp
	var t=new Date();
	return weekdays[t.getUTCDay()]+', '+normalize(t.getUTCDate())+' '+months[t.getUTCMonth()]+' '+t.getUTCFullYear()+' '+normalize(t.getUTCHours())+':'+normalize(t.getUTCMinutes())+':'+normalize(t.getUTCSeconds())+' GMT'
}

function camTrigger() {
	if (currentScene==0) {
		thetick='<TT>&gt; building connection ';
		showDiv('tickdiv',thetick+'<\/TT>');
		currentScene++;
		connectionLength=(Math.random()<theInstabRate)? 35 : 5+Math.random()*27;
		setTimeout('camTrigger()',80)
	}
	else if (currentScene==1) {
		thetick+='.';
		showDiv('tickdiv',thetick+'<\/TT>');
		currentTick++;
		if (currentTick>connectionLength) {
			if (connectionLength==35) {
				showDiv('tickdiv',thetick+'<BR>&gt; connection timed out, can\'t establish link; line might be broken.<BR>&gt; click to retry ...<BR><BR><A HREF="javasc'+'ript:self.location.reload()" onmouseover="window.status=\'reestablish link ...\'; return true" onmouseover="window.status=\'\'; return true">&nbsp;&gt; reconnect to cam #'+theCam+'&nbsp;</A></TT>');
			}
			else {
				currentScene++;
				setTimeout('camTrigger()',500)
			}
		}
		else {
			setTimeout('camTrigger()',500)
		}
	}
	else if (currentScene==2) {
		theTransRate=theTransfer+Math.floor(Math.random()*60)-30;
		thetick+='<BR>&gt; link established '+getTimeStamp()+' at '+theTransRate+' kbs<BR>&gt; displaying live cam (cam #'+theCam+', location: '+theLoc+')<\/TT>';
		showDiv('tickdiv',thetick);
		currentScene++;
		setTimeout('camTrigger()',1000)
	}
	else {
		showDiv('camdiv',getClip());
		currentScene++;
		showTime()
	}
}

function showDiv(d,t) {
	if (document.layers) {
		document.layers[d].document.open();
		document.layers[d].document.write(t);
		document.layers[d].document.close()
	}
	else if (document.getElementById) {
		var obj=document.getElementById(d);
		obj.innerHTML=t
	}
	else if (document.all) {
		document.all[d].innerHTML=t
	}
}

function showTime() {
	var t=new Date();
	showDiv('timediv', '<TT><FONT COLOR="'+green+'">'+normalize(t.getUTCHours())+':'+normalize(t.getUTCMinutes())+':'+normalize(t.getUTCSeconds())+' GMT<\/FONT><\/TT>');
	setTimeout('showTime()',1000)
}

function normalize(x) {
	return (x<10)? '0'+x:x;
}

