$(document).ready(function(){
	if( $(window).width() < 1010 )
	{
		resizeTo(1024,768);
	}
});

$(function(){

//
// Config numbers.

	var drw_top        = -640;              // Drawer start location relative to top   side of #page
	var drw_right      = -665;              // Drawer start location relative to right side of #page
    var drw_width      =  870;              // Drawer width.
    var drw_height     =  1500;             // Drawer height.
    
    var drw_hide_top   = -75;               // Drawer hidden relative to start location.
    var drw_hide_right = -220;              
    
    var drw_diff_top   =  272;              // Drawer open relative to start location.
    var drw_diff_right =  600;              // 
	
	var drw_left	   =  595;				// Drawer start location for Firefox
	var drw_diff_left  =  595;				// Drawer movement for Firefox
    
    var ease_method   = 'easeOutExpo'       // Easing method.
    var ease_duration = 800;                // Easing duration (lower is faster).
	
	var drawerVisible = false;
	
	var logo1 = new Image();				// Preload logo image rollovers
	logo1.src = 'images/corner_logo_m.gif';
	var logo2 = new Image();				// Preload logo image rollovers
	logo2.src = 'images/corner_logo_mil_studio.gif';
	var logo3 = new Image();				// Preload logo image rollovers
	logo3.src = 'images/corner_logo_work.gif';
    
//
// Setup the initial css properties.

    $('#drawer').css({width: drw_width+'px', height: drw_height+'px', top: drw_top+'px', right: drw_right+'px'});

//
// Place the #page div in the center of the window.

    var left = ($(window).width()  - $("#page").width())  / 2;
    var top  = ($(window).height() - $("#page").height()) / 2;


//
// Move the drawer slightly outside of view, fade the page in, and slide the drawer in.
/*
	$('#drawer').css({top: (drw_top+drw_hide_top)+'px', right: (drw_right+drw_hide_right)+'px'});

	$('#page').fadeIn("fast", function () {
	
		$('#drawer').animate({top: drw_top+'px', right: drw_right+'px'}, {duration: ease_duration, easing: ease_method});
		
	});

*/
//
// Drawer click action.

	$('#home').click(function(){
			
		if ( drawerVisible == false )
		{
			/*
			$('#aboutmiL').show();
			$('#bios').hide();
			$('#mainContainer').css( 'z-index', '1');
			$('#deactivateOverlay').css( 'z-index', '2');
			if($.browser.mozilla)									// Fix for Firefox 2 animate bug
				$('#drawer').animate({top: (drw_top+drw_diff_top)+'px', left: (drw_left-drw_diff_left)+'px'}, {duration: ease_duration, easing: ease_method});
			else
				$('#drawer').animate({top: (drw_top+drw_diff_top)+'px', right: (drw_right+drw_diff_right)+'px'}, {duration: ease_duration, easing: ease_method});
			drawerVisible = true;
			*/
		} else
		{
			$('#deactivateOverlay').css( 'z-index', '1');
			if($.browser.mozilla)									// Fix for Firefox 2 animate bug
				$('#drawer').animate({top: drw_top+'px', left: drw_left+'px'}, {duration: ease_duration, easing: ease_method});
			else
				$('#drawer').animate({top: drw_top+'px', right: drw_right+'px'}, {duration: ease_duration, easing: ease_method});
			drawerVisible = false;
			setTimeout("$('#mainContainer').css( 'z-index', '3')", ease_duration);
			$('#cornerLogo').attr({src: 'images/corner_logo.gif'});
			$('#home').css( 'cursor', 'default' );
		}
	});
	
	$('#about').click(function(){
		if( drawerVisible )
		{
			$('#aboutmiL').show();
			$('#bios').hide();
		}
		else
		{
			$('#aboutmiL').show();
			$('#bios').hide();
			$('#mainContainer').css( "z-index", "1");
			$('#deactivateOverlay').css( 'z-index', '2');
			if($.browser.mozilla)									// Fix for Firefox 2 animate bug
				$('#drawer').animate({top: (drw_top+drw_diff_top)+'px', left: (drw_left-drw_diff_left)+'px'}, {duration: ease_duration, easing: ease_method});
			else
				$('#drawer').animate({top: (drw_top+drw_diff_top)+'px', right: (drw_right+drw_diff_right)+'px'}, {duration: ease_duration, easing: ease_method});
			drawerVisible = true;
		}
	});
	
	$('#work').click(function(){
			
		if ( drawerVisible )
		{
			$('#deactivateOverlay').css( 'z-index', '1');
			if($.browser.mozilla)									// Fix for Firefox 2 animate bug
				$('#drawer').animate({top: drw_top+'px', left: drw_left+'px'}, {duration: ease_duration, easing: ease_method});
			else
				$('#drawer').animate({top: drw_top+'px', right: drw_right+'px'}, {duration: ease_duration, easing: ease_method});
			setTimeout("$('#mainContainer').css( 'z-index', '3')", ease_duration);
			drawerVisible = false;
		}
	});
	
	$('#deactivateOverlay').click(function(){
		if ( drawerVisible )
		{
			$('#deactivateOverlay').css( 'z-index', '1');
			if($.browser.mozilla)									// Fix for Firefox 2 animate bug
				$('#drawer').animate({top: drw_top+'px', left: drw_left+'px'}, {duration: ease_duration, easing: ease_method});
			else
				$('#drawer').animate({top: drw_top+'px', right: drw_right+'px'}, {duration: ease_duration, easing: ease_method});
			setTimeout("$('#mainContainer').css( 'z-index', '3')", ease_duration);
			drawerVisible = false;
		}
	});
	
	$('#topFiller').click(function(){
		if( drawerVisible)
		{
			$('#deactivateOverlay').css( 'z-index', '1');
			if($.browser.mozilla)									// Fix for Firefox 2 animate bug
				$('#drawer').animate({top: drw_top+'px', left: drw_left+'px'}, {duration: ease_duration, easing: ease_method});
			else
				$('#drawer').animate({top: drw_top+'px', right: drw_right+'px'}, {duration: ease_duration, easing: ease_method});
			setTimeout("$('#mainContainer').css( 'z-index', '3')", ease_duration);
			drawerVisible = false;
		}
	});
	
	$('#bottomFiller').click(function(){
		if( drawerVisible)
		{
			$('#deactivateOverlay').css( 'z-index', '1');
			if($.browser.mozilla)									// Fix for Firefox 2 animate bug
				$('#drawer').animate({top: drw_top+'px', left: drw_left+'px'}, {duration: ease_duration, easing: ease_method});
			else
				$('#drawer').animate({top: drw_top+'px', right: drw_right+'px'}, {duration: ease_duration, easing: ease_method});
			setTimeout("$('#mainContainer').css( 'z-index', '3')", ease_duration);
			drawerVisible = false;
		}
	});
		 
//
// Biographies carousel setup
	
	$(".biographies").jCarouselLite({
		btnNext: ".next",
		btnPrev: ".prev",
		speed: ease_duration,
		easing: ease_method,
		visible: 1,							// Show 1 at a time
		scroll: 1							// Scroll 1 at a time
	});
	$("#bios").hide();						// Hide carousel after it is constructed
	
	// Carousel setup for each project
	$(".project_1").jCarouselLite({
		btnNext: ".next_1",
		btnPrev: ".prev_1",
		speed: 400,
		easing: ease_method,
		visible: 1,
		scroll: 1
	});
	$(".project_1").hide();
	
	$(".project_2").jCarouselLite({
		btnNext: ".next_2",
		btnPrev: ".prev_2",
		speed: 400,
		easing: ease_method,
		visible: 1,
		scroll: 1
	});
	$(".project_2").hide();
	
	$(".project_3").jCarouselLite({
		btnNext: ".next_3",
		btnPrev: ".prev_3",
		speed: 400,
		easing: ease_method,
		visible: 1,
		scroll: 1
	});
	$(".project_3").hide();
	
	$(".project_4").jCarouselLite({
		btnNext: ".next_4",
		btnPrev: ".prev_4",
		speed: 400,
		easing: ease_method,
		visible: 1,
		scroll: 1
	});
	$(".project_4").hide();
	
	$(".project_5").jCarouselLite({
		btnNext: ".next_5",
		btnPrev: ".prev_5",
		speed: 400,
		easing: ease_method,
		visible: 1,
		scroll: 1
	});
	$(".project_5").hide();
	
	$(".project_6").jCarouselLite({
		btnNext: ".next_6",
		btnPrev: ".prev_6",
		speed: 400,
		easing: ease_method,
		visible: 1,
		scroll: 1
	});
	$(".project_6").hide();
	
	$(".project_7").jCarouselLite({
		btnNext: ".next_7",
		btnPrev: ".prev_7",
		speed: 400,
		easing: ease_method,
		visible: 1,
		scroll: 1
	});
	$(".project_7").hide();
	
	$(".project_8").jCarouselLite({
		btnNext: ".next_8",
		btnPrev: ".prev_8",
		speed: 400,
		easing: ease_method,
		visible: 1,
		scroll: 1
	});
	$(".project_8").hide();
	
	$(".project_9").jCarouselLite({
		btnNext: ".next_9",
		btnPrev: ".prev_9",
		speed: 400,
		easing: ease_method,
		visible: 1,
		scroll: 1
	});
	$(".project_9").hide();
	
	$('#home').mouseover(function(){
		if( drawerVisible )
		{
			$('#cornerLogo').attr({src: 'images/corner_logo_m.gif'});
			$('#home').css( 'cursor', 'pointer' );
		}
	});
	
	$('#home').mouseout(function() {
		if( drawerVisible )
		{
			$('#cornerLogo').attr({src: 'images/corner_logo.gif'});
		}
	})

})

function showBios()
{
	$('#aboutmiL').hide();
	$('#bios').show();
}

function showProject( projectID, toggle )
{
	if( toggle == true )
	{
		$('#project_' + projectID + '_intro').hide();
		$('.project_' + projectID).show();
	}
	else
	{
		$('.project_' + projectID).hide();
		$('#project_' + projectID + '_intro').show();
	}
}
