var _lastTop = null;
var _items = { "preferences":0,"help":0,"about":0 }

/*
function showButtons(_show) {
	
	var _buttons = {
		'cloud':'',
		'cloud_a':'<span id="toolbar_button_cloud" class="toolbar_button_active">termcloud</span>',
	    'cluster':'',
		'cluster_a':'<span id="toolbar_button_cluster" class="toolbar_button_active">cluster</span>',
		'spacer':'<span class="toolbar_spacer"></span>',
	    'lessterms':'<span class="toolbar_button" onclick="resizeTagcloud(-1)">terms +</span>',
	    'moreterms':'<span class="toolbar_button" onclick="resizeTagcloud(1)">terms -</span>',
		'clusters':''
	}
	
	$("#terms_toolbar").html("");
	
	for(var _key in _show) {
		$("#interface_toolbar").append(_buttons[_show[_key]]);
	}
}
*/

function screenMsgIn(_msg) {
	$("#screenmsg").html(_msg);
	$("#screenmsg").css("display","block");
}

function screenMsgOut(_msg) {
	$("#screenmsg").css("display","none");
}

function removeX(_term) {
	
	_term = _term.substr(1,_term.length - 1);
	
	return _term;
}

function toogleTop(_param) {
	
	_items[_param] = (_items[_param] == 0) ? 1 : 0;
	
	if(_items[_param] == 1) {
		for (var _key in _items) {
			if(_key != _param) {
				_items[_key] = 0;
			}
		}
	}
	
	for(var _key in _items) {
		
		if(_items[_key] == 0) {
			$("#box_"+_key).slideUp();
		} else {
			$("#box_"+_key).slideDown();
		}
		
	}
	
	
	
}

function keySortAlpha(a, b){

	if (a["term"] < b["term"]) {
		return -1;
	} else {
		return 1;
	}
}

function keySortCounter(a, b){

	if (a["counter"] > b["counter"]) {
		return -1;
	} else {
		return 1;
	}
}

function setInterface(_param) {
	
	if(_param == "cloud") {
		$("#box_results").css("margin-top",$("#box_terms").height() + 90);
		$("#box_results").css("margin-left","0px");
		$("#box_results").css("z-index","0");
		$("#box_results").css("width","980px");
		$("#toolbar_button_cloud").removeClass().addClass("toolbar_button_active");
		$("#toolbar_button_cluster").removeClass().addClass("toolbar_button");
		$("#interface_right").css("visibility","hidden");
	}
	
	if(_param == "cluster") {
		$("#box_results").css("margin-top","110px");
		$("#box_results").css("margin-left","240px");
		$("#box_results").css("width","430px");
		$("#box_results").css("z-index","2");
		$("#toolbar_button_cloud").removeClass().addClass("toolbar_button");
		$("#toolbar_button_cluster").removeClass().addClass("toolbar_button_active");
		$("#interface_right").css("visibility","visible");
	}
}

var Utf8 = {
 
	// public method for url encoding
	encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// public method for url decoding
	decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
}

