function $_(id){
	return document.getElementById(id);
}
document.write('<span id="showControl"  style="background-color:white;position:absolute;left:0px;top:0px;z-Index:10000"></span>')
function show(obj,cmd){
	str = '';
	for(key in obj){
		try{
			str += '&nbsp;&nbsp;&nbsp;&nbsp;<b>'+key+'</b>='+(obj[key]&&obj[key][cmd] ? obj[key][cmd]:obj[key])+'<br>';
		}catch(e){}
	}
	$_('showControl').innerHTML = str!=''? str:'<b>EMPTY</b>';
	$_('showControl').onclick = function(){this.innerHTML = ''}
}
function printArray(arr){
	$_('showControl').innerHTML = '<pre>' + print_r(arr, true);
}
function print_r( array, return_val ) {
	var output = "", pad_char = " ", pad_val = 4;
	var formatArray = function (obj, cur_depth, pad_val, pad_char) {
		if (cur_depth > 0) {
			cur_depth++;
		}
		var base_pad = repeat_char(pad_val*cur_depth, pad_char);
		var thick_pad = repeat_char(pad_val*(cur_depth+1), pad_char);
		var str = "";
		if (obj instanceof Array || obj instanceof Object) {
			str += "Array\n" + base_pad + "(\n";
			for (var key in obj) {
				//if (obj[key] instanceof Array) {
					str += thick_pad + "["+key+"] => "+formatArray(obj[key], cur_depth+1, pad_val, pad_char) + '<br>';
				//} else {
				//	str += thick_pad + "["+key+"] => " + obj[key] + "\n";
				//}
			}
			str += base_pad + ")\n";
		} else {
			if(obj && obj.toString){
				str = obj.toString();
			}
		}
		return str;
	};
	var repeat_char = function (len, pad_char) {
		var str = "";
		for(var i=0; i < len; i++) { 
			str += pad_char; 
		};
		return str;
	};
	output = formatArray(array, 0, pad_val, pad_char);
	if (return_val !== true) {
		document.write("<pre>" + output + "</pre>");
		return true;
	} else {
		return output;
	}
}






Function.prototype.rcBind = function(obj)
{
	var m = this;
	var a = arguments.length>1 ? arguments[1] : {};
	return function(e)
	{
		if(arguments.length)
		{
			if(arguments[0].srcElement || arguments[0].target)
			{
				a['oEvent'] = arguments[0];
			}
			else
			{
				for(var key in arguments[0])
				{
					a[key] = arguments[0][key];
				}
			}
			
		}
		return m.call(obj, a);
	}
}

if(!window['RCShell'])
{
	window['RCShell'] = new Function();
	window['RCShell'].prototype.$_ = function(id)
	{
		return document.getElementById(id);
	}
}
else
{
	throw new Error("Init RCShell Variable.\nPlease don't use variable RCShell");
}



(
	function()
	{
		var $_ = RCShell.prototype.$_;
		
		
		
		RCShell.prototype.RcRssControler = new function()
		{
			this._templates = [];
			this.feed       = '';
			var callBack    = 'RCShell.prototype.RcRssControler.callBack';
			var path        = 'http://www.google.com/uds/Gfeeds';
			var tail        = 'hl=en&output=json&key=internal-sample&v=1.0&q='; 
			
			
			this.setFeed = function(hash)
			{
				if(typeof hash.url == 'string')
				{
					var url = hash.url.replace(/\?/g,'%3F').replace(/&/g,'%26').replace(/\//g,'%2F').replace(/:/g,'%3A').replace(/\+/g,'%2B').replace(/\+/g,'%2B').replace(/=/g,'%3D');
				}
				else
				{
					throw new Error("RcRssControler::setField.\nUrl udefined or not string.");
				}
				
				if(typeof hash.template_id != 'string')
				{
					throw new Error("RcRssControler::setField.\nTemplate_id udefined or not string.");
				} 
				
				
				if($_(hash.template_id))
				{
					var template = hash.template_id;
				}
				else
				{
					throw new Error("RcRssControler::setField.\nNode with id = '" + hash.template_id + "' not found.");
				}
				this._templates.push({ template : template, parent : $_(hash.template_id)});
				var ind =  this._templates.length-1;
				
				var dinCallBack = callBack + '_' + ind;
				this[dinCallBack.replace(/^.*\./,'')] = dinamycCallBack.rcBind(this, { index : ind});
				
				var fillUrl = path + '?callback=' + dinCallBack  + '&' + tail + url;
				
				document.write('<script type="text/javascript" src="' + fillUrl + '"></script>');
			}
			
			
			function dinamycCallBack(hash)
			{
				if(this._templates[hash.index] && (hash.responseStatus == 200 || hash.responseStatus == '200') && hash.responseData && hash.responseData.feed)
				{
					var template = this._templates[hash.index].template;
					var parent   = this._templates[hash.index].parent; 
					
					
					var result = '';
					try
					{
						var result = TrimPath.processDOMTemplate(template, hash.responseData.feed, {throwExceptions : true});
						
					}
					catch(e)
					{
						if(location.hash.match(/debug/))
						{
							result = e.message;
						}
					}
					parent.innerHTML = result;
					parent.style.visibility = 'visible';
				}
			}
			
			
			
			
			
			
			
		}
		
	}
)();



//window.onload = function()
//{
	
//}




