LinkOfTheWeek.USER = "a3northcalifornia"
LinkOfTheWeek.TABLE = "linkoftheweek.json";

function LinkOfTheWeek()
{
}

function LinkOfTheWeekAPI(){
	this.getAll = function(callbackMethod) 
	{
		LinkOfTheWeek.callback = callbackMethod;
		// Retrieve the JSON feed.
		var script = document.createElement('script');
		var url = 'http://www.editgrid.com/user/'+LinkOfTheWeek.USER
			+"/"+LinkOfTheWeek.TABLE
			+"?callback=LinkOfTheWeekAPI.getCallback";
		script.setAttribute('src', url );
		
		document.documentElement.firstChild.appendChild(script);
		var ret = new Array();
	}
	
	this.getActiveLinkOfTheWeek = function(callbackMethod) {
		var ret = null;
		callback = function (items) {
			for(var i=0; i<items.length; i++) {
				var item = items[i];
				if ("Y" == item.active.toUpperCase()) {
					ret = item;
					break;
				}
			}
			callbackMethod(ret);
		};
		var items = this.getAll(callback);
	}
}

LinkOfTheWeekAPI.getCallback = function(json) 
{
	var data = onorex.jsonEditGridToData(json.sheet.Sheet1);
	LinkOfTheWeek.callback(data);
}