$(document).ready(function () {

	//Display the Weather
	getWeather('CAXX0442','Dakota Dunes');

});

/*  Grabs the current weather based on the IP of the user. Weather code from weather.com is used. 
*   There are only 6 different locations (in the web.config)
*   Uses YQL, AJAX, and jQuery */
function getWeather(location, site) {
    
    // Specify the ZIP/location code and units (f or c)
    var loc = location;
    var u = 'c';
    var siteName = site;

    var query = "SELECT item.condition,wind.chill FROM weather.forecast WHERE location='" + loc + "' AND u='" + u + "'";
    var cacheBuster = Math.floor((new Date().getTime()) / 1200 / 1000);
    var url = 'http://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent(query) + '&format=json&_nocache=' + cacheBuster;

    window['wxCallback'] = function(data) {
        var info = data.query.results.channel.item.condition;
        var wind = data.query.results.channel.wind;
        //$('#wxIntro').html(siteName);
        $('#wxIcon').css({
            backgroundPosition: '-' + (61 * info.code) + 'px 0'
        }).attr({
            title: info.text
        });
        $('#wxIcon2').append('<img src="http://l.yimg.com/a/i/us/we/52/' + info.code + '.gif" width="34" height="34" title="' + info.text + '" />');
        $('#wxTemp').html(info.temp + '&deg;' + (u.toUpperCase()));
        $('#wxTemp').append('<p>Windchill: ' + wind.chill + '&deg;' + (u.toUpperCase()) + '</p>');
    };

    $.ajax({
            url: url,
            dataType: 'jsonp',
            cache: true,
            jsonpCallback: 'wxCallback'
        });
    }
