$(document).ready(function(){
$("#webcam").appendTo($("#jwebcam"));});

  self.name = "mxHome10__1__30__81";
	var hostname;
	var url_regexpr= /(\w+):\/\/([^\/]+)\/(\S*)/;
	var result = document.URL.match(url_regexpr);
	if (result != null)
		hostname = result[2];
	else
		hostname = "";
	document.write('<TITLE>' + hostname + '  <\/TITLE>');

var filesystem__version="M10-V2.0.5.5";
	var homepage__language="en";
	var windowname_home="mxHome10__1__30__81";
	var windowname_ext ="mxExtern10__1__30__81";
	var windowname_help="mxHelp10__1__30__81";
	var windowname_info="mxInfo10__1__30__81";
	function openExtNoDeko(path,winname) {
		if ( path.search(/^!/) >= 0 ) {
			path=path.replace(/^!/,"");
			path=path+"?cachedummy="+Math.floor(Math.random()*1000000);
		}
		return window.open(path,winname,"scrollbars=yes,resizable=yes,width=722");
	}

	function goUserlevel()
	{
		if (self.name == windowname_ext)
		{
			if (window.opener==null || window.opener.closed)
			// Kein Opener oder bereits geschlossen
		  	window.open("http://byronbellavista.dyndns.org:8001/control/userimage.html",windowname_home);
			else
				window.opener.focus();
	   	self.window.close();
			return;
		}
		location.href="/control/userimage.html";
	}
	function getTextFensterX(breite) {
		var wString=",width="+breite;
		if (window.screenLeft)
			wString+=",left="+parseInt(screenLeft+document.body.offsetWidth/2-breite/2);
		else if (window.screenX)
			wString+=",screenX="+parseInt(screenX+outerWidth/2-breite/2);
		return wString;
	}
	function getTextFensterY(hoehe) {
		var wString=",height="+hoehe;
		if (window.screenTop)
			wString+=",top="+parseInt(screenTop+document.body.offsetHeight/2-hoehe/2);
		else if (window.screenY)
			wString+=",screenY="+parseInt(screenY+innerHeight/2-hoehe/2);
		return wString;
	}

	function open_camerainfo(prefix,evt) {
		var text="";
		if ( evt
				&& ( evt.shiftKey || evt.altKey || evt.CtrlKey ) ) {
			text="&text";
		}
		if (typeof prefix == "undefined")
			var prefix="";
		var wdh=window.open(prefix+"/control/camerainfo?rand="+Math.random()+text, windowname_info,
			"width=370,height=320,scrollbars=yes,resizable=yes");
		if (wdh) wdh.focus();
	}
