$(document).ready(function() {
	// News listing images
	$('#news .thumb, #single .thumb').hover(function() {
		if (navigator.appName != "Microsoft Internet Explorer")
			$(this).stop(true, true).fadeTo(200, 0.9);
		$(this).find('.prev, .next').stop(true, true).fadeIn(200);	
	}, function() {
		if (navigator.appName != "Microsoft Internet Explorer")
			$(this).stop(true, true).fadeTo(200, 1);
		$(this).find('.prev, .next').stop(true, true).fadeOut(200);
	});
	// Some height adjustments in order to fit the design
	downloadHeight = $(".homeContainer-bottom .download").height() + 16;
	blogHeight = $(".homeContainer-bottom .blog").height() - 24;
	if (downloadHeight > blogHeight)
		$(".homeContainer-bottom .blog").height(downloadHeight);
	else
		$(".homeContainer-bottom .download").height(blogHeight);
	newsHeight = $(".levelContainer .news li").height();
	eventsHeight = $(".levelContainer .events li").height();
	textboxTopHeight = $(".levelContainer .textbox .top").height() - 50;
	textboxBottomHeight = $(".levelContainer .textbox .bottom").height() - 50;
	maxHeight = Math.max(newsHeight, eventsHeight, textboxTopHeight, textboxBottomHeight);
	$(".levelContainer .news li").height(maxHeight);
	$(".levelContainer .events li").height(maxHeight);
	$(".levelContainer .textbox .top").height(maxHeight + 43);
	$(".levelContainer .textbox .bottom").height(maxHeight);
	// Rounded corners
	$(".levelContainer .events .date, #home .eventItem .date, .button, #calendar table td, #calendar .upcoming .date").corner("5px");
	$(".levelContainer .news .left a img, .homeContainer-top .newsItem .left a img, #gallery .gallery a img, .thumb-img img").fadeTo(1,0);
	$("#breadcrumbs").corner("5px");
	// FancyBox (Image Zoom)
/*	$(".zoom").fancybox({
		onStart : function( links, index ) {
				var self = $(links[index]);
				if ( self.hasClass('video') ) {
					alert(self.attr('id'));
				}
				//$("#videoData").html('<a id="player" href="<TMPL_VAR NAME=MEDIA_FLV>' + self.attr('id') + '" style="display:block;width:475px;height:330px;"></a>' + $("#videoDataTemplate").html());
			},
		'transitionIn'		:	'elastic',
		'transitionOut'		:	'elastic',
		'speedIn'			:	300, 
		'speedOut'			:	150,
		'opacity'			: 	true,
		'titlePosition'		:	'outside',
		'showCloseButton'	:	false
	});*/
	
	$('#gallery .pagination-gallery a').click(function(){
		pages = parseInt($('#gallery .pagination-gallery a').not('.next').not('.prev').length, 10);
		current_page = parseInt($('.current_page').html(), 10);
		$('#gallery .pagination-gallery .active').removeClass('active');
		if ($(this).hasClass("prev") && current_page > 1) {
			page = current_page - 1;
			$('#p_page_'+page).addClass('active');
		}
		else if ($(this).hasClass("next") && current_page < pages) {
			page = current_page + 1;
			$('#p_page_'+page).addClass('active');
		}
		else {
			$(this).addClass("active");
			page = $(this).html();
		}
		if (page != current_page && page > 0 && page <= pages) {
			$("#page_"+page).fadeIn(300);
			$("#page_"+current_page).fadeOut(300);
			$('.current_page').html(page);
			running = 0;
			if (page == pages)
				$('#gallery .pagination-gallery .next').hide();
			else
				$('#gallery .pagination-gallery .next').show();
			if (page == 1)
				$('#gallery .pagination-gallery .prev').hide();
			else
				$('#gallery .pagination-gallery .prev').show();
		}
		return false;
	});
});
