//	+-----------------------------------------------------------------------+
//	|	Name		Rank Show Core											|
//	|	Version		2.2														|
//	|	Author		Chappell Wat											|
//	|	E-Mail		Chappell.Wat@Gmail.com									|
//	|	URL			http://www.QuChao.com/?p=147							|
//	|	Date		11/9/2007												|
//	+-----------------------------------------------------------------------+

//	{{{	Configuration

/**
 *	Request Page URL. 
 *	@default	'http://www.QuChao.com'
 *	@warning	Start with protocol - 'http://'.
 */
var requesturi = 'http://www.kumoo.net';

/**
 *	Rank Type Filter. 
 *	@default	'alexa|googlepr|sogourank|chinarank|competerank'
 *	@warning	Separated with '|'.
 */
var ranktype = 'alexa|googlepr|sogourank|chinarank|competerank';

//	}}}


//	{{{	Core

function rankLauncher() {
	new Ajax.Request('rank.php', {method: 'post', parameters: 'requesturi=' + encodeURI(requesturi) + '&ranktype=' + encodeURI(ranktype), onComplete:showRank });
	function showRank(json) {
		var rank = eval('(' + json.responseText + ')');
		var rankPercent;
		var calcPercent = function (rankValue) {
			var rank = Math.floor(Math.log(rankValue) / Math.log(10));
			rank = (rank > 10) ? 0 : (10 - rank) * 10;
			return (rank > 100) ? 100 : rank;
		}
		for(i in rank) {
			if (rank[i] > 0) {
				switch(i){
					case 'sogourank':rankPercent = rank[i];break;
					case 'googlepr':rankPercent = Math.floor(rank[i] * 10);break;
					case 'alexa':
					case 'chinarank':
					case 'competerank':rankPercent = calcPercent(rank[i]);break;
					default:rankPercent = 0;
				}
			} else {
				rankPercent = 0;
			}
			$(i + 'Value').innerHTML = $(i + 'Value').innerHTML + ': ' + rank[i];
			myJsProgressBarHandler.setPercentage(i, rankPercent);
		}
	}
}
Event.observe(window, 'load', rankLauncher, false);

//	}}}

