

$( document ).ready( function() {

	$.ajax({
	  url: 'main_menu.html',
	  cache: false,
	  success: function( html ){
	  
		//callback -->
	  
		$( '#left_side' ).append( html );
		
		function ajax_load_pages( that ){
			$( '#loader' ).fadeIn( 300 );
			var which_page = $( that ).attr( 'href' );
			$( '#middle' ).empty();
			$( '#middle' ).load( which_page );
			var width = $( that ).parent( 'li' ).css( 'margin-left' );
			numeric_width = width.replace( 'px','');
			if( numeric_width < 1 ){
			$( '#main_menu li' ).css( { 'margin-left' : '0px' } );
			$( that ).parent( 'li' ).animate( { marginLeft : '15px' }, 700, 'swing'  );
			}
			$( '#loader' ).fadeOut( 2000 );
		}
		
		$( '#main_menu a,#register' ).live( 'click', function( e ){
			e.preventDefault();
			that = this;
			ajax_load_pages( that );
			return false;
		});

		$( '#main_menu' ).animate({ 
			marginLeft: "10px"
			}, 1500, function(){
				$( '#main_menu li:first' ).animate( { marginLeft : '15px' }, 700, 'swing'  );
			});
		
		// end of callback
	  }
	});
	
	news_functions = function(){
			
			$( 'h2:first','#right' ).css( { 'font-size' : '22px' } );
			$( 'h2:first','#right' ).css( { 'margin-top' : '-16px' } );
			$( '.news_section','#right' ).slideUp( );
			$( '.news_section:first','#right' ).slideDown();
			$( 'h2','#right' ).css( { 'margin-bottom' : '10px' } );
			$( '.little_arrow:first' ).fadeIn( 1000 );
			
			$( '.little_arrow'  ).each( function(){

				if( $( this ).next( 'h2' ).height() > 16 ){
					$( this ).css( { 'top' : '8px' } );
				}
			});
			
			$( 'h2','#right' ).click( function( e ){
				if( $( 'h2','#right' ).index( this ) == 0 ){
					$( this ).css( { 'margin-top' : '-16px'  } );
				}else{
					$( 'h2','#right' ).css( { 'margin-top' : '2px'  } );
				}
				$( '.news_section','#right' ).slideUp();
				$( 'h2','#right' ).css( { 'font-size' : '14px' } );
				$( this ).css( { 'margin-bottom' : '0px'  } );
				$( this ).css( { 'font-size' : '22px' } );
				$( this ).next( '.news_section' ).slideDown();
				$( '.little_arrow' ).fadeOut( 200 );
				$( this ).prev( '.little_arrow' ).fadeIn( 1000 );
				
			});
			
	}
	
	
	$( '#right h2' ).hover( function(){
		$( this ).css( { 'background-color' : '#ff9405' } );
	},function(){
		$( this ).css( { 'background-color' : 'transparent' } );
	});
	
	news_functions();
	

});
