// -------------------------------------------------------------------------------------
// GLOBALS
// -------------------------------------------------------------------------------------
var portfolio_open = false;
var view_small = "290px";
var view_large = "400px";
var view_width = "878px"
var thumb_small = "93px";
var thumb_large = "280px";
// -------------------------------------------------------------------------------------
// DOCUMENT READY
// -------------------------------------------------------------------------------------
$(document).ready(function() {

	$('.portfolio').hover(
		function(){	$('#portfolio-text').css('color','#fff'); },
		function(){ $('#portfolio-text').css('color','#999'); }
	);
	
	$('.portfolio').click(function(){
	   if(portfolio_open==false) {
			portfolioOpen();
	   } else {
			portfolioClose();
	   }
	});

	$('#slidethumbs img.thumb').hover(
		function(){	$(this).fadeTo(250,'1.0'); },
		function(){ $(this).fadeTo(500,'0.5'); }
	);

	$('#slidethumbs img.thumb').click(function(){
		var newSlide = $(this).attr('id');
		if(portfolio_open==false) {
			portfolioOpen(newSlide);
		} else {
			swapSlide(newSlide);
		}
	});

	$('#featuredWork').click(function(){portfolioOpen('website_goproductions');});

});
// -------------------------------------------------------------------------------------
// FUNCTION DEFINITIONS
// -------------------------------------------------------------------------------------

function swapSlide(newSlide) {
	// special case for flyers
	if (newSlide=="flyer_cabana" || newSlide=="flyer_shag" || newSlide=="flyer_ritual") { newSlide = "flyer_all"; }
	$('#slideshow .slide').animate({ opacity: "0", backgroundPosition: view_width + " 0" }, 400, function() {
		$('#slideshow .slide').attr('style','background: url(images/portfolio/' + newSlide + '.jpg) top no-repeat; height: ' + view_large + '; opacity: 0;');	 
	});
	$('#slideshow .slide').animate({ opacity: "1" }, 400);
}

function portfolioOpen(newSlide) {  // optional newSlide variable
	$('.buttontext').css('color','#fff');
	$('#expand').attr('src','images/btn_contract.png');
	$('#slidethumbs').animate({height:thumb_large}, 500, function(){ 
		$('#slideshow .slide').animate({height:view_large}, 500);	
		$('.box').slideUp(800);
		$('#portfolioText').text("[-] Exit Portfolio Mode");
		if(newSlide!=undefined) { swapSlide(newSlide); }  // this is in here to delay the swapping
		portfolio_open = true;
	});	
}

function portfolioClose() {
	$('.buttontext').css('color','#999');
	$('#expand').attr('src','images/btn_expand.png');
	$('#slidethumbs').animate({height:thumb_small}, 800, function(){ 
		$('.box').slideDown(500);
		$('#slideshow .slide').animate({height:view_small}, 500);
		$('#portfolioText').text("[+] Portfolio Mode");
		portfolio_open = false;
	});
}
