// JavaScript Document
$(document).ready(function() {

randomBackground();

//begin slideshow code

   getSrcs();
   $('.floatLeftSlideShow').hide();
   $('.floatLeftSlideShow').first().show();
   makeArrowButtons();
  $('.bgButtonArrowRight').click(nextImage);
   $('.bgButtonArrowLeft').click(prevImage);
  

//end slideshow code

$('.expandcontract').text("expand ");
$('.goto').text("go to ");
$('.open').text("open ");
//$('.content').hide();
$('.updown').addClass('bgButtonArrowDown');
$('.forward').addClass('bgButtonArrowForward');
$('.back').addClass('bgButtonArrowBack');
$('.external').addClass('bgButtonArrowExternal');
$('.email').addClass('bgButtonEmail');
$('.pdf').addClass('bgButtonPDF');
$('.01').addClass('bgButton01');
$('.02').addClass('bgButton02');
$('.03').addClass('bgButton03');
$('.04').addClass('bgButton04');
$('.05').addClass('bgButton05');
$('.06').addClass('bgButton06');
$('.07').addClass('bgButton07');
$('.08').addClass('bgButton08');
$('.09').addClass('bgButton09');
						   



$('.bgButton01').click(bg01);
$('.bgButton02').click(bg02);
$('.bgButton03').click(bg03);
$('.bgButton04').click(bg04);
$('.bgButton05').click(bg05);
$('.bgButton06').click(bg06);
$('.bgButton07').click(bg07);
$('.bgButton08').click(bg08);
$('.bgButton09').click(bg09);
$('.bgButtonArrowUp').toggle(arrowOut,arrowIn);





$('.updown').toggle(arrowdown,arrowup);

/*function gothere() { open('http://www.google.com', 'theWin', 'height=200,width=200');}*/


$('#goBEARS').click(function(){window.location='scaredbears.html'});
$('#goFALCORPS').click(function(){window.location='falcorps.html'});
$('#goMORNINGSIDE').click(function(){window.location='morningside.html'});
$('#goEYES').click(function(){window.location='covenant_eyes.html'});
$('#goTAX').click(function(){window.location='tax_geek.html'});
$('#goAIGA').click(function(){window.location='aiga_poster.html'});
$('#goBloc').click(function(){window.location='bloc_fashion.html'});
$('#goContact').click(function(){window.location='contact.html'});
$('#goDesign').click(function(){window.location='design.html'});
$('#goHome').click(function(){window.location='index.html'});
$('#goMap').click(function(){window.location='law_student_map.html'});
$('#goPhoto').click(function(){window.location='photo.html'});
$('#goReview').click(function(){window.location='portfolio_reviews_poster.html'});
$('#goWharton').click(function(){window.location='wharton.html'});
$('#goLink').click(function(){open('http://www.linkedin.com/in/njcrandall')});
$('#goMail').click(function(){window.location='mailto:njcrandall@gmail.com'});
$('#goResume').click(function(){open('njcrandall_resume.pdf')});
$('#goSweet').click(function(){open('brownie.pdf')});



//begin photo page script

$('.photoPagePhoto').hide();
$('#bs1').click(function(){$('.photoPagePhoto').hide();$('#ps1').show();});
$('#bs2').click(function(){$('.photoPagePhoto').hide();$('#ps2').show();});
$('#bs3').click(function(){$('.photoPagePhoto').hide();$('#ps3').show();});
$('#bs4').click(function(){$('.photoPagePhoto').hide();$('#ps4').show();});
$('#bg1').click(function(){$('.photoPagePhoto').hide();$('#pg1').show();});
$('#bg2').click(function(){$('.photoPagePhoto').hide();$('#pg2').show();});
$('#bg3').click(function(){$('.photoPagePhoto').hide();$('#pg3').show();});
$('#be1').click(function(){$('.photoPagePhoto').hide();$('#pe1').show();});
$('#be2').click(function(){$('.photoPagePhoto').hide();$('#pe2').show();});
$('#be3').click(function(){$('.photoPagePhoto').hide();$('#pe3').show();});
$('#bb1').click(function(){$('.photoPagePhoto').hide();$('#pb1').show();});
$('#bb2').click(function(){$('.photoPagePhoto').hide();$('#pb2').show();});
$('#bb3').click(function(){$('.photoPagePhoto').hide();$('#pb3').show();});
$('#bb4').click(function(){$('.photoPagePhoto').hide();$('#pb4').show();});
$('#br1').click(function(){$('.photoPagePhoto').hide();$('#pr1').show();});
$('#br2').click(function(){$('.photoPagePhoto').hide();$('#pr2').show();});
$('#bot1').click(function(){$('.photoPagePhoto').hide();$('#pot1').show();});
$('#bot2').click(function(){$('.photoPagePhoto').hide();$('#pot2').show();});
$('#bot3').click(function(){$('.photoPagePhoto').hide();$('#pot3').show();});


//end photo page script




						  
						   });

