$(document).ready(function() {
	
	$("#hide").click(function (e) {
		$(this).fadeOut("slow");
		$("#content").fadeOut("slow", function() {
			$("#controls").fadeIn("slow");
			$("#show").fadeIn("slow");
		});
		e.preventDefault();
	});

	$("#show").click(function (e) {
		$(this).fadeOut("slow");
		$("#controls").fadeOut("slow", function() {
			$("#content").fadeIn("slow");					
			$("#hide").fadeIn("slow");													
		});
		e.preventDefault();
	});
	

    $("#content").hover(
      function () {
        $("#controls").stop(false, true).fadeOut("slow");
      }, 
      function () {
        $("#controls").stop(false, true).fadeIn("slow");
      }
    );
	

	/* Background Image Cycle */
    $('#bg').cycle({
        fx:      	'fade',
        timeout:	15000,
		speed: 		2000,
        prev:    	'#prev',
        next:    	'#next',
		pauseOnPagerHover: 0,
		requeueOnImageNotLoaded: true,
		before: onBefore,
		after: onAfter
    });
	function onBefore() {
		$('.title').fadeOut("slow");
	}
	function onAfter() {
		$('.title').html($(this).attr('alt')).fadeIn("slow");
	}
	

// AJAX Requests
$.ajaxSetup ({  
	cache: false  
});  
var ajax_load = "<img src='img/load.gif' alt='loading...' />";  

//  load() functions
$("#nav a").click(function(e){
	$("#nav a").removeClass("active");
	e.preventDefault();
	var url = $(this).attr("href");
	
	$(this).addClass("active");
	//alert(url);
	//$("#main").html(ajax_load).load(url);
	
	$.ajax({
	  url: url,
	  success: function(data) {
		$('#main').html(data);
		/* Reactivate Fancybox .:TODO:. find clean workaround */
		$(".ce_gallery a").fancybox({
			'titleShow'			: false,
			'overlayOpacity'	: 0.8,
			'overlayColor'		: '#000'
		});		
	  }
	});	
	
});  



/* Frontpage Newsslider: insert / into #nav */
$("#news-nav a").insertAfter("&#47;");




	/* News Cycle */
	


	// Background Cycle
	
	
    // Gallery Overlay
	/*
	$('a[rel^="#galleryoverlay"]').overlay({ 
		top: 84, 
        onBeforeLoad: function() {
            var wrap = this.getContent().find(".contentWrap"); 
            wrap.load(this.getTrigger().attr("href")); 
        }
    });
	*/
	
	
	/* Main Container Max Height */
	maxMainHeight = $(window).height() - 201;
	$('#main').css('max-height', maxMainHeight);
	
});

