/**
 * @author Xun Exnano
 * @version 1
 * 
 * JS
 */

var $=jQuery.noConflict();

var wd = $(window).width();
var ht = $(window).height();

$(document).ready(function() {

	if(wd<1440){
		wd = '90%';
		ht = '85%';
		//alert(wd);
	} else {
		wd = 1200;
		ht = 600;
	}
	
	$('#nav ul li').click(function(){
		$('#nav ul li').removeClass('selected');
		$(this).addClass("selected")
		var curr = $(this).attr('title');
		//alert(curr);
		$('.content').fadeOut(500,function(){
			$(this).remove();
			$('#frame').append('Gathering data . . .');
			$('#frame').load(curr+'.html',function(){
				$('#'+curr).slideDown(700);
				$(".content a.portfolio").fancybox({
					'width'				: wd,
					'height'			: ht,
					'margin'			: 0,
					'autoScale'			: false,
					'transitionIn'		: 'elastic',
					'transitionOut'		: 'fade',
					'type'				: 'iframe'
				});
			});
		});
	});
	
	$('img').bind('contextmenu', function(e){
	    return false;
	});
});


$(window).load(function(){
	startAnimation();
});


function startAnimation() {
	$('#nav').delay(2000).animate({
		marginTop:'0px'	
		},1500,'easeOutQuad',
		
		function() {
			$(this).animate({marginTop:'-40px'});
			fadeInNav();
	});

}

function fadeInNav() {
	$('#nav-ul').fadeIn(1000,function(){ slideInHome();});
	$('#frame').load('home.html');
}

var timer = 0;
function slideInHome() {
	$('#home ul li').css('opacity','0');
	$('#secondText li').css('margin-left','-30px');
	$('#home').fadeIn(1000, function(){
		$('#firstText li').each(function(i){
			timer = (timer*0.8 + 300);
			$(this)
			.animate({marginLeft: '70px', opacity: 1},timer)
			.animate({marginLeft: '0'},timer*3,'easeOutQuad');
		});
		
		$('#secondText li').delay(4000).each(function(i){
			timer = (timer*0.8 + 700);
			$(this)
			.animate({marginLeft:'0',opacity: 1},timer);
		});
	});
}
