if (location.search.length > 0) {
	var sch = location.search.substring(1,3); 
	var rla = location.search.substring(3,6);
	var thisLoc = location.href.substring(0,location.href.indexOf('?'));
	switch (sch) {
		case 'bs': thisApp = 'N0R';	ttl = 'Short Range Base Reflectivity';	break
		case 'bl': thisApp = 'N0Z'; 	ttl = 'Long Range Base Reflectivity';	break
		case 'cs': thisApp = 'NCR';	ttl = 'Short Range Composite Reflectivity';	break
		case 'oh': thisApp = 'N1P';	ttl = 'Previous One Hour Total Precipitation';	break
		case 'st': thisApp = 'NTP';	ttl = 'Storm Total Precipitation';	break
		case 'ns': thisApp = '';		ttl = 'Weather Radar Loops';	break
		case 'fc': thisApp = 'AAL';	break
		var sch = 'ns'; var ttl = 'Weather Radar Loops'; var rla = 'GRR'; thisApp = '';
	}
}
else { 
	var thisApp = ''; var rla = 'GRR'; var sch = 'ns';
	var thisLoc = location.href.substring(0,location.href.length);
}
var rlb = ( rla == 'GRR' ? 'DTX' : 'GRR' );	
var rlc = ( rla == 'GRR' ? 'Grand Rapids' : 'Detroit' );	
var rln = ( rla == 'GRR' ? 'Detroit' : 'Grand Rapids' );	

function getContent() {
	doPreview(sch,rla); doRadar(rln);
	if (thisApp != '') doMain(ttl,rlc,rla,sch,thisApp);	
}

function choose(loop) {
	location.replace(thisLoc + ( loop == '' ? '' : '?' + loop + ( loop.length > 2 ? '' : rla ) ) );		
}

function doPreview(sch,rla) {
	pvwImg = ( sch == 'oh' ? 'NCR' : 'N1P' );
	thisImg = 'http://radar.weather.gov/lite/'+ pvwImg +'/'+ rla +'_loop.gif';
	pvwHdg = '<span id="hdg">'+( pvwImg == 'N1P' ? 'Previous One Hour Total Precipitation' : 'Short Range Composite Reflectivity' );
	pvwHdg += '<\/span>' +'\r<br><img src="' + thisImg + '" width=100%>';
	document.getElementById('previewImg').innerHTML = pvwHdg;
}

function doMain(ttl,rlc,rla,sch,thisApp) {
	if (thisApp != 'AAL') {
		output = '<span id="hdg">' + ttl + ' -- from ' + rlc + ' radar station<\/span><br>\r';
		linkURL = 'http:\/\/radar.weather.gov\/radar_lite.php?rid=' + rla + '&product=' + thisApp + '&loop=yes';
		output += '\rSource: <a href="' + linkURL + '">' + linkURL + '<\/a><br>';
		output += '<img src="http://radar.weather.gov/lite/'+ thisApp + '/' + rla + '_loop.gif" width=100%>\r';
		document.getElementById('mainDiv').innerHTML = output;
	}
	else fcFrame.location.replace('http://www.crh.noaa.gov/forecast/MapClick.php?CityName=Ann+Arbor&state=MI&site=DTX');	
	document.getElementById('fcDiv').style.display = ( sch == 'fc' ? 'block' : 'none' );
	document.getElementById('mainDiv').style.display = ( sch == 'fc' ? 'none' : 'block' );
}

function doRadar(rln) {
	var radarBtn = 'Switch to '+ rln +' (R)adar';
	document.getElementById('rl').value = radarBtn;
}

function doit(e) {
	var theKey = String.fromCharCode(e.charCode ? e.charCode : e.keyCode);
	switch (theKey) {
		case 'f': sch = 'fc'; break
		case 'h': sch = 'oh'; break
		case 't': sch = 'st'; break
		case 's': sch = 'bs'; break
		case 'l': sch = 'bl'; break
		case 'c': sch = 'cs'; break
		case 'r': sch = sch + rlb;	break
		case 'x': sch = ''; break
		case 'g': fcFrame.location.replace('http://www.timeanddate.com/weather/usa/ann-arbor');
		return;
	}	
	choose(sch);
}
