App = {

	menu: '#menu',
	firstPage: '#welcome',	
	currentPage: null,
	currentTab: 'rentalTech',
	
	setupMenu: function() {	

		var self= this;
	
		$( '.page' ).each( function(index) {
			var title= $(this).attr( 'menu' );
			var pageId= $(this).attr( 'id' );
			$( '#menu > ul' ).append( '<li pageId="' + pageId + '"><a href="#">' + title + '</a></li>' );
		});
		
		$( '#menu > ul > li' ).click( function() {			
			self.showPage( $(this).attr( 'pageId' ) );
		} );
	},
	
	appLaunched: function() {
	
		$.scrollTo( 0 );
		this.setupMenu();
		var self= this;
		$( '#inner' ).animate( { 'min-height': '+=400' }, 750, function() { 
			self.currentPage= $( self.firstPage );
			$( self.menu ).add( self.firstPage ).fadeIn( 2000 );  
		});
		     
		     
		this.tabviewNeedDisplay();		
		$( 'li[tab]' ).click( function() {		
				self.showTabview( $( this ).attr( 'tab' ) );
		} );
		
		$( 'a.toptech' ).click( function() {
			$( this ).parents( 'div.window' ).scrollTo( 0, 800 );
		} ); 

	},
	
	showTabview: function( tabId ) {
	
		this.currentTab= tabId;
		this.tabviewNeedDisplay();		
	},
	
	tabviewNeedDisplay: function() {
		
		$( 'div.tabview div.container' ).hide();
		$( '#' + this.currentTab ).show();
		$('li[tab]').removeClass( 'selected' );
		$('li[tab="' + this.currentTab + '"]').addClass( 'selected' );
	},		
		
	showPage: function( pageId ) {
	
		var display= true;
		if( this.currentPage != null ) {
			
			var theCurrentId= this.currentPage.attr( 'id' );
			if( theCurrentId == pageId ) {
				display= false;
			}
		} // if 
		
		if( display ) {
			var self= this;		
			var f= function() {		
				self.currentPage= $( '#' + pageId);
				self.currentPage.fadeIn( 400 );
			};
			
			if( self.currentPage != null) {
				$( self.currentPage ).fadeOut( 400, f )
			}
			else
				f()				
		} // if 	
	}	
}

$(document).ready( function() { 

	App.appLaunched();
	
} );
 
 

