// JavaScript Document
function gen_random(min, max){
return Math.floor(Math.random() * (max- min) + min);
}

function popTheNews(listElement, newsCount, doAnim){
	//var startNum = 1;
	var $allVisible = jQuery(listElement+':visible');
	
		var $nthChild = jQuery(listElement+':nth-child('+newsCount+')');
		
		var newsTwo = newsCount + 1;
		var $qthChild = jQuery(listElement+':nth-child('+newsTwo+')');
		$allVisible.fadeTo("fast", "toggle");
		//console.log("wat " + $nthChild.height);
		if(doAnim){
			$nthChild.slideToggle(1000);
			$qthChild.slideToggle(1000);
		} else {
			$nthChild.css('display','block');
			$qthChild.css('display','block');
			
		}
}

function popTransactions(listElement, totalTrans, doAnim){
	
	var $allVisible = jQuery(listElement+':visible');
	
	var numTesti = gen_random(1, totalTrans);
	
		
		var $nthChild = jQuery(listElement+':nth-child('+numTesti+')');
		if($nthChild.is(':visible')){
			numTesti = gen_random(1, totalTrans);
			$nthChild = jQuery(listElement+':nth-child('+numTesti+')');
		}
		 var numTesti2 = numTesti+1;
		var $qthChild = jQuery(listElement+':nth-child('+numTesti2+')');

		$allVisible.hide();
		if(doAnim){
			$nthChild.slideToggle("slow");
			$qthChild.slideToggle("slow");
		} else {
			$nthChild.css('display','block');
			$qthChild.css('display','block');
		}
}



var newsCount = 1;
var totalNews = jQuery(".news-ticker  li ul li").size();
	
var totalTrans = jQuery('#sidebar1 .ngg-galleryoverview .ngg-gallery-thumbnail-box').size();// get real count!!!

jQuery(document).ready(function(){ 

    popTheNews(".news-ticker li ul li",newsCount, true);
 
    popTransactions('#sidebar1 .ngg-galleryoverview .ngg-gallery-thumbnail-box', totalTrans, true);
    jQuery('.ngg-gallery-thumbnail-box a[href]').attr('href','transactions/');

});

setInterval(function() {
		newsCount = newsCount+2;
		if (newsCount > totalNews){
			newsCount = 0;
		}
	    popTheNews(".news-ticker  li ul li", newsCount, true);
				 
		 popTransactions('#sidebar1 .ngg-galleryoverview .ngg-gallery-thumbnail-box', totalTrans, true);

}, 5000);

	
