function waitUntilGlueInitialized(cb, timeout) {
	if(isGlueInstalled()) {
		var info = getGlueInfo();
		if (info && info.initialized == "true") {
			cb.call(null, info);
			return;
		}
	}
	if (timeout && timeout < 0) {
		cb.call();
		return;
	}
	var freq = 500;
	setTimeout(function() {
		waitUntilGlueInitialized(cb, parseInt(timeout) - freq);
	}, freq);
}

function glueInstalledCheck(cb, timeout){
    if (isGlueInstalled()) {
        cb.call( null, getGlueInfo());
        return;
    }
    if (timeout && timeout < 0) {
        cb.call();
        return;
    }
    var freq = 500;
    setTimeout(function() {
        glueInstalledCheck(cb, parseInt(timeout) - freq);
    }, freq);
}

function getGlueInfo() {
	var info = new Object();
	try {
		$.getScript("glue://info");
	} catch ( e ) {}
	var glueInfo = document.getElementById("glueinfo");
	if (glueInfo) {
		var pairs = glueInfo.firstChild.nodeValue.split(";");
		for(var i = 0; i < pairs.length; i++) {
			var t = pairs[i].split("=");
			info[t[0]] = t[1];
		}
	}
	return info;
}

function getProtocolPath() {
	var s = document.URL;
	var idx = s.indexOf("glue.com/");
	return s.substring(idx + "glue.com/".length);
}

function isGlueInstalled() {
	return document._abGlueInstalled;
}

