jQuery(function($) {
	
	$('#navigation > ul > li').each(function() {
		if($(this).find('ul').length > 0) {
			$(this).find('a:eq(0)').append('<span class="dropdown-arrow">&nbsp;</span>');
		}
	});
	
	$('#side-nav > ul > li').each(function() {
		if($(this).find('ul').length > 0) {
			$(this).find('a:eq(0)').addClass('dropdown-arrow');
		}
	});
	
	$('.events .event:last, #latest-news .news-item:last').addClass('last');
	
	$('#slides img:eq(0), #slider-text p:eq(0)').show();
	$('#slider-links a:eq(0)').addClass('active')
	
	var slider_links_count = $('#slider-links a').length;
	var slider_link_width = $('#slider-links a:eq(0)').width() + parseInt($('#slider-links a:eq(0)').css('margin-left'));
	$('#slider-links').width(slider_links_count * slider_link_width);
	
	$('#navigation > ul > li').hover(
		function() {
			if($(this).find('ul').length > 0) {
				$(this).find('ul').show();
				$(this).addClass('hover');
			}
		},
		function() {
			if($(this).find('ul').length > 0) {
				$(this).find('ul').hide();
				$(this).removeClass('hover');
			}
		}
	);
	
	function change_slide(idx) {
		if ($('#slides img:animated').length == 0 && $('#slider-text p:animated').length == 0) {	
			if($('#slides img').index($('#slides img:visible')) != idx) {
				$('#slides img:visible, #slider-text p:visible').fadeOut();
				$('#slides img:eq(' + idx + '), #slider-text p:eq(' + idx + ')').fadeIn();
				$('#slider-links a.active').removeClass('active');
				$('#slider-links a:eq(' + idx + ')').addClass('active');						
			}
		}
	}
	
	$('#slider-links a').click(function() {
		var idx = $('#slider-links a').index($(this));
		change_slide(idx);
		return false;
	});
	
	$('#content .post:last').addClass('last');
	
});