$(document).ready(function()
{
	addServiceSlider();
	addLatestSlider();
});

function addServiceSlider()
{

	var _currentActiveContent;

	$('ul.subpages-list.service li').click(

		function()
		{
			if(_currentActiveContent)
			{
//				toggleServiceContent(_currentActiveContent);
			}
			_currentActiveContent = $(this);

			if(_currentActiveContent.children('div.subpage-content').is(':visible'))
			{
				toggleServiceContent(_currentActiveContent);
			}
			else
			{
				_currentActiveContent.removeClass('show');
				toggleServiceContent(_currentActiveContent);
			}
		}
	);


	$('ul.subpages-list.service li').hover(

		function()
		{
			if(!$(this).children('div.subpage-content').is(':visible'))
			$(this).addClass('show');
		},
		function ()
		{
			$(this).removeClass('show');
		}
	);

	$('ul.subpages-list.course li').hover(

			function()
			{
				if(!$(this).children('div.subpage-excerpt').is(':visible'))
				{
					$(this).addClass('show');
					$(this).children('div.subpage-excerpt').animate({opacity: 'show', height: 'show'}, 300);
				}
//				$(this).children('div.subpage-excerpt').slideFadeToggle(300);

			},
			function ()
			{
				$(this).children('div.subpage-excerpt').animate({opacity: 'hide', height: 'hide'}, 300);
//				$(this).children('div.subpage-excerpt').slideFadeToggle(300);
				$(this).removeClass('show');
			}
	);

	function toggleServiceContent(obj)
	{
		var doHide = _currentActiveContent.children('div.subpage-content').is(':visible');

		obj.children('div.subpage-excerpt').slideFadeToggle(doHide ? 500 : 250);
		obj.children('div.subpage-content').slideFadeToggle(doHide ? 500 : 500);
	}
}

function addLatestSlider()
{
	var _currentIndex = 0;
	var _entryHeight = 233;
//	var _entryLength = $('#news-container').children.length;
	var _entryLength = $('.entryExcerpt').length;
	
	console.log(_entryLength);

	var btnPrev = $('#latest a.prev').click(
		function(event)
		{
			event.preventDefault();
			if(_currentIndex > 0)
			{
				animateBox(1);
			}
		}
	);

	var btnNext = $('#latest a.next').click(
		function(event)
		{
			event.preventDefault();	
			if(_currentIndex + 1 < _entryLength)
			{
				animateBox(-1);
			}
		}
	);

	function animateBox(direction)
	{
		_currentIndex = direction > 0 ? --_currentIndex : ++_currentIndex;
		var offset = -(_currentIndex * _entryHeight);
		$('#news-container').animate({top: offset + 'px'}, 500);
		
		
	}
}

jQuery.fn.slideFadeToggle = function(speed, easing, callback)
{
	return this.animate({opacity: 'toggle', height: 'toggle'}, speed, easing, callback);
};


