// remap jQuery to $

     
      
(function($){})(window.jQuery);

(function($){
 
    $.fn.shuffle = function() {
 
        var allElems = this.get(),
            getRandom = function(max) {
                return Math.floor(Math.random() * max);
            },
            shuffled = $.map(allElems, function(){
                var random = getRandom(allElems.length),
                    randEl = $(allElems[random]).clone(true)[0];
                allElems.splice(random, 1);
                return randEl;
           });
 
        this.each(function(i){
            $(this).replaceWith($(shuffled[i]));
        });
 
        return $(shuffled);
 
    };
 
})(jQuery);


function slideshow(selector,speed,timeout) {
	 $(selector+' img:gt(0)').hide();
    setInterval(function(){
      $(selector+' :first-child').fadeOut(speed)
         .next('img').fadeIn(speed)
         .end().appendTo(selector);}, 
      timeout);
}


/* trigger when page is ready */
$(document).ready(function (){


	// your functions go here
	if ($('#team').length > 0) {
		$('#team .photo:gt(0), #team .bio:gt(0)').hide();
		$('.showbio:eq(0)').addClass('selected');
		$('#team .showbio').click(function(){
			ind = $(this).index();
			$('#team .photo, #team .bio').hide();
			$('#team .photo:eq('+ind+'), #team .bio:eq('+ind+')').show();
			$('.showbio').removeClass('selected');
			$(this).addClass('selected');
		})
	}
	
	if ($('#gallery').length > 0) {
		$('#gallery img').css('position','absolute');
		$('#gallery img').shuffle();
		slideshow('#gallery',1000,10000);
	}
	
	//animation to make the each page appear from white
 		$('#page-wrap').hide().delay(1500).fadeIn(1000);
	    
	     if ($('BODY').hasClass('home')) {
	      $('#page-wrap').delay(1500).fadeIn(1000);
	      $('#footer-content').delay(1500).fadeIn(1000);
	     }else{
	      $('#page-wrap').delay(1500).fadeIn(300);
	      $('#footer-content').delay(1500).fadeIn(350);
	     }
	     
	     $('#gallery').hide().delay(700).fadeIn(1000);
	     
	
});

