(function($){
	
	
	
	function sayfa_yukle_hava(deger,durum){
		$.ajax({
		type: 'GET',
		url: '?page=weather&ajx=1&cekme='+durum+'&deger='+deger ,
		success: function(sonuc) {
						$('#weather_area').html(sonuc);
		}
	});
return false;
}
	



	
	

	var row = 'odd';

	$.fn.weatherfeed = function(locations, options) {	
	
		// Set pluign defaults
		var defaults = {
			unit: 'c',
			image: false,
			highlow: true,
			wind: false,
			link: false,
			showerror: false
		};  
		var options = $.extend(defaults, options); 
		
		// Functions
		return this.each(function(i, e) {
			var $e = $(e);
			
			// Add feed class to user div
			if (!$e.hasClass('weatherFeed')) $e.addClass('weatherFeed');

			// Check and append locations
			if (!$.isArray(locations)) return false;
			var count = locations.length;
			if (count > 10) count = 10;
			var locationid = '';
			for (var i=0; i<count; i++) {
				if (locationid != '') locationid += ',';
				locationid += "'"+ locations[i] + "'";
			}

			// Cache results for an hour to prevent overuse
			now = new Date()
					
			// Create Yahoo Weather feed API address
			
		
			var query = "select * from weather.forecast where location in ("+ locationid +") and u='"+ options.unit +"'";
			var api = 'http://query.yahooapis.com/v1/public/yql?q='+ encodeURIComponent(query) +'&rnd='+ now.getFullYear() + now.getMonth() + now.getDay() + now.getHours() +'&format=json&callback=?';

			// Send request
			//$.getJSON(api, function(data) {
			$.ajax({
				type: 'GET',
				url: api,
				dataType: 'json',
				success: function(data) {

					if (data.query) {
			
						if (data.query.results.channel.length > 0 ) {
							
							// Multiple locations
							var result = data.query.results.channel.length;
							for (var i=0; i<result; i++) {
							
								// Create weather feed item
								_callback(e, data.query.results.channel[i], options);
							}
						} else {

							// Single location only
							_callback(e, data.query.results.channel, options);
						}
					} else {
						if (options.showerror) $e.html('<p>Weather information unavailable</p>');
					}
				},
				error: function(data) {
					if (options.showerror)  $e.html('<p>Weather request failed</p>');
				}
			});

		});
	};

	var _callback = function(e, feed, options) {
		var $e = $(e);

		
		var wf = feed.item.forecast[0];
		
		wpd = feed.item.pubDate;
		n = wpd.indexOf(":");


		// Add item container
		
		// Add item data
		var  deger =  feed.item.condition.code+'|'+ feed.location.city +'|'+ wf.high +'|'+ wf.low ;
		
		
		

		// Alternate row classes
		if (row == 'odd') { row = 'even'; } else { row = 'odd';	}
		//alert(html) ;
		sayfa_yukle_hava(deger,'1');
		
		//$e.append(html);
	};

	// Get time string as date
	var _getTimeAsDate = function(t) {
		
		d = new Date();
		r = new Date(d.toDateString() +' '+ t);

		return r;
	};
})(jQuery);




