/* Author: Ash Crooks, Web Designer & Developer (http://ash.crooks.me/)
*/

jQuery.noConflict(); //noConflict just incase and for future-proofing
jQuery(document).ready(function($){

	if($('#news_bar li').length > 1){

		$('#news_bar .controls').show();
		$('#news_bar li').hide().first().show();

		var current = 0,
		total = $('#news_bar li').length-1,
		timer,
		fadeDur = 400,
		waitDur = 7000;

		function changeIt(direction){
			clearTimeout(timer);

			$('#news_bar li').eq(current).fadeOut(fadeDur);

			if(direction == 'next'){
				current = current+1;
			}else{
				current = current-1;
			}

			if(current>total) current = 0;
			if(current<0) current = total;

			setTimeout(function(){
				$('#news_bar li').eq(current).fadeIn(fadeDur);
			}, fadeDur);

			timer = setTimeout(function(){
				changeIt('next');
			}, waitDur);
		}

		clearTimeout(timer);
		timer = setTimeout(function(){
				changeIt('next');
			}, waitDur);

		$('#news_bar .controls .prev').click(function(){
			changeIt('prev');
			return false;
		});

		$('#news_bar .controls .next').click(function(){
			changeIt('next');
			return false;
		});

		$('#news_bar .controls .playpause').click(function(){
			if($(this).hasClass('pause'))
			{
				clearTimeout(timer);
				$(this).removeClass('pause').addClass('play').text('Play');
			}
			else
			{
				timer = setTimeout(function(){
					changeIt('next');
				}, waitDur);
				$(this).removeClass('play').addClass('pause').text('Pause');
			}

			return false;
		});

	}


	if($('#sidebar .block').length > 1){

		var tallest = 0,
				thish = 0;

		$('#sidebar .block').each(function(){
			thish = $(this).height();
			if(thish > tallest) tallest = thish;
		});

		$('#sidebar .block').height(tallest);
	}


//	if($('ul li a[href$=".pdf"]').length > 0)
//	{
//		$('ul li a[href$=".pdf"]').parents('li').addClass('icon pdf');
//	}

});//jQuery
