// JavaScript Document
//  Comunicatek.com
//  From:  http://graphicallyherdingthemasses.blogspot.com/2009/11/access-yahoos-weather-api-via-yql-and.html
//  informació proveida per yahoo weather!
$.YQL = function(query, callback) {
    var encodedQuery = encodeURIComponent(query.toLowerCase()),
        url = 'http://query.yahooapis.com/v1/public/yql?q='
            + encodedQuery + '&format=json&callback=?';
    $.getJSON(url, callback);
};

$(document).ready(function(){ 

$.YQL("select * from xml where url='http://weather.yahooapis.com/forecastrss?w=769243'",function(data){
            var w=data.query.results.rss.channel;
            var weatherImage2="imatges/eltemps2/"+w.item.condition.code+"d.png";
            var wd=w.wind.direction;
			var t = parseInt(w.item.condition.temp);
			var temp = Math.round((t-32)/1.8);
			var humitat = w.atmosphere.humidity;
			var velocitat = Math.round(parseInt(w.wind.speed)/1.609344);
            if(wd>=348.75&&wd<=360){wd="N"};if(wd>=0&&wd<11.25){wd="N"};if(wd>=11.25&&wd<33.75){wd="NNE"};if(wd>=33.75&&wd<56.25){wd="NE"};if(wd>=56.25&&wd<78.75){wd="ENE"};if(wd>=78.75&&wd<101.25){wd="E"};if(wd>=101.25&&wd<123.75){wd="ESE"};if(wd>=123.75&&wd<146.25){wd="SE"};if(wd>=146.25&&wd<168.75){wd="SSE"};if(wd>=168.75&&wd<191.25){wd="S"};if(wd>=191.25 && wd<213.75){wd="SSW"};if(wd>=213.75&&wd<236.25){wd="SW"};if(wd>=236.25&&wd<258.75){wd="WSW"};if(wd>=258.75 && wd<281.25){wd="W"};if(wd>=281.25&&wd<303.75){wd="WNW"};if(wd>=303.75&&wd<326.25){wd="NW"};if(wd>=326.25&&wd<348.75){wd="NNW"};
            //$('#weatherWidget').css("background-image",weatherImage);
			var imatge = $("<img class='png_fix' />");
			if(typeof(window["DD_belatedPNG"]) != "undefined"){
				DD_belatedPNG.fix('.png_fix');
			}
			imatge.attr({src:weatherImage2, width : 64, height:46});
            $('#texteltemps').html(temp+"&deg; <br/>"+humitat+"%   ");
			$('#icoeltemps').append(imatge);			
            /*$('#weatherText').html(w.item.condition.text);
            $('#weatherWind').html(wd +" "+velocitat+"KM/H");
            $('#weatherLink').html("<a href='"+w.item.link+"'>Full Forecast</a>");*/
        });
});