function debugmsg(k) {};

			var pic_url="http://byronbellavista.dyndns.org:8001/record/current.jpg";
			var noframepath="http://byronbellavista.dyndns.org:8001/decor/m1m-error.jpg";
			var n=Math.floor(Math.random()*1000000);
			var session_id=Math.floor(Math.random()*1000000);
			var startn=n;
			var GetItOn=1;
			var framerate=0.1;
			var buffer= new Image();
			var aktiv=null;
			var db_enabled=0;
			var passiv=null;

  function DoComplete()
  {
		//debugmsg("DoComplete() buffer.src="+buffer.src);
		if (db_enabled != 0) {
			if (db_enabled<0) {
				//document.CamPic.style.filter="";buffer.style.filter="alpha(opacity=70,style=0)";
				document.CamPic.style.display="";
				buffer.style.display="none";
			} else {
				//document.CamPic.style.filter="alpha(opacity=70,style=0)";buffer.style.filter="";
				buffer.style.display="";
				document.CamPic.style.display="none";
			}
			db_enabled*=-1;
		} else {
	  	document.CamPic.src = buffer.src;
		}
 		GetItOn = 1;
		if (current_refresh_method_nr == 1 && framerate>0) {// Sync onload implementieren
			if (passiv==null)
				Animation();
			else 
				// Moz. ruft manchmal LoadError und DoComplete kurz hintereinander auf
				debugmsg("timer for Animation() already started...");
		}
  }
	function LoadError()
	{
		debugmsg("LoadError:#"+(n-1)+"  db:"+db_enabled);
		if (db_enabled != 0) {
			db_enabled*=-1;			
		} else {
			document.CamPic.src=noframepath;
		}
		GetItOn = 1;
		if (current_refresh_method_nr == 1 && framerate>0) // Sync onload Fehlerbehandlung
			passiv=setTimeout("passiv=null;Animation();",1000);
	}

  function setframerate() {
		framerate=getframerate();
		debugmsg("setframerate: aktiv="+aktiv+" rm="+current_refresh_method_nr+" fps="+framerate);
 		if (aktiv) {
			window.clearInterval(aktiv);
			aktiv = null;
		}
		document.CamPic.onerror=null;
		buffer.onerror=null;
		if (framerate<0) {
			if (current_refresh_method_nr == 0.1) { //  Stream ausschalten
				GetItOn=1; Animation();
			}
			return;
		}
		// Refresh Typen
		if (current_refresh_method_nr == 2) { //  Stream anschalten
			buffer.onload = null;
			buffer.onerror= null;
			document.CamPic.onload=null;
			// wg. Mozilla Bug # 42224 "Spontaner Abbruch des Streams"
			document.CamPic.onerror= function () {setTimeout("setframerate();",500) } ;
			document.CamPic.src = "http://byronbellavista.dyndns.org:8001/cgi-bin/faststream.jpg?stream=full&fps="+framerate+"&rand=" + String(n++);
			return;
		} else if (current_refresh_method_nr == 1) { // OnLoad synced
			session_id++;
			Animation();
			return;
		}
		aktiv=window.setInterval("Animation()",1000/framerate);
		GetItOn=1;	// auf alle Faelle anzeigen!
		Animation(); // und go...
	}
  function Animation()
  {
		var my_rm_nr=current_refresh_method_nr;
		var my_fr=framerate;
		var my_session=session_id;
		
	  if (GetItOn == 1 || (my_rm_nr == 1 && my_fr>0))
		 	// Bild ist geladen und das naechste kann 
	  {	// angefordert werden.
			GetItOn = 0;
			//debugmsg("Animate:#"+n+" aktiv="+aktiv+" db:"+db_enabled);
			if (db_enabled<0) {
				buffer.onerror=buffer.onload=null;
				document.CamPic.onerror= LoadError;
				document.CamPic.onload = DoComplete;
				if (my_rm_nr == 0)
					document.CamPic.src = pic_url + "?rand=" + String(n++);
				else					
					document.CamPic.src = pic_url + "?sync="+my_fr+"&session="+my_session+"&rand="+String(n++);
			} else {
				document.CamPic.onerror=document.CamPic.onload=null
				buffer.onerror= LoadError;
				buffer.onload = DoComplete;
				if (my_rm_nr == 0)
					buffer.src = pic_url + "?rand=" + String(n++);
				else
					buffer.src = pic_url + "?sync="+my_fr+"&session="+my_session+"&rand="+String(n++);
			}
		}
  }
  function animation_init() {
		if ( document.all 
				&& (navigator.platform.substr(0,3) != "Mac")
				&& (document.CamPic.inserAdjacentHTML)
				 ) {
			document.CamPic.insertAdjacentHTML("AfterEnd","<img border=0 style=\"display:none;\" name=dbbuffer><\/b>");
			buffer=document.dbbuffer;
			db_enabled=1;
		}
		setframerate();
	}

	var filesystem__version="M10-V2.0.5.5";
	var homepage__language="en";
	var windowname_home="mxHome10__1__30__81";
	var windowname_ext ="mxExtern10__1__30__81";
	var windowname_help="mxHelp10__1__30__81";
	var windowname_info="mxInfo10__1__30__81";
	function openExtNoDeko(path,winname) {
		if ( path.search(/^!/) >= 0 ) {
			path=path.replace(/^!/,"");
			path=path+"?cachedummy="+Math.floor(Math.random()*1000000);
		}
		return window.open(path,winname,"scrollbars=yes,resizable=yes,width=722");
	}

	function goUserlevel()
	{
		if (self.name == windowname_ext)
		{
			if (window.opener==null || window.opener.closed)
			// Kein Opener oder bereits geschlossen
		  	window.open("/control/userimage.html",windowname_home);
			else
				window.opener.focus();
	   	self.window.close();
			return;
		}
		location.href="/control/userimage.html";
	}
	function getTextFensterX(breite) {
		var wString=",width="+breite;
		if (window.screenLeft)
			wString+=",left="+parseInt(screenLeft+document.body.offsetWidth/2-breite/2);
		else if (window.screenX)
			wString+=",screenX="+parseInt(screenX+outerWidth/2-breite/2);
		return wString;
	}
	function getTextFensterY(hoehe) {
		var wString=",height="+hoehe;
		if (window.screenTop)
			wString+=",top="+parseInt(screenTop+document.body.offsetHeight/2-hoehe/2);
		else if (window.screenY)
			wString+=",screenY="+parseInt(screenY+innerHeight/2-hoehe/2);
		return wString;
	}

	function open_camerainfo(prefix,evt) {
		var text="";
		if ( evt
				&& ( evt.shiftKey || evt.altKey || evt.CtrlKey ) ) {
			text="&text";
		}
		if (typeof prefix == "undefined")
			var prefix="http://byronbellavista.dyndns.org:8001";
		var wdh=window.open(prefix+"/control/camerainfo?rand="+Math.random()+text, windowname_info,
			"width=370,height=320,scrollbars=yes,resizable=yes");
		if (wdh) wdh.focus();
	}
function debugmsg(k) {};
