var div;
function successHandler(o) {
    var root = o.responseXML;
	var oCondition = root.getElementsByTagName("condition")[0];
	var tempHTML;
	if(oCondition == null){
		 oCondition = root.getElementsByTagName('yweather:condition').item(0);
    }
    var d = new Date();
    var dayNight;
    var curr_hour = d.getHours();
    dayNight = (curr_hour >= 17) ? "n" : "d";

    var oImage = '/images/weather/sm/' + oCondition.getAttribute('code') + dayNight + '.png';
	var oLink = root.getElementsByTagName('link')[0].firstChild.nodeValue;
	var fontSize = (oCondition.getAttribute('text').length > 20) ? "10px" : "12px";
	div = document.getElementById('weatherModule0');
	tempHTML = '<div style="position:relative; height:65px; background-image:url(' + oImage + '); background-repeat:no-repeat; background-position:0px -5px;">';
 	tempHTML += '<div style="width:100%; position:absolute; top:5px; left:70px; color:#555; font-weight:bold; font-style:italic; font-size:' + fontSize + ';">' + oCondition.getAttribute('temp') + '&deg; F<br/>' + oCondition.getAttribute('text') + '</div>';
 	tempHTML += '<div style="width:100%; position:absolute; top:40px; left:0px;"><a href="javascript:void(0);" onclick="handleLink(\'' + oLink.replace('http://', '') + '\');">Yahoo! Weather Forecast</a></div>';
 	tempHTML += '</div>';
 	if (div) {
 	    div.innerHTML = tempHTML;
 	}
}

function failureHandler(o) {
    if (div) {
        div.innerHTML = o.status + " " + o.statusText;
    }
}

function getModule(br){
    var locZips = ['42066'];
	var entryPoint = '/weather.aspx';
	var queryString = encodeURI('?p=' + locZips[br]);
	var sUrl = entryPoint + queryString;
	var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, { success: successHandler, failure: failureHandler, argument: br});
}
function initWeather() {
	getModule(0);
}
YAHOO.util.Event.addListener(window, "load", initWeather);

