/*
 * Omogoca scrollanje novic.
 * Prikaze toliko novic, da so novice prikazane v celoti, preverja velikost parent okna.
 */
/*
  log = function (msg) {
      console.log("%s: %o", msg, this);
      return this;
  };
*/
$(document).ready(function() {
	// get hoder div size
	holderSize = $(".news-list").height()+50;
	
	// get number of news
	numberOfNews = $(".news-list ul li").size();
	
	// starting height
	newsHeight = 0;
	
	// firt visible, default 0
	firstVisible = 0;
	
	// last visible, default last item
	lastVisible = numberOfNews - 1;
	
	// hide news that go over the edge and remember the last visible
	function hideNotVisible() {
		newsHeight = 0;
		$(".news-list ul li").each(function(index) {
			if($(this).outerHeight() + newsHeight > holderSize) {
				$(this).hide();
			} else {
				$(this).show();
				newsHeight = newsHeight + $(this).outerHeight();
				lastVisible = index;
			}
		});	
	}
	
	//log('Last visible: '+lastVisible);
	
	// next (up) button
	$('.news-next').click(function() {
		// remove the first item and put in as last item
		$('.news-list ul li:eq(0)').appendTo('.news-list ul');
		
		// hide all none visible
		hideNotVisible();
	});
	
	// prev (down) button
	$('.news-prev').click(function() {
		// remove the first item and put in as last item
		$('.news-list ul li:last').prependTo('.news-list ul');
		
		// hide all none visible
		hideNotVisible();
	});
	
	
	// hide all none visible on page load
	hideNotVisible();
});