function bg01() {$('body').css('background-image', 'url(images/backgroundPatterns/bgPattern01.png)');}
function bg02() {$('body').css('background-image', 'url(images/backgroundPatterns/bgPattern02.png)');}
function bg03() {$('body').css('background-image', 'url(images/backgroundPatterns/bgPattern03.png)');}
function bg04() {$('body').css('background-image', 'url(images/backgroundPatterns/bgPattern04.png)');}
function bg05() {$('body').css('background-image', 'url(images/backgroundPatterns/bgPattern05.png)');}
function bg06() {$('body').css('background-image', 'url(images/backgroundPatterns/bgPattern06.png)');}
function bg07() {$('body').css('background-image', 'url(images/backgroundPatterns/bgPattern07.png)');}
function bg08() {$('body').css('background-image', 'url(images/backgroundPatterns/bgPattern08.png)');}
function bg09() {$('body').css('background-image', 'url(images/backgroundPatterns/bgPattern09.png)');}
function arrowIn() {$(this).next('#compartment').show();}
function arrowOut() {$(this).next('#compartment').hide();}

function arrowup() {
	$(this).next('.thetitlepluscontent').children('.content').hide();
	$(this).next('.thetitlepluscontent').find('.expandcontract').text("expand ");
	$(this).removeClass('bgButtonArrowUp');
	$(this).addClass('bgButtonArrowDown');
	}
function arrowdown() {
	$(this).next('.thetitlepluscontent').children('.content').show();
	$(this).next('.thetitlepluscontent').find('.expandcontract').text("contract ");
	$(this).removeClass('bgButtonArrowDown');
	$(this).addClass('bgButtonArrowUp');
	}
	
function randomBackground(){
	
	var backgroundNumber = Math.floor(Math.random()*9 +1);


var background;

if(backgroundNumber == 1){
	$('body').css('background-image', 'url(images/backgroundPatterns/bgPattern01.png)');}
if(backgroundNumber == 2){
	$('body').css('background-image', 'url(images/backgroundPatterns/bgPattern02.png)');}
if(backgroundNumber == 3){
	$('body').css('background-image', 'url(images/backgroundPatterns/bgPattern03.png)');}
if(backgroundNumber == 4){
	$('body').css('background-image', 'url(images/backgroundPatterns/bgPattern04.png)');}
if(backgroundNumber == 5){
	$('body').css('background-image', 'url(images/backgroundPatterns/bgPattern05.png)');}
if(backgroundNumber == 6){
	$('body').css('background-image', 'url(images/backgroundPatterns/bgPattern06.png)');}
if(backgroundNumber == 7){
	$('body').css('background-image', 'url(images/backgroundPatterns/bgPattern07.png)');}
if(backgroundNumber == 8){
	$('body').css('background-image', 'url(images/backgroundPatterns/bgPattern08.png)');}
if(backgroundNumber == 9){
	$('body').css('background-image', 'url(images/backgroundPatterns/bgPattern09.png)');}
	
}



//slideshow functions

var index = 0;
var indexMax = 0;

function getSrcs() {
	 $('.floatLeftSlideShow').each(function(i){indexMax++;						  });	 
}

function nextImage(){
	if(index < indexMax-1){
	$('.floatLeftSlideShow').eq(index+1).show();
	$('.floatLeftSlideShow').eq(index).hide();
	index++;
	}else{
		$('.floatLeftSlideShow').eq(0).show();
		$('.floatLeftSlideShow').eq(indexMax-1).hide();
		index = 0;
	}
}

function prevImage(){
	if(index > 0){
		$('.floatLeftSlideShow').eq(index-1).show();
		$('.floatLeftSlideShow').eq(index).hide();
		index--;
	}else{
		$('.floatLeftSlideShow').eq(indexMax-1).show();
		$('.floatLeftSlideShow').eq(0).hide();
		index = indexMax-1;
	}
}

function makeArrowButtons(){
	$('.floatLeftSlideShow:last').parent().after('<div class="theSlideShowArrows"><span class="bgButtonArrowLeft"></span><span class="bgButtonArrowRight"></span></div>'); 	
}

//end slideshow functions
