var remote;
 
function checkId()
{
	task = setTimeout("checkId()", 2000);
	remote.getUser(siqur_hash, function(data){
		//console.info("checking action to perform:");
		if (data != null)
		{
			//console.info("performing action: "+data["action"]);
			switch (data["action"])
			{
				case "login":
				{
					clearTimeout(task);
					login(data["params"]["user_name"],data["params"]["token"]);
					break; 
				}
				case "logout":
				{
					clearTimeout(task);
					logout();
					break; 
				}				
			}
		}
	}
	);
}		
		
window.onload = function(){
     
	var host = 'accounts.siqur.com';
	
	if(typeof(safetivity_app) != "undefined")
	{
		if(safetivity_app == "siqur"){
			host = 'accounts.siqur.com';
		}
		//host = safetivity_app + '.' + host;
	}
	/**
	 * When the window is finished loading start setting up the channel
	 */
	remote = new easyXDM.Interface(/** The channel configuration */{
		/**
		 * Register the url to hash.html, this must be an absolute path
		 * or a path relative to the root.
		 * @field
		 */
		local: "/hash.html",
		/**
		 * Register the url to the remote interface
		 * @field
		 */
		remote: "http://"+host+"/siqur-mini-login?token="+siqur_hash,
		/**
		 * Register the DOMElement that the generated IFrame should be inserted into
		 */
		container: document.getElementById("login")
	}, /** The interface configuration */ {
		remote: {
				getUser: {}
			}
	},/**The onReady handler*/ function(){
	checkId();
	});
	
}