jQuery(function(e){function h(){e.ajax({data:"action=getStatus",success:function(j,k){if(j){a=/cam=true/.test(j);i=/motion=true/.test(j);if(a){e("#cam").attr("src","images/camera_unmount.png").parent().attr("title","Camera is connected and mounted");if(i){e("#status").css("background-color","green");e("#motion").attr("src","images/HAL-9000_on.png").parent().attr("title","Motion is running");e("#stopStart").children().attr("src","images/stop.png").parent().attr("title","Stop Motion (as this is a demo, this is not for real)")}else{e("#status").css("background-color","red");e("#motion").attr("src","images/HAL-9000_off.png").parent().attr("title","Motion is NOT running");e("#stopStart").children().attr("src","images/play.png").parent().attr("title","Start Motion (as this is a demo, this is not for real)")}}else{e("#cam").attr("src","images/camera_unmount.png").parent().attr("title","Camera is NOT connected and mounted");e("#status").css("background-color","red");e("#motion").attr("src","images/HAL-9000_off.png").parent().attr("title","Motion is NOT running");e("#stopStart").children().attr("src","images/play.png").parent().attr("title","Start Motion (as this is a demo, this is not for real)")}}},timeout:1000,type:"POST",url:location.pathname})}function d(){e.ajax({data:"action=showLatest",success:function(k,l){if(k){var j=false;f=/latest=([0-9]{14}-[0-9][0-9]\.jpg)&hasPrev=(.+)/.exec(k);latest=f[1];src="photo.php?filename="+f[1];if(f[2]=="true"){j=true}e("#photo").children().remove().end().append('');if(j){e("#prev").children().css("visibility","visible");e("#first").children().css("visibility","visible")}else{e("#prev").children().css("visibility","hidden");e("#first").children().css("visibility","hidden")}e("#delete").children().css("visibility","visible");e("#last").children().css("visibility","hidden");e("#next").children().css("visibility","hidden")}else{e("#delete").children().css("visibility","hidden");e("#first").children().css("visibility","hidden");e("#last").children().css("visibility","hidden");e("#next").children().css("visibility","hidden");e("#photo").children().remove();e("#prev").children().css("visibility","hidden")}},timeout:1000,type:"POST",url:location.pathname})}var f,g,c;var a=true;var i=false;if(e.browser.mozilla){e("#status").css("-moz-border-radius","5px")}else{if(e.browser.safari){e("#status").css("-webkit-border-radius","5px")}}e("#dialog").dialog({autoOpen:false,bgiframe:true,buttons:{OK:function(){e(this).dialog("close")}},modal:true,title:"Error…",width:500});h();d();setInterval(function(){h()},3000);var b=setInterval(function(){d()},3000);e("#delete").children().click(function(){clearInterval(b);f=/photo\.php[?]filename=(.+)$/.exec(e("#photo").children().attr("src"));e.ajax({data:"action=delete&filename="+f[1],success:function(j,k){if(j=="ok"){e("#dialog").html("”"+f[1]+"” has been deleted.").dialog("option","title","Success").dialog("open");d();b=setInterval(function(){d()},3000)}else{e("#dialog").html("Error deleting ”"+f[1]+"”!").dialog("option","title","Error…").dialog("open")}},timeout:1000,type:"POST",url:location.pathname})});e("#first").children().click(function(){clearInterval(b);e.ajax({data:"action=showFirst",success:function(j,k){if(j){e("#photo").children().remove().end().append('');e("#first").children().css("visibility","hidden");e("#last").children().css("visibility","visible");e("#next").children().css("visibility","visible");e("#prev").children().css("visibility","hidden")}else{b=setInterval(function(){d()},3000)}},timeout:1000,type:"POST",url:location.pathname})});e("#last").children().click(function(){clearInterval(b);d();b=setInterval(function(){d()},3000)});e("#next").children().click(function(){clearInterval(b);f=/photo\.php[?]filename=(.+)$/.exec(e("#photo").children().attr("src"));e.ajax({data:"action=showNext&filename="+f[1],success:function(j,k){if(j){f=/^filename=(.+)&hasNext=(.+)$/.exec(j);if(f[2]=="true"){g=true}else{g=false}e("#photo").children().remove().end().append('');if(g){e("#next").children().css("visibility","visible");e("#last").children().css("visibility","visible")}else{e("#next").children().css("visibility","hidden");e("#last").children().css("visibility","hidden")}e("#first").children().css("visibility","visible");e("#prev").children().css("visibility","visible")}else{b=setInterval(function(){d()},3000)}},timeout:1000,type:"POST",url:location.pathname})});e("#prev").children().click(function(){clearInterval(b);var j=/photo\.php[?]filename=(.+)$/.exec(e("#photo").children().attr("src"));e.ajax({data:"action=showPrev&filename="+j[1],success:function(k,l){if(k){j=/^filename=(.+)&hasPrev=(.+)$/.exec(k);if(j[2]=="true"){c=true}else{c=false}e("#photo").children().remove().end().append('');if(c){e("#prev").children().css("visibility","visible");e("#first").children().css("visibility","visible")}else{e("#prev").children().css("visibility","hidden");e("#first").children().css("visibility","hidden")}e("#last").children().css("visibility","visible");e("#next").children().css("visibility","visible")}else{b=setInterval(function(){d()},3000)}},timeout:1000,type:"POST",url:location.pathname})});e("#stopStart").click(function(){if(a){e.ajax({data:"action=toggleMotion",success:function(j,k){if(j=="error"){e("#dialog").dialog("option","title","Error…").html("An error has occurred!").dialog("open")}else{if(j=="started"){clearInterval(b);b=setInterval(function(){d()},3000);e("#status").css("background-color","green");e("#motion").attr("src","images/HAL-9000_on.png").parent().attr("title","Motion is running");e("#stopStart").children().attr("src","images/stop.png").parent().attr("title","Stop Motion");i=true}else{e("#status").css("background-color","red");e("#motion").attr("src","images/HAL-9000_off.png").parent().attr("title","Motion is NOT running");e("#stopStart").children().attr("src","images/play.png").parent().attr("title","Start Motion");i=false}}},timeout:10000,type:"POST",url:location.pathname})}})});