$(document).ready(function() {
	// SLIDE NAV
	
	$('#prev-slide').click(function(){
		hide_content();
		api.prevSlide();
	});
	$('#next-slide').click(function(){
		hide_content();
		api.nextSlide();
	});
	$('#prev-slide, #next-slide').mouseover(function(){
		$(this).animate({
			opacity : 0.9
		});
	});
	
	$('#prev-slide, #next-slide').mouseout(function(){
		$(this).animate({
			opacity : 0.7
		});
	});
	
	// MENU
	
	$('#navmenu li a').mouseover(function(){
		$(this).animate({backgroundColor: 'rgba(157, 205, 16, 1)'}, 300);
	});
	
	$('#navmenu li a').mouseout(function(){
		$(this).animate({backgroundColor: 'rgba(0, 0, 0, 0.6);'}, 300);
	});
	
	$('#navmenu li a').click(function(){
		var url_parts = $(this).attr('href').split('/');
		load_page(url_parts[url_parts.length - 1]);
		return false;
	});
	
	// CONTENT
	
	$('#hide').click(function(){
		hide_content();
	});
	
	//
	
	init();
});

$(window).resize(function() {
	set_screen();
});

jQuery(function($){  	
  	$.supersized({
  		// Functionality
  		autoplay                : 0,
  		slide_interval          : 1000,		// Length between transitions
  		transition              : 1, 			// 0-None, 1-Fade, 2-Slide Top, 3-Slide Right, 4-Slide Bottom, 5-Slide Left, 6-Carousel Right, 7-Carousel Left
  		transition_speed		: 500,		// Speed of transition
  		// Components							
  		slide_links				: 'blank',	// Individual links for each slide (Options: false, 'number', 'name', 'blank')
  		slides 					: images		// Slideshow Images
  	});
});

var content_state = 'visible';

function init(){
	$('#navmenu li a[href="' + current_page + '"]').addClass('selected');
	set_screen();
}

function set_screen(){
	if(content_state == 'hidden'){
		$('#content-wrapper').css('top',  $(window).height() + 'px');
	}else{
		$('#content-wrapper').css('top', '150px');
	}
	
	$('#content-wrapper').css('height', $(window).height() - 168 + 'px');
	$('#content').css('height', $('#content-wrapper').height() - 47 + 'px');
}

function hide_content(){
	$('#content-wrapper').animate({
		top: $(window).height() + 'px'
	}, 400);
	
	content_state = 'hidden';
}
 
function show_content(){
	$('#content-wrapper').animate({
		top: '150px'
	}, 400);
	
	content_state = 'visible';
}
 
var block_navigation = false;

function load_page(page){
	if(page != current_page && !block_navigation){
		block_navigation = true;
		$('#navmenu li a[href="' + current_page + '"]').animate({backgroundColor: 'rgba(0, 0, 0, 0.6);'}, 600);
		$('#navmenu li a[href="' + current_page + '"]').removeClass('selected');
		$('#navmenu li a[href="' + page + '"]').addClass('selected');
		
		//hide_content();
		var data = {'page' : page};
		
//		$('#content').fadeOut(400, null, function(){
//			$.ajax({
//				type: "POST",
//				url: 'load_page',
//				data: data,
//				complete: function(response){
//					current_page = page;
//					
//					$('#content').html(response.responseText);
//					$('#content').fadeIn(400);
//					
//					if(content_state == 'hidden') show_content();
//					//show_content();
//				}
//			});
//		});
		
		$('#content').fadeOut(300, null, function(){
			$.ajax({
				type: "POST",
				url: 'load_page',
				data: data,
				complete: function(response){
					current_page = page;
					$('#content').html(response.responseText);
					$('#content').fadeIn(300);
					$('#content').scrollTop(0);
					if(content_state == 'hidden') show_content();
					block_navigation = false;
				}
			});
		});
		
	}else if(content_state == 'hidden'){
		show_content();
	}
}
