

var client = null;

if ("WebSocket" in window) {
		document.write("<script type=\"text/javascript\" src=\"mqttws.js\"></script>");
		setTimeout(function() {
			console.log("loading mqttws.js");
			var host = location.hostname;
			var port = 8181;
			client = new MQTT.Client(host,port,"web");
			if (client != undefined) {
				client.setMessageArrivedCallback(onMessage);
				var conOpts = new MQTT.ConnectOptions();
				conOpts.setKeepAliveInterval(15);
				conOpts.setPurge(true);
				conOpts.setDisconnectExisting(true);
				client.connect(conOpts);
				client.subscribe("#",onMessage);
			}
		}, 1000);
	} else {
		var appletTag = "<object classid=\"clsid:CAFEEFAC-0015-0000-0000-ABCDEFFEDCBA\" width=\"3px\" height=\"3px\">" +
						"    <param name=\"code\" value=\"com.ibm.hardillb.dashboard.applets.MQTTBridge.class\">" +
						"    <param name=\"mayscript\" value=\"true\"/>" +
						"    <param name=\"archive\" value=\"../wmqtt.jar\" />" +
						"    <param name=\"codebase\" value=\"bin/\" />" +
						"    <param name=\"topics\" value=\"#\"/> " +
						"    <comment>" +
						"       <embed code=\"com.ibm.hardillb.dashboard.applets.MQTTBridge.class\"" + 
						"              type=\"application/x-java-applet;version=1.5\"" +
						"              archive=\"../wmqtt.jar\"" +
						"              mayscript=\"true\"" +
						"              codebase=\"bin/\"" +
						"              width=\"3px\"" +
						"              height=\"3px\"" +
						"              topics=\"#\"" +
						"              debug=\"true\">" +
						"            <noembed>No Java Support.</noembed>" +
						"        </embed>" +
						"    </comment>" +
						"</object>";
		document.write(appletTag);
};
