var download_url = "http://www.wimob.com/install.html";

function findWimob() {
	if ((navigator.userAgent.indexOf('MSIE') != -1)) { 
		var wimob = null;
		try {
			wimob = new ActiveXObject("plWimob.wimob.1");
		} catch(e) {}
		
		if(!wimob) {
			return false;
		} else {
			return true;
		}
	} else {
		if (navigator.plugins && navigator.plugins.length) {
			if(navigator.plugins["Wimob Plugin for Mozilla"]) {
				return true;
			}
		} 
		return false;
	}
}

function sniffWimob(url) {
	if(findWimob()) {
		if((navigator.userAgent.indexOf('MSIE') == -1)) {
			window.location = url;
		} else {
			var layer = document.getElementById('wimoblayer');
			if(!layer) {
				try {
					layer = document.createElement("<div id='wimoblayer'/>");
				} catch(e) {
					layer = document.createElement("div");
					layer.setAttribute("id", "wimoblayer");
				}
				window.document.body.appendChild(layer);
			}
			layer.innerHTML = '<iframe width="0" height="0" src="' + url + '" frameborder="0">';
		}
	} else {
		if((navigator.userAgent.indexOf('MSIE') != -1)) {
			if(confirm("English: Wimob has not been detected on your system. Wimob allows downloading multimedia content from different websites to your mobile phone for free, using Bluetooth, Infrared or USB. If you need to install Wimob, please click on Accept (If you have already installed it, click on Cancel and then click on the above message choosing \"Run ActiveX\").\n\nEspañol: Wimob no ha sido detectado en su sistema. Wimob permite la descarga de contenido multimedia desde páginas web a su teléfono móvil de manera gratuita, usando Bluetooth, Infrarrojos o USB. Si necesita instalar Wimob, por favor haga clic en Aceptar (Si ya lo ha instalado, haga clic en Cancelar y luego en el mensaje arriba en la página escogiendo \"Descargar archivo\").")) {
				openDownloadWindow();
			}
		} else {
			openDownloadWindow();
		}
	}
}

function openDownloadWindow() {
	var win = window.open(download_url, '_blank', '');
	if(win == null) {
		//window.location = download_url;
		window.open(download_url, '_blank', '');
	}
}

function openWimob(groupid, wimobid) {
	sniffWimob("wmbp://www.wimob.com/wimob/WimobWeb.xml?" + groupid + "|" + wimobid);
}

function wimobrun(wimobid)
{
	sniffWimob("wmbp://i|20|" + wimobid + "|");
}

function openWimobURL(url, groupid, wimobid) {
	sniffWimob("wmbp://" + url + "?" + groupid + "|" + wimobid);
}
		
function wimob(url, groupid, wimobid, size, color) {
	if(color < 10) {
		color = "0" + color;
	}
	
	document.write("<img style='cursor:pointer;' onClick=\"javascript:openWimobURL('" + url + "','"  + groupid + "','" + wimobid + "');\" src='http://www.wimob.com/icons/wimob-" + size + "-" + color + ".gif' alt='Wimob - Web to Mobile Content' title='Wimob - Web to Mobile Content'/>");
}