$(document).ready(function(){		
	//INITIATE SCREEN
	function initiateScreen(){
		
		var screenWidth=$(window).width()+18+"px";		
		var screenHeight=$(window).height()+"px";
		$("#sections li.section").css({width:"1870px", height:screenHeight});
		
		
		//definisikan posisi center di halaman clients
		var leftMarginforCenter="-"+(1870-$(window).width()+18)/2+"px";
		$("#clients-logo").css("marginLeft",leftMarginforCenter);
		
		//definisikan posisi container works supaya di tengah
		var leftMarginPortfolio=""+($(window).width()-800)/2+"px";
		var centerMarginPortfolio=""+($(window).width()-60)/2+"px";
		$("#portfolio-details-wrap").css("width",screenWidth);
		$("#portfolio-block-bottom").css("marginLeft",leftMarginPortfolio);
		$("#portfolio-prev").css("marginLeft",centerMarginPortfolio);
		
		
		var topMarginHome=""+($(window).height()-541)+"px";
		var leftMarginHome=""+($(window).width()-1000)/2+"px";
		$("#service-content").css("marginLeft",leftMarginPortfolio);
		$("#main-content-wrap").css("marginLeft",leftMarginHome);
		$("#main-content-wrap").css("marginTop",topMarginHome);
		
		//definisikan posisi container Contacts supaya di tengah
		var leftMarginPortfolio=""+($(window).width()-842)/2+"px";
		$("#contact-container").css("marginLeft",leftMarginPortfolio);
		
	};
	
	
	//SCREEN ON RESIZE
	$(window).resize(function() {
	  initiateScreen();
	});
	
	//INITIATE SCREEN FOR THE FIRST TIME
	initiateScreen();

	
	
	//MAIN NAVIGATION
	function resetActiveMenu(){
		$("li.nav-services a").removeClass("active");
		$("li.nav-works a").removeClass("active");
		$("li.nav-clients a").removeClass("active");
		$("li.nav-contact a").removeClass("active");
	};
			
	$("li.nav-home a").click(function(event){	
			event.preventDefault();
			$("#portfolio-inner-wrap2").cycle({
				//fx: 'scrollVert',		
			});	
			resetActiveMenu();
			$("#sections").stop().trigger( "goto", [0]);
			
	});
	
	$("li.nav-services a").click(function(event){		
			event.preventDefault();	
			$('#portfolio-inner-wrap2').cycle('pause');
			resetActiveMenu();	
			$("li.nav-services a").addClass("active");	
			$("#sections").stop().trigger( "goto", [1]);
			
	});
	
	$("li.nav-works a").click(function(event){		
			event.preventDefault();	
			$('#portfolio-inner-wrap2').cycle('pause');
			resetActiveMenu();
			$("li.nav-works a").addClass("active");			
			$("#sections").stop().trigger( "goto", [3]);
			
	});
	
	$("li.nav-clients a").click(function(event){		
			event.preventDefault();
			$('#portfolio-inner-wrap2').cycle('pause');
			resetActiveMenu();
			$("li.nav-clients a").addClass("active");	
			$("#sections").stop().trigger( "goto", [2]);			
	});
	
	$("li.nav-contact a").click(function(event){		
			event.preventDefault();
			$('#portfolio-inner-wrap2').cycle('pause');
			resetActiveMenu();
			$("li.nav-contact a").addClass("active");	
			$("#sections").trigger( "goto", [4]);
			
	});
	
	//DEFINE SCROLLING FOR PAGE
	$('#screen').serialScroll({
		target:'#sections',
		items:'li.section', 
		prev:'a.prev',
		next:'a.next',
		axis:'x',		
		duration:2000,
		force:true, 
		
		constant:false, 
		
		onBefore:function( e, elem, $pane, $items, pos ){
			e.preventDefault();
			if( this.blur )
				this.blur();
		},
		onAfter:function( elem ){
			
		}
	});
	
	
	
	//DEFINE SCROLLING FOR PORTFOLIO ON MAINPAGE
	$("#portfolio-inner-wrap2").cycle({
		//fx: 'scrollVert'		
	});	
	
	$("#portfolio-block-bottom").cycle({
		fx: 'scrollHorz',		
		timeout:10000,
		// easing: true,
		prev: '#portfolio-prev',
		next: '#portfolio-next',
		speed: 600
	});	
	
	$('#portfolio-next').click(function() { 
	    $('#portfolio-block-bottom').cycle('pause'); 
	});	
	
	$('#portfolio-prev').click(function() { 
	    $('#portfolio-block-bottom').cycle('pause'); 
	});	
	
	$("a[rel*=facebox]").click(function() { 
	    $('#portfolio-block-bottom').cycle('pause'); 
	});	
	
	$('#portfolio-block-bottom').cycle('pause');
	
	
	
	//FACEBOX
	$("a[rel*=facebox]").facebox({
	    loading_image : '/js/facebox/loading.gif',
	    close_image   : '/js/facebox/closelabel.gif'
	  }); 
	
	//LOAD DATA FOR PAGE WORKS
	var page=1;
	$('#portfolio-next').click(function(event){		
			event.preventDefault();
			page=page+1;
			//reloadWorks(page);			
	});
	
	$('#portfolio-prev').click(function(event){		
			event.preventDefault();
			page=page-1;
			//reloadWorks(page);			
	}); 
		 
	
	
	
   	
});	

jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
	return -c * ((t=t/d-1)*t*t*t - 1) + b;
};
