// JavaScript mainjs


$().ready(function() {
	$('#coda-slider-1').codaSlider();
	
	/* These are the 4 content areas - Add more for more areas */
	$('#coda-slider-2').codaSlider();
	$('#coda-slider-3').codaSlider();
	$('#coda-slider-4').codaSlider();
	$('#coda-slider-5').codaSlider();
	
	
	/* Page transisions */
	$('.admen').click(function() {
		FadeAllContent();
		 $('.AdmenPage').fadeIn('slow', function() {
			// Animation complete
			PageHash('AdmenPage');
		 });
	
	});
	
	$('.portfolio').click(function() {
		FadeAllContent();
		 $('.PortfolioPage').fadeIn('slow', function() {
			// Animation complete
			PageHash('PortfolioPage');
		 });
	
	});
	
	$('.web').click(function() {
		FadeAllContent();
		 $('.WebPage').fadeIn('slow', function() {
			// Animation complete
			PageHash('WebPage');
		 });
	
	});
	
	$('.animation').click(function() {
		FadeAllContent();
		 $('.AnimationPage').fadeIn('slow', function() {
			// Animation complete
			PageHash('AnimationPage');
		 });
	
	});
	
	
	CheckHash();
});

 $(function() {
 	var settings = { containerResizeSpeed: 350
 	};
	$('#gallery a').lightBox(settings);
});






function FadeAllContent() {
	
	 $('.AdmenPage').fadeOut('fast', function() {
		// Animation complete.
	  });
	 
	 $('.PortfolioPage').fadeOut('fast', function() {
		// Animation complete.
	  });
	 
	 $('.WebPage').fadeOut('fast', function() {
		// Animation complete.
	  });
	 
	 $('.AnimationPage').fadeOut('fast', function() {
		// Animation complete.
	  });
	 
}

function PageHash(PageName) {
	window.location.hash = PageName;
}

function CheckHash() {
	FadeAllContent();
	var Hash = window.location.hash;
	Hash = Right(Hash, Hash.length-1);	
	
	if(Hash!='') {
		 $('.' + Hash).fadeIn('slow', function() {
			// Animation complete 
		 });
	} else {
		 $('.AdmenPage').fadeIn('slow', function() {
			// Animation complete
		});
	}	
}

function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}
