// Start this method at body onInit
function init() {

	window.onresize = repositionMainDiv;

	// If method at parent not available...show button, else, do not show
	if(parent.isHidden == null) {
		document.getElementById("ninoLauncher").style.visibility = "visible";
	} else {
		if(parent.isHidden() == true) {
			document.getElementById("ninoLauncher").style.visibility = "visible";
		} else {
			// Hide buttons if Nino is not hidden
			document.getElementById("ninoLauncher").style.visibility = "hidden";
		}
    }
}

//Redirects to Nino showing current webpage
function launchNino(language) {

	// Only launch if not present
	if(parent.showNinoLang == null) {
		// Producción kukuxumusu
		var currentUrl = location.href;

        // replace kukuxumusu.com with www.kukuxumusu.com

        var safeUrl = currentUrl.replace("http://kukuxumusu.com","http://www.kukuxumusu.com");

        // Producción kukuxumusu

        window.location = "http://www.kukuxumusu.com/mr_testis.html?showUrl="+safeUrl+"&lang="+language;
		
	} else {
		repositionMainDiv();
		// Show nino if parent exists
		parent.showNinoLang(language);
	}
}

function findPosition(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
		return [curleft,curtop];
	}
}

function repositionMainDiv() {
	var positionTop = findPosition(document.getElementById("ninoLauncher"));

	var mainDivWidth = 232; // 238w - 6 de right offset

	var mostRightPart = positionTop[0]+mainDivWidth;

	var windowWidth = document.body.clientWidth;

	var rightOffset = windowWidth - mostRightPart;

	var specialOffset = getSpecialOffsetDependingOnBrowser(); // to make things work
	rightOffset = rightOffset + specialOffset;

	// Update position
	parent.document.getElementById("dd-agent-1").style.right=rightOffset+"px";
	if(parent.isHidden() == false){ // Preguntamos si se tiene que ver, en caso de ser así, lo mostramos ya ubicado
		parent.document.getElementById("dd-agent-1").style.display='inline';
	};
}

function getSpecialOffsetDependingOnBrowser() {

	if(isBrowserIE()) {
		return 3;
	}
	if(isBrowserChrome()) {
		return -4;
	}
	// ff
	return -4;
}

//Browser specific function
function isBrowserIE()
{

	var browser=navigator.appName;

	if(browser=="Microsoft Internet Explorer") {
		return true;
	}
	return false;
}

//Browser specific function
function isBrowserChrome()
{

	var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;

	if(is_chrome) {
		return true;
	}
	return false;
}



