jQuery(document).ready(function($) {

	// Slide page d'accueil
	(function() {
		if ($('#slider').length) {
			$('#slider').nivoSlider({
				effect:'fade',
				pauseTime:5000,
				pauseOnHover:false,
				controlNavThumbsSearch: '-620x280.', // Replace this with...
				controlNavThumbsReplace: '-125x80.', // ...this in thumb Image src
				controlNavThumbs:true,
				directionNav:false
			});
		}
	})();

	// Météo page d'accueil
	(function() {
		var yqlUrl = "http://query.yahooapis.com/v1/public/yql?q=use%20'http%3A%2F%2Fwww.datatables.org%2Fweather%2Fweather.bylocation.xml'%20as%20weather.bylocation%3B%0Aselect%20*%20from%20weather.bylocation%20where%20location%3D'{CITY}'%20and%20unit%3D'c'%3B&format=json";
		var imgUrl = "http://l.yimg.com/a/i/us/we/52/{CODE}.gif";
		$('.weather').each(function() {
			var div  = $(this);
			var city = $(this).attr('title');
			
			$.ajax({
				dataType: 'jsonp',
				url: yqlUrl.replace('{CITY}', city),
				crossDomain: true,
				context: document.body,
				success: function(data, textStatus, jqXHR){
					if (data.query && data.query.results && data.query.results.weather.rss.channel.item.condition) {
						var result = data.query.results;
						$(div)
							.append(
								'<h4>' + city + '</h4>' +
								'<p>' +
									'<img src="' + imgUrl.replace('{CODE}', result.weather.rss.channel.item.condition.code) + '" />' +
									'<span class="high">' + result.weather.rss.channel.item.forecast[0].high + '°</span>' +
									'<span class="low">' + result.weather.rss.channel.item.forecast[0].low + '°</span>' +
								'</p>'
							);
					} else {
						$(div).remove();
					}
				}
			});
		});
	})();
	
	// Champ Email Newsletter
	(function() {
		var text = 'Adresse email';
		$('input[name=addEmail]')
			.attr('value', text)
			.focus(function(){
				if ($(this).attr('value')==text) {
					$(this).attr('value', '');
				}
			})
			.blur(function() {
				if (!$(this).attr('value')) {
					$(this).attr('value', text);
				}
			});
	})();
	
});
