/* Activate proxy for cross-domain request */
WA.Proxy("WebApp/Proxies/ProxyJSON.php");

/* Twitter stuff */

function twitterTrends(o) {
	if (!o) {
		WA.Request("http://search.twitter.com/trends.json", null, twitterTrends, true);
		return;
	}
	
	if (!(o = o.responseJSON))
		return;

	$('twButton').style.display = "none";
	
	var h3 = $('twResult').getElementsByTagName("h3")[0];
	var ul = $('twResult').getElementsByTagName("ul")[0];
	
	h3.innerHTML = o.trends.length + " trends found";

	for (var n = 0; n < o.trends.length; n++) {
		var li = document.createElement('li');
		var lk = document.createElement('a');
		
		lk.href = o.trends[n].url;
		lk.target = "_blank";
		lk.innerHTML = o.trends[n].name;
		li.appendChild(lk);
		ul.appendChild(li);
	}
}

function $(s) {
	return document.getElementById(s);
}


/* Register the handler which will change the header color */

WA.AddEventListener("beginasync", function(evt) {
	/*	Have to put this here for now because it is handled only
		for async content and just before the content is added to the document */
	WA.Progressive(evt.context[0].indexOf("_Images") != -1);
});

WA.AddEventListener("beginslide", function(evt) {
	/* Enable progressive images loading */
	WA.Progressive(evt.context[1][0] == "waImages");

	if (evt.context[1][0] == "waAdapt") {
		document.getElementById('iHeader').style.backgroundColor = "#A95900";	// Changed to grey
//		with (document.wan.header)
//			WA.Header(1, 'tab1', [BACK, TITLE]);
	} else if (evt.context[1][0] == "waTwitter") {
		document.getElementById('WebApp').style.backgroundColor = "#efefef";
		document.getElementById('iHeader').style.backgroundColor = "#bf1238";
	} else {
		document.getElementById('WebApp').style.backgroundColor = "";
		document.getElementById('iHeader').style.backgroundColor = "";	// Restore CSS color
	}

});


