//the actual application
//requires: lib_android.js, webchemy.js


(function() {
	//different versions of webchemy (web, android, ios, etc)
	var port = {};
	port.web = function(p) {//fallback
		
		p.callback({endSplashAnimation: true});
		var wc = new Webchemy({
			port: "WebApp",
			retina: true,
			callback: function(val) {
				if(val.save) {
				}
			}
		});
		
		function localStoragePolling() { //communicate with iframes
			if(localStorage.getItem("triggerBuyProKey") === "true") {
				localStorage.setItem("triggerBuyProKey", "false");
				wc.closeInfoPage();
				
				//alert("BUY!");
				console.log("buy!");
			}
			
			setTimeout(localStoragePolling, 300);
		}
		localStoragePolling();
		return true;
	};
	port.firefoxOS = LIB.firefoxOS.webchemyApp;
	
	
	var runApp = port.firefoxOS;
	var appParams = {
		callback: function(val) {
			if(val.endSplashAnimation) {
				//document.getElementById("loadingDiv").doneLoading = true;
			}
		}
	};
	runApp(appParams);
})(); 

/* //onscreen debug console -> call via window.screenPrint("message");
setTimeout(function() {
	var screenConsole = UI.div({
		parent: document.body,
		innerHTML: "test",
		position: "fixed",
		left: 0,
		top: 0,
		height: "100%",
		width: "100%",
		background: "#000",
		color: "#fff",
		opacity: 0.4,
		zIndex: "999999999",
		pointerEvents: "none"
	});
	var output = [];
	UI.div({
		position: "fixed",
		right: 0,
		bottom: 0,
		background: "#fff",
		color: "#000",
		innerHTML: "[clear]",
		onclick: function() {
			output = [];
			screenConsole.innerHTML = "";
		},
		parent: document.body,
		zIndex: "9999999999"
	});
	function timer() {
		
		screenConsole.innerHTML = "";
		for(var i = output.length - 1; i >= 0; i--) {
			screenConsole.innerHTML += output[i] + "<br>";
		}
		setTimeout(timer, 2000);
	}
	timer();
	window.screenPrint = function(str) {
		while(output.length > 50) {
			output.shift();
		}
		output.push('<span style="font-size: 9px">' + (new Date().getTime() % 100000) + "</span> " + str);
	};
}, 10);
*/