$(document).ready(function(){
			
	$('a[rel*=facebox]').facebox();
	
	// Set up the Slider
	var slideID = 1; // The initial slide (First one)
	var animation_active = false;
	
	var totalSlides = 3;		// IMPORTANT: There are 3 portfolio entries PER SLIDE,
								// so this number should be the total number of SLIDES.
								// Example: 2 slides would equal 6 portfolio entries (3 per slide)
							
	totalPortfolioEntries = totalSlides * 3;
	
	// This sets up the slider panels when you hover over the portfolio thumbs
	for (tempPortfolioNum=1;tempPortfolioNum<=totalPortfolioEntries;tempPortfolioNum=tempPortfolioNum+1) 
	{
		if (animation_active == false) {
			$("div.hoverBlock #portfolioEntry_"+tempPortfolioNum).hover(function(){
				$(this).find("img").animate({top:"290px"},{queue:false,duration:250});
			}, function(){
				$(this).find("img").animate({top:"0px"},{queue:false,duration:400});
			});
		}
	}
	
	// Bump the slides over to fix an alignment problem
	for (tempSlideNum=1;tempSlideNum<=totalSlides;tempSlideNum=tempSlideNum+1) 
	{
		$("#slide-"+tempSlideNum).find(".entry-1").animate({left:"10px"},{duration:0});
		$("#slide-"+tempSlideNum).find(".entry-2").animate({left:"10px"},{duration:0});
		$("#slide-"+tempSlideNum).find(".entry-3").animate({left:"10px"},{duration:0});
	}
	
	// This initially hides all of the slides except the first one
	for (tempSlideNum=2;tempSlideNum<=totalSlides;tempSlideNum=tempSlideNum+1) 
	{
		$("#slide-"+tempSlideNum).hide();
		$("#slide-"+tempSlideNum).find(".grid_4").hide();
	}
	
	// NEXT SLIDE
	$("div.pagination").click(function(event){
														  
		if (this.id != slideID && animation_active == false) {
			
			animation_active = true;
			
			if (this.id == "next") {
				if (slideID != totalSlides) {
					whatClicked = "next";
					newslideID = slideID + 1;
					abort = false;
					if (newslideID != totalSlides) {
						$("#portfolio").find('#next').removeClass("inactive");
						$("#portfolio").find('#previous').removeClass("inactive");
					} else {
						$("#portfolio").find('#next').addClass("inactive");
						$("#portfolio").find('#previous').removeClass("inactive");
					}
				} else {
					abort = true;
				}
			} else {
				if (slideID != 1) {
					whatClicked = "previous";
					newslideID = slideID - 1;
					abort = false;
					if (newslideID != 1) {
						$("#portfolio").find('#previous').removeClass("inactive");
						$("#portfolio").find('#next').removeClass("inactive");
					} else { 
						$("#portfolio").find('#previous').addClass("inactive");
						$("#portfolio").find('#next').removeClass("inactive");
					}
				} else {
					abort = true;
				}
			}
			
			if (abort == true) {
				animation_active = false;
			} else {
				
				if (whatClicked == "next") {
					positionOne = "-1200px";
					positionTwo = "1200px";
					positionThree = "10px";
					speedOne = 500;
					speedTwo = 550;
					speedThree = 600;
					entryOne = 1;
					entryThree = 3;
				}
				
				if (whatClicked == "previous") {
					positionOne = "1200px";
					positionTwo = "-1200px";
					positionThree = "10px";
					speedOne = 500;
					speedTwo = 550;
					speedThree = 600;
					entryOne = 3;
					entryThree = 1;
				}
		
				$("#slide-"+slideID).find(".entry-"+entryOne).animate({left:positionOne},{duration:500, easing:"easeInQuint"});
				$("#slide-"+slideID).find(".entry-2").animate({left:positionOne},{duration:550, easing:"easeInQuint"});
				$("#slide-"+slideID).find(".entry-"+entryThree).animate({left:positionOne},600, "easeInQuint", function(){
																
					$("#slide-"+slideID).hide();
					$("#slide-"+slideID).find(".grid-4").hide();
					
					// Wait until the above has finished, then do the rest
		
					slideID = newslideID;
					
					$("#slide-"+slideID).find(".entry-1").css("left",positionTwo);
					$("#slide-"+slideID).find(".entry-2").css("left",positionTwo);
					$("#slide-"+slideID).find(".entry-3").css("left",positionTwo);
					
					$("#slide-"+slideID).show();
					$("#slide-"+slideID).find(".entry-1").show();
					$("#slide-"+slideID).find(".entry-2").show();
					$("#slide-"+slideID).find(".entry-3").show();
					
					$("#slide-"+slideID).find(".entry-"+entryOne).animate({left:positionThree},{duration:500, easing:"easeOutExpo"});
					$("#slide-"+slideID).find(".entry-2").animate({left:positionThree},{duration:550, easing:"easeOutExpo"});
					$("#slide-"+slideID).find(".entry-"+entryThree).animate({left:positionThree},600, "easeOutExpo", function(){
					
						animation_active = false;

					});
					
				});
			
			}
		
		}
		
	});

});
