$(document).ready(function() {
	var contentAni = false;
	var cShown = true;
	
	var commentPage = 1;

	function slideSwitch() {
		var $active = $('#slideshow IMG.active');

		if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

		var $next =  $active.next().length ? $active.next()
			: $('#slideshow IMG:first');

		$active.addClass('last-active');

		$next.css({opacity: 0.0})
			.addClass('active')
			.animate({opacity: 1.0}, 1000, function() {
				$active.removeClass('active last-active');
			});
	}
	
	function commentSwitch() {
		var oldPage = commentPage;
		commentPage++;
		if ($("#cPage" + commentPage).length == 0) commentPage = 1;
		$("#cPage" + commentPage).css("left", "375px");
		$("#cPage" + oldPage).animate({"left": "-375px"}, 1000, "easeOutBack");
		$("#cPage" + commentPage).animate({"left": "0px"}, 1000, "easeOutBack");
	}

	setInterval(slideSwitch, 8000);
	if ($("#cPage2").length > 0) {
		setInterval(commentSwitch, 8000);
	}	
	
	$("#slideShowContent").jScrollPane({showArrows:true,scrollbarWidth:7});
	$(".jScrollPaneContainer").css("z-index", "20");
	
	$(".contentWrapper").append('<a href="#" id="closeContent"></a>');
	$("#closeContent").click(function(e){
		e.preventDefault();	
		if (contentAni == false) {
			contentAni = true;
			
			if (cShown == true) {
				$(".contentWrapper").animate({"left": "-300px"}, 500, "easeInSine", function() { contentAni = false; cShown = false; $(".contentWrapper").addClass("hidden").animate({"left": "-292px"}, 1000, "easeOutExpo"); $("#closeContent").addClass("showAgain"); });
			} else {
				$(".contentWrapper").removeClass("hidden");
				$(".contentWrapper").animate({"left": "0px"}, 1000, "easeOutExpo", function() { contentAni = false; cShown = true; });
				$("#closeContent").removeClass("showAgain");
			}			
		}	
	});	
	
   $(".news").each(function(i) {
		$(this).jScrollPane({showArrows:true,scrollbarWidth:7});
   });	
	
});	
