/**
 *
 * JavaScript developed by digiblink.eu
 *
 **/

jQuery.noConflict();

jQuery(document).ready(function() {
	if (jQuery('#twitter-top-trends').length) { // implies *not* zero
		loadTopTrends();
	}
});

function loadTopTrends() {
	// Display a loading icon in our display element
	jQuery('#twitter-top-trends').html('notiek tendenču ielāde...');
		
	// Request the JSON and process it
	jQuery.ajax({
		type: 'GET',
		url: "https://api.twitter.com/1/trends/1.json",
		data: "callback=?",
		success:function(feed) {
			// Create an empty array to store trends
			var trendsFromFeed = [];
			var numOfTrends = feed[0].trends.length;

			// Loop through the items
			for(var i=0; i<numOfTrends; i++) 
			{
				// Get trend name and URL
				var trendName = feed[0].trends[i].name;
				var trendUrl = feed[0].trends[i].url;
				var trend = '<li><a href="'+trendUrl+'" target="_blank">'+trendName+'</a></li>';
		
				// Add the new element to the array
				trendsFromFeed.push(trend);
			}
		
			// Display the trends on the page
			jQuery('#twitter-top-trends').html('<ul>'+trendsFromFeed.join('')+'</ul>');
		},
		dataType:'jsonp'
	});
}

