// JavaScript Document
var data = { project_index: 4 };

var nav = {
	current_page: 1, 
	
	page: function ( id ){
	
		var win_width = $( window ).width();
		var w =  Math.round(  ( id - 1) * 1440  - ( ( win_width - 1440 ) / 2 ) );
		nav.current_page = id;
		$.scrollTo( w < 0 ? 0 : w ,400,{axis:'x'});
	},
	
	locall_scroll: function(){
		$('#page_1').localScroll({ axis:'x' });
	}	
};


var layout  = {
	resizeTimer: null,
	reposition: function(){
		var win_height = $( window ).height();	
		var page_height = $('#page_c').height();
		if( win_height > page_height ){
			$('#page_c').css({'margin-top':  (( win_height - page_height ) /2 )+'px' });
		} else {
			$('#page_c').css({'margin-top': '0px' });
		}	
		nav.page( nav.current_page );		 
	 }
};


var project = {
	move: 840,
	duration:'1000',
	index: 1,
	
	init: function(){
		
	},
	view: function ( index ){
		if( index == data.project_index || $('#project_' + index ).size()== 0  )
			return;
		this.index = index ;
		$('#project_' + index ).animate({left:0}, this.duration , function(){ 
			$('#pm a').removeClass('selected');
			$('#pm .li_' + project.index + ' a').addClass('selected');
		
		});
		$('#project_' + data.project_index ).animate({opacity:0}, this.duration , function(){ project._set_current() });
	},
	_set_current: function (){
		$('#project_' + data.project_index ).css({ opacity:1, left: project.move });
		data.project_index = project.index;	
	}	
}


$( document ).ready( function(){
	$('html').css({ overflow: 'hidden' });
	layout.reposition();	
	project.init();
	nav.page( 1 );	
});

$( window ).bind('resize', function (e ) {
		if (layout.resizeTimer ) clearTimeout( layout.resizeTimer );
		layout.resizeTimer = setTimeout( layout.reposition , 80 );
});

