// COLORBOX FOR LOGIN
function loginBox() {    	
  $.fn.colorbox({href:'#loginPopupBackground', inline:true, onComplete: function(){ document.loginForm.loginName.focus();}});
}

// Submit login form for Login Popup
function submitLoginForm() {
	document.loginForm.submit();
	return false;
}

// Press Enter to Submit Form
function enterToSubmitLoginForm() {	
    // look for window.event in case event isn't passed in
	if (window.event) { e = window.event; return false; }
	if (e.keyCode == 13)
	{
		document.loginForm.submit();
		return false;
	}	
}

// Translate this page
function translateThisPage() {
	var theTranslatedPageURL = "http://translate.google.com/translate?js=y&prev=_t&hl=en&ie=UTF-8&layout=1&eotf=1&u="+location.href+"&sl=en&tl=es";
	window.location = ""+theTranslatedPageURL+"";	
};


// WEATHER
var myCityName = ""+geoplugin_city()+", "+geoplugin_region()+"";
if ((myCityName == "") || (myCityName == ", ") || (myCityName == null)) {
	myCityName = "Providence, RI";
}

$.simpleWeather({
		location: ''+myCityName+'',
		//zipcode: '02852',
		unit: 'f',
		success: function(weather) {
				
				// Storm
				if (((weather.code >= 0) && (weather.code <= 4)) || ((weather.code >= 37) && (weather.code <= 39)) || (weather.code == 45) || (weather.code >= 47))  {
					weatherType = "storm";
				}
				// Light Rain
				else if ((weather.code == 10) || (weather.code == 11) || (weather.code == 12) || (weather.code == 13)) {
					weatherType = "lightRain";
				}
				// Heavy Rain
				else if (weather.code == 40) {
					weatherType = "heavyRain";
				}
				// Cloudy
				else if ((weather.code == 20) || (weather.code == 21) || (weather.code == 26) || (weather.code == 44)) {
					weatherType = "cloudy";
				}
				// Mixed or freezing
				else if (((weather.code >= 5) && (weather.code <= 8)) || (weather.code == 10) || (weather.code == 17) || (weather.code == 18) || (weather.code == 35))  {
					weatherType = "mixed";
				}
				// Sunny
				else if ((weather.code == 32) || (weather.code == 36)) {
					weatherType = "sunny";
				}
				// Snow
				else if (((weather.code >= 13) && (weather.code <= 16)) || ((weather.code >= 41) && (weather.code <= 43)) || (weather.code == 46))  {
					weatherType = "snow";
				}
				else if ((weather.code == 23) || (weather.code == 24)) {
					weatherType = "windy";
				}
				else if ((weather.code == 27) || (weather.code == 29)) {
					weatherType = "cloudyNight";
				}
				else if ((weather.code == 28) || (weather.code == 30)) {
					weatherType = "cloudyDay";
				}
				else if (weather.code == 31) {
					weatherType = "clearNight";
				}
				else if (weather.code == 33) {
					weatherType = "fairNight";
				}
				else if (weather.code == 34) {
					weatherType = "fairDay";
				}
				else {
					weatherType = "na";
				}
										
				html = '<img src="../images/weather/'+weatherType+'.png" class="weatherIcon" title="Todays Forecast" />';
				html += '<div class="leftSide"><a target="_blank" href="'+weather.link+'" title="Todays Forecast">';
				html += '<div class="weatherLocation">'+weather.city+', '+weather.region+'</div>';
				html += '<div class="weatherCurrently">'+weather.forecast+'</div>';
				html += '</a></div>';
				html += '<div class="rightSide">';
				html += '<div class="weatherTemperature" title="Current Temperature"><b>'+weather.temp+'</b>&#186;</div>';
				html += '</div>';
				//html += '<img style="float:left;" width="125px" src="images/weather/'+weather.code+'.png">';
				//html += '<p>'+weather.temp+'&deg; '+weather.units.temp+'<br /><span>'+weather.currently+'</span></p>';
				//html += '<a href="'+weather.link+'">View Forecast &raquo;</a>';
				$("#weather").html(html);
		},
		error: function(error) {
				$("#weather").html("<p>"+error+"</p>");
		}
});	
