require(['scripts/knockout-3.3.0', 'scripts/act', 'scripts/LogWebObject'], function(ko, ACTSocket, LogWebObject) {	

		//var Log = new ACTSocket("Log");
		//Log.onopen = function () {
		//	obj = new LogWebObject("All", "");
		//    Log.send(obj);
		//}
			
        $(document).ready(function () {
			$( "#cleanLog" ).click(function(event) {
				obj = new LogWebObject("Clear", "");
			    ACTSocket.send("Log", obj);
				event.stopPropagation();
			});
			
			setInterval(function(){myTimer()},1000);
			
        });
		
		var processing = false;
		
		function onMessage(cmd) {
		    processing = true;
		    var msg = cmd.Content;
            if (cmd.Command=="Clear") {
				$("#log_content").html("");
            }
			if (msg!="") {
				var $target = $("#log_content");
				$target.append(msg);
				$target.animate({scrollTop: $target[0].scrollHeight}, 500);
			}
			processing = false;
		}

		function myTimer() {
			if (processing) {
				return;
			}
			processing = true;
			obj = new LogWebObject("Get", "");
			ACTSocket.send("Log", obj);
		}
		
		ACTSocket.registerService("Log", onMessage);
        
		
});