var targetUrl = '';

// Layout
function eLayout() {
	var layout;
	targetUrl = 'http://www.sitestimator.com/estimate/site?domain=' + unescape(document.domain);
	
	// Background
	layout = unescape('<div id="eWidget" style="position:relative;left:0px;top:0px;width:110px;height:55px;z-index:1;border: 1px solid #8ea9ba;background: url(http://www.sitestimator.com/images/sitestimator-bg.gif) repeat-y;overflow: hidden; cursor:pointer;" onclick = "eGoto()">');
	// My site worths
	layout+= unescape('<div id="eMyWorth" style="position:absolute;left:0px;top:4px; width:110px; z-index:1; font: bold 10px Verdana, Tahoma; text-align: center; color: #000000;">My site worths</div>');
	// Worth value
	layout+= unescape('<div id="eSiteValue" style="position:absolute;left:0px; top:18px; width:110px; z-index:1; font:Bold 11px Verdana, Tahoma; color: #ff8c00; text-align: center;">loading...</div>');
	// Logo
	//layout+= unescape('<div id="eLogo" style="position:absolute;left:15px;top:35px;width:84px;height:18px;z-index:1;"><img src="http://www.sitestimator.com/images/sitestimator-logo.gif" alt="www.sitestimator.com" width="84" height="18" /></div></div>');
	layout+= unescape('<div id="eLogo" style="position:absolute; left:0px; top:30px; width:110px; z-index:1; font: 9px Verdana, Tahoma; color: #000000; text-align: center;">How much is yours?</div></div>');
	// Draw the script that load value
	// layout+= unescape('<script type="text/javascript" src="http://www.sitestimator.com/sitevalue.js?domain='+ document.domain +'"></script>');
	// Draw the layout
	document.write(unescape(layout));
	// Find if cookie is exist
	value = checkCookie();
	if (value != null) {
		var div = document.getElementById("eSiteValue");
		div.innerHTML = value;
	}
}

function eGoto() {
	window.location = targetUrl;
}

function getCookie (name) {
	if (document.cookie.length > 0) {
		c_start = document.cookie.indexOf (name + "=")
		if (c_start != -1) { 
			c_start = c_start + name.length + 1;
			c_end = document.cookie.indexOf (";", c_start)
			if (c_end == -1) c_end = document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end))
		} 
	}
	return "";
}

function checkCookie () {
	value = getCookie(document.domain);
	returnValue = null;
	if (value != null && value != "") {
		tempValue = value.split(";");
		returnValue = tempValue[0];
		targetUrl = tempValue[6];
	} else {
		var layout = unescape('<script type="text/javascript" src="http://www.sitestimator.com/sitevalue.js?domain='+ document.domain +'"></script>');
		document.write(unescape(layout));
		returnValue = null;
	}
	return returnValue;
}

// Draw the layout
eLayout ();