
$(document).ready(function()
{		
	$( '#context' ).hide();
	
	$( '.context-button' ).click( function(){ toggleContext( $(this) ) } );
	
	layout();
	
	$(window).resize( function() { layout(); } );
	
	//$( '.project-grid .item' ).find( 'img' ).hide(  );
	
	//$( '.project-grid .item' ).find( 'img' ).load( function(){ $( this ).fadeIn('slow') });
	
	var header_h = $( '#header' ).outerHeight();
	
	if( $( '#header' ).css('position') != 'relative' )
	{
		
		$( '#content' ).css( 'top', header_h + 'px' );
		
		if( !isMobile )
		{
			$( '.project-grid .item' ).hover(
				function()
				{
					$(this).find('.info').show();
					var t = Math.round( ( $( this ).height() - $(this).find('.info .text').innerHeight() )/2 );
					$(this).find('.info .text').css( 'top', t + 'px' );
				},
				function()
				{
					$(this).find('.info').hide();
				}
			);

			$( '.project-grid .item' ).click(
				function()
				{
					var id = $(this).attr('id');
					showInfo( true, eval('info'+id), eval('title'+id) );
					return false;
				}
			);
		}
	}
});

//

function toggleContext( o )
{	
	$( '#context' ).toggle();
	
	updateContentPosition();
		
	if( o.html() == "more options" )
	{
		o.html( "hide options" );
	} 
	else if( o.html() == "hide options" )
	{
		o.html( "more options" );
	} 
	else if( o.html() == "project info" )
	{
		o.html( "hide info" );
	} 
	else if( o.html() == "hide info" )
	{
		o.html( "project info" );
	}
	
	updateContentPosition();
}

function updateContentPosition()
{
	var h = $( '#header').height();
	
	$( "#content" ).animate( { top:h+'px' } );
}

function showInfo( state, str, title )
{
	if( state )
	{
		$( "#header .project-list").html('');
		$( "#header .project-list").html( str ).show();
	}
	else
	{
		$( "#header .project-list").html('').hide();
	}
	
	updateContentPosition();
	
	pageTracker._trackEvent('Projects','Info',title);
}

function showImages( array, title )
{
	jQuery.slimbox( array, 0 );	
	
	pageTracker._trackEvent('Projects','Images',title);	
}

function onGridRefresh( w, h )
{
	x = 10;
	
	$( "#nav").css( 'width', w + 'px' );
	
	$( '#project-nav' ).css( 'position', 'absolute' );
	$( '#project-nav' ).css( 'top', h+15 );
	$( '#project-nav' ).css( 'left', x + 'px' );
	//
	$( '#project-footer' ).css( 'width', w/2 + 'px' );
	x = w - $( '#project-footer' ).width() - x;
	$( '#project-footer' ).css( 'position', 'absolute' );
	$( '#project-footer' ).css( 'top', cols[0].y+15 );
	$( '#project-footer' ).css( 'left', x + 'px' );
}


