//READY HANDLER
$(document).ready(function() {
	$('.fancy').fancybox(); 
	

	
});
		// Handler when ajax request is sent
		$('#loadingMessage').ajaxSend(function(e, xhr, settings) {});
		//Whenever an Ajax request completes, jQuery triggers the ajaxComplete event. Any and all handlers that have been registered with the .ajaxComplete() method are executed at this time. We can attach our event handler to any element:
		$('#loadingMessage').ajaxComplete(function(e, xhr, settings) {});
		
		$('#loadingMessage').ajaxStop(function(){});
		

		
// NEW WINDOW HANDLER
function newWindow(){
	var windowName = 'New Window';
	var url = $(this).attr('href');
	window.open(url, windowName, 'toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes'); 
	return false;
}




function setFooter(){
	$('#footerContainer').css('visibility', 'hidden');
	var contentHeight = $('#allContainer').outerHeight();					 
	var windowHeight = $(window).height();
	var footerHeight = $('#footerContainer').outerHeight();
	if(contentHeight + footerHeight < windowHeight){
		$('#footerContainer').addClass('bottomPos');
		$('#footerContainer').css('visibility', 'visible');
	} else{
		if($('#footerContainer').hasClass('bottomPos')){
			$('#footerContainer').removeClass('bottomPos');
		}
		$('#footerContainer').css('visibility', 'visible');
	}
}



$('.newWindow').bind('click', newWindow);
$('.flickr_badge_image a').bind('click', newWindow);


$(window).bind('resize', setFooter);
$(window).bind('load', setFooter);

function doVisibility(){
	
	// STEP #1 In the complicated show / hide procedure:
		/*   
			a) hide projectList using visibility 
			b) show project list using display properties so that the height registers and the project image heights can be adjusted
			c) set the height of the section to auto so that the scrollbars register properly
			d) grab the value of the height
			e) make adjustments to the heights of the project images
		
		*/
		$(".projectList").queue("namedQueue", function() {
			 // alert("Second");
			 $('#loading').fadeOut(200, function(){    
													
													
			 //$('#loading').hide(0);
			 // $('.projectList').css('visibility', 'hidden')
			  $(".projectList").show();
			  $('#myWork').css('height', 'auto');
			 // alert($('#myWork').outerHeight());
			  $('#myWork').css('height', $('#myWork').outerHeight());
			  setFooter();
			  adjustHeights();
			  $('.scroll-pane').jScrollPane();
			
			 });
			
			  var self = this;
			  setTimeout(function() {
				$(self).dequeue("namedQueue");
			  }, 200);
		});
		
		// STEP #3 In the complicated show / hide procedure:
		/*   
			a) hide projectList again so that fadein works
			b) set the visibility to visible so that when the fadein begins, the project display will show up
			c) Fade the project list in... finally
		*/
		$(".projectList").queue("namedQueue", function() {
			$(".projectList").hide();
			$('.projectList').css('visibility', 'visible')
			$(".projectList").fadeIn(500);	
			//$(".projectList").show();	
		 	setTimeout(function() {
				$(self).dequeue("namedQueue");
			 }, 100);
		});
		$(".projectList").dequeue("namedQueue");
		

}

$('.navBtn').click( function(){
			
	//alert('clicked');
	
	$('.navBtn').removeClass('activeNav');
	$(this).addClass('activeNav');
	
	
	$storedText = $(this).text();
	$('#myWork .sectionTitle').text($storedText);
	/*$('#myWork .sectionTitle').animate(
		{'opacity': 0,
		 'margin-top':'-=50' },250, function(){
			
			
			
			
			$('#myWork .sectionTitle').animate(
				{'opacity': 100,
				 'margin-top':'+=50' },1000)		
		  
		}  
									   
	)
	*/
	$('#recentWork .sectionTitle').text($(this).text())
	
	
	
	$storedHeight = $('#myWork').outerHeight();
	$hrefVal = $(this).attr('href');
	$("#porfolioContainer").hide(0,  function(){  
		  $('#myWork').css('height', $storedHeight);
		   $.ajax({
		  url: "?p=recent",
		  data: $hrefVal,
		  type: "GET",
		  async: true,
		  cache: false,
		  success: function(html){
			$("#porfolioContainer").html(html);  
			
		   }
	});										  

	})
		
	$("#loading").show();
	return false;
});	
		

/*	
$(window).load(function () {
	adjustHeights(); 
	$("#loading").hide();
	$("#content").hide();
	$("#content").css('visibility', 'visible');
	// Instantiate scrollpane again when window is resized
	clearTimeout(doit);
	doit = setTimeout(function(){
		$('.scroll-pane').jScrollPane(); 
		//$('.scroll-pane').css('height', (imgHeight-20));
	}, 500);
	$("#content").fadeIn('slow');
});
*/
