/* Author: Inge Vlaar 

*/

var toLoad; 
var url = document.location.toString();
if (url.match('#contact')) {
	toLoad = $("nav[role='navigation'] a#contact").attr('href');
	$("nav[role='navigation'] a#about").removeClass('active');
	$("nav[role='navigation'] a#contact").addClass('active');
	$('#portfolio').css('height' ,'20');
	$('.slideshow').css('opacity' ,'0');
	$('.slideshow').addClass('hidden');
	$('#content').css('opacity', '0');
	if(posting) {
		toLoad = "includes/contact-success.html"; 
	}
	loadContent();	
}

function animateContact() {
	$("nav[role='navigation'] a#about").removeClass('active');
	$("nav[role='navigation'] a#contact").addClass('active');
	toLoad = $("nav[role='navigation'] a#contact").attr('href'); 
	
	$('#portfolio').animate({
		height: '20'
	}, 1000);
	
	$('.slideshow').animate({
		opacity: '0'
	}, 1000, function() {
		$('.slideshow').addClass('hidden');
	});
	$('.slideshow').cycle('pause');
	
	animateContent();
}

function animateAbout() {
	$("nav[role='navigation'] a#contact").removeClass('active');
	$("nav[role='navigation'] a#about").addClass('active');
	toLoad = $("nav[role='navigation'] a#about").attr('href'); 
	
	$('#portfolio').animate({
		height: '398'
	}, 1000);
	
	$('.slideshow').animate({
		opacity: '1'
	}, 1000, function() {
		$('.slideshow').cycle('resume');
	});
	$('.slideshow').removeClass('hidden');
	animateContent();
}

function animateContent() {
	$('#content').animate({
		opacity: '0'
	  }, 1000, function() {
		loadContent();
	  });
}

function loadContent() { 
	$('#content').load(toLoad, showNewContent());  
} 
	
function showNewContent() {  
	$('#content').animate({
		opacity: '1'
	}, 500);
} 


$(".slideshow-overlay").hover(
	function() {
		$('.slideshow').cycle('pause');
	},
	function() {
		$('.slideshow').cycle('resume');
	}
);

$("nav[role='navigation'] a").click(function (event) { 
	event.preventDefault();
	if($(this).attr('id') == 'about') {
		animateAbout();
	}
	else {
		animateContact();
	}
	return false; 
});
	

$(document).ready(function() {
	
	slideshowCycle();
	
	function slideshowCycle() {
		$('.slideshow').cycle({
			fx: 'scrollHorz',
			timeout: 6000,
			next: '#next',
			prev: '#prev'
		});
	}
	
	if (url.match('#contact')) {
		$('.slideshow').cycle('pause');
	}
	
	$('body').bind('orientationchange',function(){
		alert('orientation');
		$('.slideshow').cycle('destroy');
		slideshowCycle();
	})
	
	
});

























