var apiKey = "756b563010dec7e5ed0f94c8defd5795";

var currentJotKey = "";

var applications = null;

function init() {
	var request = new Ajax.Request('/service/'+apiKey+'/applications',
		{
			method:'get',
			onSuccess: receiveApplicationList,
			onFailure: failedRequest
		}
	);
}

function receiveApplicationList(transport) {
	applications = transport.responseText.evalJSON(true);

	var html = "";

	var appcount = applications['total_rows'];
	html += "<table border='0'>";
	for (var idx = 0; idx < appcount; idx++) {
		html += "<tr>";
		html += "<td valign='middle' width='57'>";
		html += "<img src='http://assets.tap4help.com/productimgs/"+applications['rows'][idx]['value']['listingimg'] + "' width='57' height='57'";
		html += "</td>";
		html += "<td valign='top'>";
		html += "<h2><a href='/view/" + applications['rows'][idx]['value']['shortname'] + "'>" + applications['rows'][idx]['value']['name'] + "</a></h2>";	
		html += "<b>$" + applications['rows'][idx]['value']['price'] + "</b><br />";
		html += applications['rows'][idx]['value']['description'].substring(0,300) + "<a href='/view/" + applications['rows'][idx]['value']['_id'] + "'>...</a>";
		html += "</td>";
		html += "</tr>";
	}
	html += "</table>";

	$('applisting').innerHTML = html;
}

function failedRequest(transport) {
	//alert(transport);
	alert('Error loading application data.');
}
