var newsitems;
var curritem = 0;

function getHeadlines() {

 	var sUrl = "/statistics/headlines";
 	var sItems = "";

	$.ajaxSetup ({ cache: false}); 
	$.getJSON(sUrl,
 		function(oData) {
 			if (oData.length > 0) {
 				$.each(oData, function(i, item) {
 					sItems += "<li class='hide'>" + item.headline + "<\/li>";
 					newsitems = (i + 1);
 				});
 			$("#headlines").html(sItems);
 			$(".headlines-ticker").show();
 			ticknews();
 			setInterval(ticknews, 4000); //time in milliseconds
 		}
 	});
}
	
function ticknews() {
	$(".headlines-ticker li").hide();
	$(".headlines-ticker li").html($("#headlines li:eq(" + curritem + ")").html());
	$(".headlines-ticker li").fadeIn("slow");
	curritem = ++curritem % newsitems;
}

function getRandomImages(count) {

 	var sUrl = "/flickr/random?count=" + count;
 	var sItems = "";

	$.ajaxSetup ({ cache: false}); 
	$.getJSON(sUrl,
 		function(oData) {
 			if (oData.length > 0) {
 				$.each(oData, function(i, item) {
 					sItems += "<li><a href=\"" + item.url.replace('_s','_b') + "\" flickr=\"" + item.page + "\" class=\"pirobox_gall_random\" title=\"" + item.title + "\"><img src=\"" + item.url + "\" width=\"75\" height=\"75\"/></a><\/li>";
 				});
 			$("#random-images ul").html(sItems);
			
			$().piroBox({
			    my_speed: 600, //animation speed
			    bg_alpha: 0.5, //background opacity
			    radius: 4, //caption rounded corner
			    scrollImage : false, // true == image follows the page, false == image remains in the same open position
			    pirobox_next : 'piro_next', // Nav buttons -> piro_next == inside piroBox , piro_next_out == outside piroBox
			    pirobox_prev : 'piro_prev',// Nav buttons -> piro_prev == inside piroBox , piro_prev_out == outside piroBox
			    close_all : '.piro_close',// add class .piro_overlay(with comma)if you want overlay click close piroBox
			    slideShow : 'slideshow', // just delete slideshow between '' if you don't want it.
			    slideSpeed : 4 //slideshow duration in seconds(3 to 6 Recommended)
			});
 		}
 	});
}