                                                                                                                                                                  
playAllMode = false;  
videoPlaying = false;

$(document).ready(function()
{    
	
	$('#aboutContent').fadeOut(0);
	$('#contactContent').fadeOut(0);
	
	var aboutOpen = false;
	var contactOpen = false; 
	
	var videoArray = [['video0.html', 'Mini - "Cram It in the Boot"<br/>Butler, Shine, Stern & Partners<br>Dir: Bryan Buckley', '655 540'],
					 ['video1.html', 'BMW - "Fact"<br/>Grey - Los Angeles', '655 540'], 
					 ['video2.html', 'Kia - "Research"<br/>David & Goliath<br>Dir: Gerard de Thame', '655 540'], 
				     ['video3_5.html', 'Harley Davidson - "Unchained"<br/>Victors &amp; Spoils<br/>Dir: Geordie Stephens', '655 540'],
					 ['video3.html', 'Taco Bell - "Black Taco"<br/>Draft FCB<br/>Dir: The Russo Bros. / RSA', '655 540'],
				     ['video4.html', 'Sprint - "Convergence"<br/>Goodby Silverstein & Partners<br/>Dir: Randy Stowell', '655 540'], 
				     ['video5.html', 'End War - "EndWar"<br/>Ubisoft<br/>Dir: Jim Sonzero', '655 540'],
				     ['video6.html', 'Honda - "Coming Together"<br/>Muse Communications<br/>Dir: Marcus Rayboy', '655 540'],
				     ['video7.html', 'Lexus - "Obstacles"<br/>Team One<br/>Dir: Selby', '655 540'],
				     ['video9.html', 'Brothers In Arms - "Bad Sally"<br/>Ubisoft<br/>Dir: Robert Hales', '655 540']						
			       ];
    
    $('#navReel').click(function() 
	{	   
	    playAllMode = true;	
		Mediabox.open(videoArray, 0);				
	}); 
	
	$('#playAll').click(function() 
	{            	   
	    playAllMode = true;
	    Mediabox.open(videoArray, 0);  				
	});

	$('#navAbout').click(function() 
	{   
		if(!aboutOpen)
		{
			$('#aboutContent').css('visibility', 'visible');
			$('#aboutContent').delay(250).slideDown(400);
		    $('#contactContent').fadeOut('fast');
			aboutOpen = true; 
			contactOpen = false;
		} else {
			$('#aboutContent').fadeOut(300);
			aboutOpen = false; 
		}
		
	}); 
	
	$('#navContact').click(function() 
	{   
		if(!contactOpen)
		{
			$('#contactContent').css('visibility', 'visible');  
			$('#aboutContent').fadeOut('fast');
			$('#contactContent').delay(250).slideDown(400);
			contactOpen = true;
			aboutOpen = false;
		} else {
			$('#contactContent').fadeOut(300);
			contactOpen = false; 
		}
	   
	}); 
	
	$('#logo').click(function() 
	{  		
		$('#contactContent').fadeOut(300);  
		$('#aboutContent').fadeOut(300);  
			   
		contactOpen = false;
		aboutOpen = false;
	   
	});
	
	
	
	
	$('#arrowRight').click(function() { 
		$('#footerThumbsMain').animate({ left:-400}, 300);
	});
    

	// thumbnail rollover image change
    $(function() {
	    $('.rollover').hover(function() {
	        var currentImg = $(this).attr('src');
	        $(this).attr('src', $(this).attr('hover'));
	        $(this).attr('hover', currentImg);
	    }, function() {
	        var currentImg = $(this).attr('src');
	        $(this).attr('src', $(this).attr('hover'));
	        $(this).attr('hover', currentImg);
	    });
	});
	
	
	// preload thumbs
	(function($) {
	  var cache = [];
	  // Arguments are image paths relative to the current page.
	  $.preLoadImages = function() {
	    var args_len = arguments.length;
	    for (var i = args_len; i--;) {
	      var cacheImage = document.createElement('img');
	      cacheImage.src = arguments[i];
	      cache.push(cacheImage);
	    }
	  }
	})(jQuery)
	 
	
	jQuery.preLoadImages("images/thumb_mini2.jpg", "images/thumb_bmw2.jpg", "images/thumb_kia_agency2.jpg", "images/thumb_harley2.jpg", "images/thumb_black_jack_taco2.jpg", "images/thumb_sprint_convergence2.jpg", "images/thumb_end_war2.jpg", "images/thumb_coming_together2.jpg", "images/thumb_lexus_obstacles2.jpg", "images/thumb_your_shape2.jpg", "images/thumb_bad_sally2.jpg", "images/nav_reel2.png", "images/nav_about2.png", "images/nav_contact2.png", "images/nav_client_area2.png", "images/nav_facebook2.png", "images/nav_twitter2.png",
	"images/bg2.jpg");
	  
	
	// thumb slider config
   	jQuery('#mycarousel').jcarousel({    
		animation:450,
        scroll:5   	   
	});
	
	
	
	
	
    // backgrounds 
  
    // randomizes array
	function fisherYates ( myArray ) {
	  var i = myArray.length;
	  if ( i == 0 ) return false;
	  while ( --i ) {
	     var j = Math.floor( Math.random() * ( i + 1 ) );
	     var tempi = myArray[i];
	     var tempj = myArray[j];
	     myArray[i] = tempj;
	     myArray[j] = tempi;
	   }
	}
	  
    var bgs = ["images/bg1.jpg", "images/bg2.jpg", "images/bg3.jpg"]; 
	fisherYates(bgs);
	var curBgIndex = 0;
	setInterval(fadeOut, 20000);
	nextBG();
	       	
    function nextBG()
	{
	    $.backstretch(bgs[curBgIndex], {speed: 1000, centeredX:true, centeredY:true } ); 
	    curBgIndex = (curBgIndex == bgs.length-1) ? curBgIndex = 0 : curBgIndex+=1;  
	} 
	
	function fadeOut()
	{   
		if(videoPlaying) return;
		$('#backstretch').fadeOut(600, nextBG);   		
	}  
    
	


	
});
   
