var noArticles      = 0;
var currentArticle  = 0;
var durationPaused  = 1500;		// How long the article is paused for (ms)
var durationFade    = 2000;		// Duration the fade takes, in and out (ms)
var timer 			= null;
var resumeTimer     = null;
		
		function fadein() {
			$("#review-item-" + currentArticle).fadeIn(durationFade);
			$("#review-link-" + currentArticle + " a.link").css("background", "#2d5984");
			
      timer = window.setInterval(fadeout, (durationFade+durationPaused));
		}
		
		function fadeout() {
			window.clearInterval(timer);
			$("#review-item-" + currentArticle).fadeOut(durationFade);
			$("#review-link-" + currentArticle + " a.link").css("background", "transparent");
			rotate();
		}
		
		function rotate() {
			currentArticle++;
			if (currentArticle > noArticles)
					currentArticle = 1;
			fadein();
		}
		
		function pause(article) {
      if (resumeTimer) {
        window.clearTimeout(resumeTimer);
        resumeTimer = null;
      }
			currentArticle = article;
			window.clearInterval(timer);
      timer = null;
		};
		
		function resume() {
      // Set a timer on resume, if a pause happens again before the timer expires,
      // we reset the timer and stop the resume
      resumeTimer = window.setTimeout(fadeout, 1500);
		}
		/* End article review box */
		
		$(document).ready(function() {
			
			// Get the number of articles (count the li tags)
			noArticles      = $(".review-links").children("li").length;	
			
			// Start the article roation
			window.setTimeout(fadeout, 500);
			
			// Jump to article if article link has mouse over
			$(".review-links li a.link").mouseover(function() {
				// Remove highlight on previous link, highlight this link
				$(".review-links li a.link").css("background", "transparent");
				$(this).css("background", "#2d5984");
				
				// Hide all article, then display selected article
				$(".review-links li div").css("display", "none");
				$(this).parent().children("div").css("display", "block");
				
				// Get the list index of the currently selected link
				// This is the list with an article set to display:block
				$.children = $(".review-links").children("li");
				for (var i = 0; i < $.children.length; i++) {
					$.child = $(".review-links").children("li:eq("+i+")");
					if ($.child.children("div").css("display") == "block")
						break;
				}
				pause(i);
			}).mouseout(function() {
				resume();
			});
	}); // $(document).ready
