var targetUrl = '';
var worth = '';
var googlePR = '';
var alexaRank = '';
var googleSite = '';
var yahooPage = '';
var msnSite = '';

// Layout
function eLayout() {
	var layout;
	
	targetUrl = 'http://www.sitestimator.com/estimate/site?domain=' + unescape(document.domain);
	
	// header
	layout = unescape('<div id="eWidget" style="position:relative;left:0px;top:0px;width:125px;height:125px;z-index:1;border: 0px;background: url(http://www.sitestimator.com/images/button.gif); overflow: hidden; cursor:pointer;" onclick = "eGoto()">');
	layout += unescape('<div style="position:absolute;left:-187px; top:10px; width:500px; z-index:1; font: 11px Verdana, Tahoma; color: #000; text-align: center;">');
	
	// url
	layout += unescape('<small><strong><div id="eUrl">Loading...</div></strong></small>');
	
	// Worth value
	layout += unescape('<span style="color: #f80;"><div id="eWorth">Worth: </div></span>');
	
	// Page rank value
	layout += unescape('<span style="color: #22f;"><div id="ePageRank">PageRank: </div></span>');
	
	// Alexa value
	layout += unescape('<span style="color: #22f;"><div id="eAlexa">Alexa: </div></span>');
	
	// Google value
	layout += unescape('<span style="color: #22f;"><div id="eGoogle">Google: </div></span>');
	
	// Yahoo value
	layout += unescape('<span style="color: #22f;"><div id="eYahoo">Yahoo: </div></span>');
	
	// MSN value
	layout += unescape('<span style="color: #22f;"><div id="eMSN">MSN: </div></span>');
	
	// footer
	layout += unescape('<strong><small>by<span style="color: #080;"> sitestimator.com</span></strong></small><br />');
	layout += unescape('</div></div>');

	document.write(unescape(layout));
	
	setNull();
	// find if cookie is exist
	value = checkCookie();
	if (value) {
		// assign url
		var div = document.getElementById("eUrl");
		div.innerHTML = unescape(document.domain);
		
		// assign worth value
		div = document.getElementById("eWorth");
		div.innerHTML = unescape("Worth: " + worth);
		
		// assign Page Rank value
		div = document.getElementById("ePageRank");
		div.innerHTML = unescape("PageRank: " + googlePR);

		// assign Alexa value
		div = document.getElementById("eAlexa");
		div.innerHTML = unescape("Alexa: " + alexaRank);

		// assign Google value
		div = document.getElementById("eGoogle");
		div.innerHTML = unescape("Google: " + googleSite);
		
		// assign Yahoo value
		div = document.getElementById("eYahoo");
		div.innerHTML = unescape("Yahoo: " + yahooPage);
		
		// assign MSN value
		div = document.getElementById("eMSN");
		div.innerHTML = unescape("MSN: " + msnSite);
	}
}

function eGoto() {
	window.location = targetUrl;
}

function setNull() {
	worth = '';
	googlePR = '';
	alexaRank = '';
	googleSite = '';
	yahooPage = '';
	msnSite = '';
}

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);
	if (value != null && value != "") {
		tempValue = value.split(";");
		worth = tempValue[0];
		googlePR = tempValue[1];
		alexaRank = tempValue[2];
		googleSite = tempValue[3];
		yahooPage = tempValue[4];
		msnSite = tempValue[5];
		targetUrl = tempValue[6];
		return true;
	} else {
		var layout = unescape('<script type="text/javascript" src="http://www.sitestimator.com/sitevalue.js?domain='+ document.domain +'"></script>');
		document.write(unescape(layout));
		return false;
	}
	return false;
}

// Draw the layout
eLayout ();