function init()
{
	document.getElementById("livestream").style.display = 'block';
	if (document.getElementById("commentEntry")) { document.getElementById("commentEntry").style.display = 'none'; }
//	new showLocalTime("timecontainer", "server-php", 0, "short");
	showCam();
}
function showEntry()
{
	document.getElementById("commentEntry").style.display = 'block';
	document.getElementById("showEntry").innerHTML = '';
}

/*
function startTime()
{
	this.container = document.getElementById("timecontainer");
	var servertimestring = '<?php print date("F d, Y H:i:s", time()); ?>';
	this.localtime = this.serverdate = new Date(servertimestring);
alert(localtime);
	var h = this.localtime.getHours();
	var m = this.localtime.getMinutes();
	var s = this.localtime.getSeconds();
	document.getElementById("timecontainer").innerHTML = h + m + s;
//	setTimeout('startTime()',1000);
}
*/

/***********************************************
* Local Time script- © Dynamic Drive (http://www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/
var weekdaystxt=["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
var monthstxt=["January","February","March","April","May","June","July","August","September","October","November","December"];

function showLocalTime(container, servermode, offsetMinutes, displayversion){
if (!document.getElementById || !document.getElementById(container)) return
this.container=document.getElementById(container)
this.displayversion=displayversion
var servertimestring=(servermode=="server-php")? '<? print date("F d, Y H:i:s", time())?>' : (servermode=="server-ssi")? '<!--#config timefmt="%B %d, %Y %H:%M:%S"--><!--#echo var="DATE_LOCAL" -->' : '<%= Now() %>'
this.localtime=this.serverdate=new Date(servertimestring)
this.localtime.setTime(this.serverdate.getTime()+offsetMinutes*60*1000) //add user offset to server time
this.updateTime()
this.updateContainer()
}

showLocalTime.prototype.updateTime=function(){
var thisobj=this
this.localtime.setSeconds(this.localtime.getSeconds()+1)
setTimeout(function(){thisobj.updateTime()}, 1000) //update time every second
}

showLocalTime.prototype.updateContainer=function(){
var thisobj=this
if (this.displayversion=="long")
this.container.innerHTML=this.localtime.toLocaleString()
else{
var lmonth=this.localtime.getMonth()
var lday=this.localtime.getDate()
var lyear=this.localtime.getFullYear()
var hour=this.localtime.getHours()
var minutes=this.localtime.getMinutes()
var seconds=this.localtime.getSeconds()
var ampm=(hour>=12)? "PM" : "AM"
var dayofweek=weekdaystxt[this.localtime.getDay()]
var monthofyear=monthstxt[lmonth]
//this.container.innerHTML=dayofweek+', '+monthofyear+' '+lday+', '+lyear+' at '+formatField(hour, 1)+":"+formatField(minutes)+":"+formatField(seconds)+" "+ampm
this.container.innerHTML=dayofweek+', '+monthofyear+' '+lday+', '+lyear+' at '+formatField(hour, 1)+":"+formatField(minutes)+" "+ampm
}
setTimeout(function(){thisobj.updateContainer()}, 1000) //update container every second
}

function formatField(num, isHour){
if (typeof isHour!="undefined"){ //if this is the hour field
var hour=(num>12)? num-12 : num
return (hour==0)? 12 : hour
}
return (num<=9)? "0"+num : num//if this is minute or sec field
}

function showCam(url)
{
//alert(BaseURL);
var ipaddr = document.getElementById("ipaddr").value;
	// Set the BaseURL to the URL of your camera
	if (url)
	{
		var BaseURL = "http://" + url + "/";
	}
	else
	{
		var BaseURL = "http://" + ipaddr + "/";
	}
	
	// DisplayWidth & DisplayHeight specifies the displayed width & height of the image.
	// You may change these numbers, the effect will be a stretched or a shrunk image
//	var DisplayWidth = "480";
//	var DisplayHeight = "360";
	var DisplayWidth = "640";
	var DisplayHeight = "480";
	
	// This is the path to the image generating file inside the camera itself
	var File = "axis-cgi/mjpg/video.cgi?resolution=" + DisplayWidth + "x" + DisplayHeight;
	// No changes required below this point
	var output = "";
	if ((navigator.appName == "Microsoft Internet Explorer") &&
		 (navigator.platform != "MacPPC") && (navigator.platform != "Mac68k"))
	{
		// If Internet Explorer under Windows then use ActiveX 
		output  = '<object id="Player" width='
		output += DisplayWidth;
		output += ' height=';
		output += DisplayHeight;
		output += ' classid="CLSID:DE625294-70E6-45ED-B895-CFFA13AEB044" ';
		output += 'CODEBASE="';
		output += BaseURL;
		output += 'activex/AMC.cab#version=4,1,5,5">';
		output += '<PARAM NAME="MediaURL" VALUE="';
		output += BaseURL;
		output += File + '">';
		output += '<param name="MediaType" value="mjpeg-unicast">';
		output += '<param name="ShowStatusBar" value="0">';
		output += '<param name="ShowToolbar" value="0">';
		output += '<param name="AutoStart" value="1">';
		output += '<param name="StretchToFit" value="1">';
		output += '<br><b>Axis Media Control</b><br>';
		output += 'The AXIS Media Control, which enables you ';
		output += 'to view live image streams in Microsoft Internet';
		output += ' Explorer, could not be registered on your computer.';
		output += '<br></object>';
	} else {
		// If not IE for Windows use the browser itself to display
		theDate = new Date();
		output  = '<img src="';
		output += BaseURL;
		output += File;
		output += '&dummy=' + theDate.getTime().toString(10);
		output += '" height="';
		output += DisplayHeight;
		output += '" width="';
		output += DisplayWidth;
		output += '" alt="Camera Image">';
	}
	document.getElementById("cam").innerHTML = output;
}
//document.write(output);
//document.Player.ToolbarConfiguration = "play,+snapshot,+fullscreen"

// Remove the // below to use the code for Motion Detection. 
  // document.Player.UIMode = "MDConfig";
  // document.Player.MotionConfigURL = "/axis-cgi/operator/param.cgi?ImageSource=0"
  // document.Player.MotionDataURL = "/axis-cgi/motion/motiondata.cgi";
