// Set for Zoom In/Zoom Out
var projectArrayW = new Array();
var projectArrayH = new Array();

var vid_array = new Array();
var vid_array_src = new Array();
var vid_array_w = new Array();
var vid_array_h = new Array();

var campaign = new Array();

var v = 0;

var flash_array = new Array();

function loadDesign(){
	var w=0;
	var h=0;
	var window_width =  $(window).width();
	var window_height = $(window).height();
	var image_width = $('.fullbleed').width();
	var image_height = $('.fullbleed').height();

	var ratio = window_width/window_height;
	var ratio2 = image_width/image_height;
	if (ratio > ratio2){
		w = window_width;
		h = (w * image_height)/image_width;
		var topVar = (h-window_height)/2;
		topVar = -1*topVar;
	} else {
		h = window_height;
		w = (h * image_width)/image_height;
		var leftVar = (w-window_width)/2;
		leftVar = -1*leftVar;
	}

	$('.fullbleed').attr('style','position:relative;top:'+topVar+'px;left:'+leftVar+';');
	$('.fullbleed').attr('width', w);
	$('.fullbleed').attr('height', h);

	var footerTop = window_height-25;

	/* Position Footer */
	$('footer').css('top',footerTop+'px');
	footer=0;
	$('#thumbnailHeader').removeClass();
	$('#thumbnailHeader').addClass('arrowUp');
}

//FOR HOMEPAGE
var gallery = new Array();
var counter = 0;

function loadImages() {	
			// Define images for Gallery
			gallery[0] = new Image();
  			gallery[0].src = "images/bg/bg_1.jpg";
  			gallery[1] = new Image();
  			gallery[1].src = "images/bg/bg_2.jpg";
 			gallery[2] = new Image();
  			gallery[2].src = "images/bg/bg_1.jpg";
  			gallery[3] = new Image();
  			gallery[3].src = "images/bg/bg_2.jpg";
  			gallery[4] = new Image();
  			gallery[4].src = "images/bg/bg_1.jpg";
  			gallery[5] = new Image();
  			gallery[5].src = "images/bg/bg_2.jpg";
  			gallery[6] = new Image();	
  			gallery[6].src = "images/bg/bg_1.jpg";
  			gallery[7] = new Image();
  			gallery[7].src = "images/bg/bg_2.jpg";
  			gallery[8] = new Image();
  			gallery[8].src = "images/bg/bg_1.jpg";
  			gallery[9] = new Image();
  			gallery[9].src = "images/bg/bg_2.jpg";
  			gallery[10] = new Image();
  			gallery[10].src = "images/bg/bg_1.jpg";
			gallery[11] = new Image();
  			gallery[11].src = "images/bg/bg_2.jpg";
			
			//Load Images into divs
			function loadIntoDivs(x){
				if(counter!=12) {
				$('#homeStage').append("<div class='bg-image'><img src="+gallery[x].src+" width="+gallery[x].width+" height="+gallery[x].height+" id='"+x+"'alt='Background "+x+"'/></div>");
				var window_width =  $(window).width();
				var window_height = $(window).height();
				$('.bg-image').width(window_width);
	
				image_width = gallery[x].width;
				image_height = gallery[x].height;
				w=window_width;
				h = (window_width * image_height)/image_width;

				topVar = (h-window_height)/2;
				$("#"+x).attr('width', w);
				$("#"+x).attr('height', h);
				$("#"+x).attr('style','position:relative;top:-'+topVar+'px;')
				counter++
				startBG();
			} else{
				var t=setTimeout("timerFun();",10000);
				counter=0;
			}
		}
		function startBG(){
			loadIntoDivs(counter);
		}

		startBG();
}

function startBG(){
	if (counter!=13){
		loadIntoDivs(counter);
	}
}
// Image Timer
function timerFun(){
	slideImage();
	counter++;
	var t=setTimeout("timerFun();",10000);
}

function slideImage(x){
	var window_width =  $(window).width();
	$("#homeStage").animate({
		    left: '-=100%'
		  }, 800, function() {
		    // Animation complete.
		    if(counter==10){
		    	$("#homeStage").css('left',0);
		    	counter=0;
		    }
	  	});
}

function loadHomepage(){
	var window_width = $(window).width();
	var window_height = $(window).height();
	var src = 'vid/V4no';
	var vid_width = 1080;
	var vid_height = 720;

	// RESIZE VIDEO
	var ratio = window_width/window_height;
	var ratio2 = vid_width/vid_height;
	if (ratio > ratio2){
		w = window_width;
		h = (w * vid_height)/vid_width;
	} else {
		h = window_height;
		w = (h * vid_width)/vid_height;
	}
	


	//$('.bg-image').width(window_width);

	var topVar = (h-window_height)/4;
	topVar = -1*topVar;
	var leftVar = (w-window_width)/2;
	leftVar = -1*leftVar;


	i = 'main';
	$("<div id='videoBox' class='video-js-box hu-css'><!-- Using the Video for Everybody Embed Code http://camendesign.com/code/video_for_everybody --><video id=\'video_"+i+"\'class='video-js' width="+w+" height="+h+" autobuffer autoplay><source src='"+src+".mp4' type='video/mp4; codecs=\"avc1.42E01E, mp4a.40.2\"' /><source src='"+src+".webm' type='video/webm; codecs=\"vp8, vorbis\"' /><source src='"+src+".ogv' type='video/ogg; codecs=\"theora, vorbis\"' /><!-- Flash Fallback. Use any flash video player here. Make sure to keep the vjs-flash-fallback class. --><object id='flash_fallback_1' class='vjs-flash-fallback' width="+w+" height="+h+" type='application/x-shockwave-flash' data='js/flowplayer-3.2.7.swf'><param name='movie' value='js/flowplayer-3.2.7.swf' /><param name='wmode' value='transparent' /><param name='allowfullscreen' value='true' /><param name=\"flashvars\" value=\'config=\{\"playlist\"\:\[\"images/spacer_black.png\", \{\"url\": \"http://www.bc-p.com/BCU/"+src+".mp4\",\"autoPlay\":true,\"autoBuffering\":true\}\]\}' />><!-- Image Fallback. Typically the same as the poster image. --></object></video></div>").appendTo('#homeStage');
	//$("#"+i).attr('css','position:relative;top:-'+topVar+'px;')
	
	//$("#videoBox").css('left',leftVar);

	// FIX IE6
		var fail = 0;
		if (jQuery.browser.msie) {
  			if(parseInt(jQuery.browser.version) == 6) {
    		 fail = 1;
  			}
		}
		if (fail == 0) {
			// After load : initialize videoJS
			var myPlayer = VideoJS.setup("video_main");


		// TURN SOUND OFF
    	myPlayer.volume(0);

		$("#video_main")[0].onended = function(e) {
			myPlayer.currentTime(0);
				myPlayer.play();
		}
		var t =setTimeout('playHome();',800);
		}

	var z =setTimeout('loopHome();',57000);

	$(".hu-css div.vjs-big-play-button").hide();
}
function loopHome(){
	$('#homeStage').empty();
	loadHomepage();
}
function resizeHomepage(){
	var window_width = $(window).width();
	var window_height = $(window).height();
	var vid_width = 1080;
	var vid_height = 720;

	$('.bg-image').width(window_width);
	$('.bg-image').height(window_height);

	// RESIZE VIDEO
	var leftVar = 0;
	
	var ratio = window_width/window_height;
	var ratio2 = vid_width/vid_height;
	if (ratio > ratio2){
		w = window_width;
		h = (w * vid_height)/vid_width;
	} else {
		h = window_height;
		w = (h * vid_width)/vid_height;
		var leftVar = (w-window_width)/2;
		leftVar = -1*leftVar;
	}
	
	//$("#video_main")[0].player.height(h);
	//$("#video_main")[0].player.width(w);
  	$('video').width(w);
  	$('video').height(h);


	var topVar = (h-window_height)/4;
	topVar = -1*topVar;
	$("#videoBox").css('top',topVar);
	$("#videoBox").css('left',leftVar);

}

var numItems = 0;
var currentTalent = 'ewen';
function loadTalent(){
	maxImg=0;
	// Load XML
	 $.get('xml/talent.xml', function(d){		 
		 // Load Client Thumbnails
		 var i = 0;
    	$(d).find('item').each(function(n) {
			i ++;
			maxImg++;
			var $xml = $(this);
			var name = $xml.find('name').text();
			var string = $xml.find('string').text();
			var bio = $xml.find('bio').text();
			$('#talentContainer').append("<div class='talentSlide' ><div id=\'"+string+"\' class='name'></div><div class='copy' ><p>"+bio+"</p></div></div>").appendTo('fullbleed');
			$('#'+string).append("<img src='images/people/n_"+string+".png' width='190' height='56' alt="+name+" />");
			
			$('#homeStage').append("<div class='bg-image'><img src='images/people/"+string+".jpg' width='1600' height='1080' id=\'"+i+"\' class="+string+" /></div>");

				$('#thumbnails').append("<a href='#'  onclick='talentClick(\""+string+"\");return false;'><img src='images/people/"+string+".jpg' width='116' height='74' class='thumbnail'/></a>");
				var window_width =  $(window).width();
				var window_height = $(window).height();
				$('.bg-image').width(window_width);
	
				image_width = $('#'+i+"_talent").width();
				image_height = $('#'+i+"_talent").height();
				w=window_width;
				h = (window_width * image_height)/image_width;

				topVar = (h-window_height)/4;
				$("."+string).attr('width', w);
				$("."+string).attr('height', h);
				$("."+string).attr('style','position:relative;top:-'+topVar+'px;')

				//
				var a = $(window).width();
				a = (a*60)/100;
				b =  window_width - (a+356);

				var c = window_height;
				c = (c-67)-358;
				c = c/2;

				var d = $(window).height-(c+$('.talentSlide').height);

				$('.talentSlide').css('margin-left',a);
				$('.talentSlide').css('margin-right',b);
				$('.talentSlide').css('margin-top',c);

        });
	}).complete(function(){
			thumbHeight();
		}); //get close
	
	// set Thumbnail height after quick delay to allow XML LOAD
	//var t =setTimeout('thumbHeight();',800);	
}
//
//
//
// RESIZING
function resizeMain(){
	//resize talentSlide
				var window_width =  $(window).width();
				var window_height = $(window).height();
				
				//FIX BG SIZE
				$('.bg-image').width(window_width);
				// SET CURRENT IMG* WINDOW WIDTH TO CSS FOR TALENT SLIDE
					var wicked = (current_talent-1)*$(window).width();
					$('#homeStage').css('left','-'+wicked+'px');

		$('#fullbleed img').each(function(){
			// resizeImages
			//resize talentSlide
				image_width = $(this).width();
				image_height = $(this).height();
				w=window_width;
				h = (window_width * image_height)/image_width;

				$(this).width(w);
				$(this).height(h);

		});
}

function resizeTalent(){
	//resize talentSlide
				var window_width =  $(window).width();
				var window_height = $(window).height();
				
				var a = $(window).width();
				a = (a*60)/100;
				b =  window_width - (a+356);

				var c = window_height;
				c = (c-67)-358;
				c = c/2;

				var d = $(window).height-(c+$('.talentSlide').height);

				$('.talentSlide').css('margin-left',a);
				$('.talentSlide').css('margin-right',b);
				$('.talentSlide').css('margin-top',c);
				//FIX BG SIZE
				$('.bg-image').width(window_width);
				// SET CURRENT IMG* WINDOW WIDTH TO CSS FOR TALENT SLIDE
					var wicked = (current_talent-1)*$(window).width();
					$('.talentSlide').css('left','-'+wicked+'px');
					$('#homeStage').css('left','-'+wicked+'px');

		$('#fullbleed img').each(function(){
			// resizeImages
			//resize talentSlide
				image_width = $(this).width();
				image_height = $(this).height();
				w=window_width;
				h = (window_width * image_height)/image_width;

				$(this).width(w);
				$(this).height(h);

		});
}
function resizeVideo(){
	var window_width =  $(window).width();
	var window_height = $(window).height();
	
	//FIX BG SIZE
  				$('.bg-image').width(window_width);
				$('.bg-image').height(window_height);
	
	var tempVar = "#video_"+currentImg;
		$('#videoBox').each(function(){
				vid_width = $('video').width();
				vid_height = $('video').height();
  				
				// RESIZE VIDEO
				var ratio = window_width/window_height;
				var ratio2 = vid_width/vid_height;
				if (ratio > ratio2){
					w = window_width;
					h = (w * vid_height)/vid_width;
					var leftVar = 0;
				} else {
					h = window_height;
					w = (h * vid_width)/vid_height;
					var leftVar = (w-window_width)/2;
					leftVar = -1*leftVar;
				}

				$('video').width(w);
  				$('video').height(h);

  				topVar = (h-window_height)/2;
				topVar = topVar*-1;
				topVar = Math.round(topVar);
				$("#videoBox").css('top',topVar+'px');
				$("#videoBox").css('left',leftVar+'px');

		});

}
function resizeProjects(){
	//resize talentSlide;
				var window_width =  $(window).width();
				var window_height = $(window).height();
				
				//FIX BG SIZE
  				$('.bg-image').width(window_width);
				$('.bg-image').height(window_height);
				// SET CURRENT IMG* WINDOW WIDTH TO CSS FOR TALENT SLIDE
				var wicked = (currentImg-1)*$(window).width();
				$('#homeStage').css('left','-'+wicked+'px');


		$('#fullbleed img').each(function(){
			// resizeImages
				image_width = $(this).width();
				image_height = $(this).height();
				
				h = window_height-(100+24+60);
				w = (image_width * h)/image_height;
				w = Math.round(w);
				topVar = 75;
				leftVar = (window_width-(w+20))/2;

				$(this).attr('width', w);
				$(this).attr('height', h);
				imageNum = $(this).attr('id')
				$("#print_"+imageNum).css('width', w);
				$("#print_"+imageNum).css('height', h+40);
				$("#print_"+imageNum).css('top',topVar);
				$("#print_"+imageNum).css('left',leftVar);
		});

			

		//this SWFs
		$('#thumbnailHeader').removeClass();
		$('#thumbnailHeader').addClass('arrowUp');
}

function resizeCS(){
	//resize talentSlide
				var window_width =  $(window).width();
				var window_height = $(window).height();
				
				//FIX BG SIZE
				$('.bg-image').width(window_width);
				$('.bg-image').height(window_height);
				

				var tempVar = currentImg;
				tempVar = "#video_cs";
				var vid_width = $(tempVar)[0].player.width();
				var vid_height = $(tempVar)[0].player.height();
  				
				// RESIZE VIDEO
				var ratio = window_width/window_height;
				var ratio2 = vid_width/vid_height;
				
				if (ratio > ratio2){
					w = window_width;
					h = (w * vid_height)/vid_width;
					var leftVar = 0;
				} else {
					h = window_height;
					w = (h * vid_width)/vid_height;
					var leftVar = (w-window_width)/2;
					leftVar = -1*leftVar;
				}

				$('video').width(w);
  				$('video').height(h);

  				topVar = (h-window_height)/2;
				topVar = topVar*-1;
				topVar = Math.round(topVar);
				$("#video_cs").css('top',topVar+'px');
}


// CLICKING TALENT
current_talent = 1;
function talentClick(x) {
	var window_width = $(window).width();
	var distance = $('.'+x).attr('id');

	var v = current_talent - distance;
	if (v > 0) {
	// Move backwards
		var electricSlide = '+='+(v*window_width);

	} else {
	// Move forwards
		var electricSlide = '-='+(v*window_width*-1);
	}
	current_talent = distance;
	// Animate
	if (v != 0) {
		$('.talentSlide').animate({
			    left: electricSlide
			  }, 400, function() {
			    // Animation complete.
		  	});
		 $('#homeStage').animate({
			    left: electricSlide
			  }, 400, function() {
			    // Animation complete.
		 });
	}

}

function nextTalent() {
	var window_width = $(window).width();
	if(current_talent != maxTalent){
			current_talent++;
		$('.talentSlide').animate({
			    left: '-='+window_width
			  }, 800, function() {
			    // Animation complete.
		  	});
		 $('#homeStage').animate({
			    left: '-='+window_width
			  }, 800, function() {
			    // Animation complete.
		 });
	}
}
function prevTalent() {
	var window_width = $(window).width();
	if (current_talent != 1){
		current_talent--;
		$('.talentSlide').animate({
			    left: '+='+window_width
			  }, 800, function() {
			    // Animation complete.
		  	});
		 $('#homeStage').animate({
			    left: '+='+window_width
			  }, 800, function() {
			    // Animation complete.
		 });
	}
}

var th = 0;
function thumbHeight() {
	var window_width = $(window).width();
	var maxNum = window_width/136;
	maxNum = Math.round(maxNum);
	var x = maxImg/maxNum;
	if (x<=1){
		x=1;
	}
	if (x>1 && x<2){
		x=2;
	}
	if (x>2 && x<3){
		x=3;
	}
	if (x>3 && x<4){
		x=4;
	}
	th = (x*86)+24;
}
// Next Button
function swapImage(){
		counter ++
		if (counter > 11) {
    		counter = 0;
  		}
		
		//gallery[counter].width
		
	//var w=0;
	//var h=0;
	var window_width =  $(window).width();
	var window_height = $(window).height();
	
	image_width = gallery[counter].width;
	image_height = gallery[counter].height;
	w=window_width;
	h = (window_width * image_height)/image_width;

	topVar = (h-window_height)/2;
	
	$(".fullbleed").fadeOut(800,function(){
		$(".fullbleed").attr({ src: gallery[counter].src});
		$('.fullbleed').attr('width', w);
		$('.fullbleed').attr('height', h);
		$(".fullbleed").fadeIn(800,function(){
			$('.fullbleed').attr('style','position:relative;top:-'+topVar+'px;')
		});
	});
	
}

//FOR ABOUT PAGE
function loadAbout(){
	var window_height = $(window).height();
	var aboutTop = (window_height-544)/2;

	/* Position Div */
	//$('#about').css('margin-top',aboutTop+'px');

	// Load XML
	 $.get('xml/about.xml', function(d){		 
		 // Load Client Thumbnails
		 var i = 0;
		 var n = 0;
    	$(d).find('item').each(function(n) {
			i ++;
			var $xml = $(this);
			var name = $xml.find('name').text();
			var category = $xml.find('category').text();
			var copy = $xml.find('copy').text();
			$('#'+category).append("<div class='slide'>"+copy+"</div>");

        });
	}); //get close
}




var currentSection = 'beliefs';
var travel = 0;
function navChange(x){
	if (currentSection != x){
		//change current section
		$("."+currentSection).removeAttr('id');
		$("."+x).attr('id','current');

		//animate in new section
		switch(x){
			case 'beliefs' :
				if (currentSection=='approach'){
					travel = '+=520';	
				} else {
					travel = '+=1040';
				}
			break;
			case 'approach' :
				if (currentSection=='beliefs'){
					travel = '-=520';	
				} else {
					travel = '+=520';
				}
			break;
			case 'reach' :
				if (currentSection=='approach'){
					travel = '-=520';	
				} else {
					travel = '-=1040';
				}
			break;
		}
		$('#vertSlide').animate({
		    top: travel
		  }, 400, function() {
		    // Animation complete.
		    currentSection=x;
	  	});
	}
}

function nextSlide(x){
	$('#'+x).animate({
		    left: '-=856'
		  }, 400, function() {
		    // Animation complete.
	  	});
}

//FOR THUMBNAILS
var footer=0;

function footerControls(){

	$('#thumbnailHeader').click(function() {
	if (zoomVar==0){
	if(footer==0){
		footer=1;
		
		$('footer').animate({
		    top: '-='+th
		  }, 400, function() {
		    // Animation complete.
		    $('#thumbnailHeader').removeClass();
			$('#thumbnailHeader').addClass('arrowDown');
	  	});
	} else {
		footer=0;
		$('footer').animate({
		    top: '+='+th
		  }, 400, function() {
		    // Animation complete.
			$('#thumbnailHeader').removeClass();
			$('#thumbnailHeader').addClass('arrowUp');
	  	});
	}
}
});
	// animate thumbnails on load
	
}

function animateThumbs(){
	zoomVar=1;
		$('footer').animate({
		    top: '-='+th
		  }, 800, function() {
		    // Animation complete.
		    var t =setTimeout('footerControls();',1000);
		    $('#thumbnailHeader').removeClass();
			$('#thumbnailHeader').addClass('arrowDown');
			zoomVar=0;
			footer=1;
				if (idleVar == 1){
					$.idleTimer(3000);

					$(document).bind("idle.idleTimer", function(){
					 // function you want to fire when the user goes idle
 						$('header').fadeOut();
						 $('footer').fadeOut();
					});
 
					$(document).bind("active.idleTimer", function(){
 						// function you want to fire when the user becomes active again
  						$('header').fadeIn();
 						$('footer').fadeIn();
					});
				}
	  	});
}



var zoomVar = 0;
function zoomOut(){
	zoomVar = 1;
	var t =setTimeout('fixZoom();',300);
	var checkIt = $('#'+currentImg).attr('class');
	var window_height = $(window).height();
	var window_width = $(window).width();
	if (checkIt == 'spread'){
			$('#'+currentImg).removeClass();
			$('#'+currentImg).addClass('zoomOut');
			image_width = $('#'+currentImg).width();
			image_height = $('#'+currentImg).height();	
			h = window_height-(100+24);
			w = (image_width * h)/image_height;
			w = Math.round(w);

			var varH = $('.bg-image').height();
			topVar = (window_height-h)*.85;
			var leftVar = (window_width-w)/2;
			//topVar = topVar + 64;
			$('#'+currentImg).width(w);
			$('#'+currentImg).height(h);
			$('#'+currentImg).css('margin-top',topVar);
			$('#'+currentImg).css('margin-left',leftVar);
	} else {
		var tempVar = "#video_"+currentImg;
		$(tempVar).addClass('zoomOut');
		$(tempVar)[0].player.width(640);
  		$(tempVar)[0].player.height(480);
  		var zMargin = $(window).width();
  		zMargin = (zMargin - 640)/2;
  		$(tempVar).css('margin-left',zMargin);

	}
	$('#zoomOutBtn').hide();
	$('#zoomInBtn').show();
}
function zoomIn(){
	zoomVar = 1;
	var t =setTimeout('fixZoom();',300);
	var checkIt = $('#'+currentImg).attr('class');
	var window_height = $(window).height();
	var window_width = $(window).width();
			
			$('#'+currentImg).removeClass();
			$('#'+currentImg).addClass('spread');
			var x = currentImg-1;
			w = projectArrayW[x];
			h = projectArrayH[x];
			$('#'+currentImg).width(w);
			$('#'+currentImg).height(h);
			$('#'+currentImg).css('margin-top',0);
			$('#'+currentImg).css('margin-left',0);

			$('#zoomOutBtn').show();
			$('#zoomInBtn').hide();

}
zoomVar = 0;
function fixZoom(){
	zoomVar = 0;
}
function setZoomBtn(){
	var x = currentImg;
	$('#zoomOutBtn').hide();
	$('#zoomInBtn').hide();
	$('#replayBtn').hide();
	var checkIt = $('#'+x).attr('class');
	if(checkIt == 'spread'){
		$('#zoomOutBtn').fadeIn(600);
	} else {
		$('#zoomOutBtn').fadeOut(600);
	}
	var checkIt2 = $('#'+x).attr('class');
	if (checkIt2 == 'digital'){
		$('#replayBtn').fadeIn(600);	
	} else {
		$('#replayBtn').fadeOut(600);
	}
}
function startZoomBtn(){
	var checkIt = $('#'+1).attr('class');
	if(checkIt == 'spread'){
		$('#zoomOutBtn').show();
	} else {
		$('#zoomOutBtn').hide();
	}
	var checkIt2 = $('#'+1).attr('class');
	if (checkIt2 == 'digital'){
		$('#replayBtn').fadeIn(600);	
	} else {
		$('#replayBtn').fadeOut(600);
	}
}
//
// LOAD WORK
//

//
// LOAD PROJECTS
//
var vidInt = 0;
var currentImg = 1;
var maxImg = 0;
var vitaminC = 0;

function loadProject(){
	// Load XML
	 $.get('xml/work.xml', function(d){		 
		 // Load Client Thumbnails
		 var i = 0;
		numItems++;
		    		//COMING SOON FIX
    		if (client=="stoli"){
    			maxImg = -1;
    		}

    	$(d).find('client').each(function(n) {
    		
			
			// SCRUB XML FOR CLIENT
			var $xml = $(this);
			var path = $xml.find('path').text();
			
			if (path == client) {
				var name = $xml.find('name').text();

				$xml.find('work').each(function(i) {		
					maxImg++;
					var src = $(this).find('src').text();
					var c = $(this).find('campaign').text();
					var type = $(this).find('type').text();
					var media = $(this).find('media').text();
					var w = $(this).find('w').text();
  					var h = $(this).find('h').text();
					i++;
					
					campaign[i] = c;

					// SET THUMBNAIL
					$('#thumbnails').append("<a href='#'  onclick='projectClick(\""+i+"\");return false;'><img src='thumbs/"+path+"/th_"+src+".jpg' width='116' height='74' class='thumbnail'/></a>");
					
					// LOAD WORK
					switch(type) {
						case 'image':
  							$('#homeStage').append("<div class='bg-image'><div id='print_"+i+"' class='print'><img src='work/"+path+"/"+src+".jpg' width="+w+" height="+h+" id="+i+" /><div class='type'><p>"+media+"</p></div></div></div>");
  							var window_width =  $(window).width();
							var window_height = $(window).height();
							$('.bg-image').width(window_width);
	
							image_width = $('#'+i).width();
							image_height = $('#'+i).height();

								h = window_height-(100+24+60);
								w = (image_width * h)/image_height;
								w = Math.round(w);
								topVar = 75;
								leftVar = (window_width-(w+20))/2;

							$("#"+i).attr('width', w);
							$("#"+i).attr('height', h);
							$("#print_"+i).css('width', w);
							$("#print_"+i).css('height', h+40);
							$("#print_"+i).css('top',topVar);
							$("#print_"+i).css('left',leftVar);
							startZoomBtn();
						break;
						case 'video' :
						vid_array[vidInt] = i;
						vidInt++;
						vid_array_src[v] = 0;
						vid_array_w[v] = 0;
						vid_array_h[v] = 0;

						var window_width =  $(window).width();
						var window_height = $(window).height();
						
						image_width = w;
						image_height = h;
						w=window_width;
						h = (window_width * image_height)/image_width;
						h = Math.round(h);

						src = "work/"+path+"/videos/"+src;
						
						// Load VIDEO into ARRAY
						
						vid_array_src[v] = src;
						vid_array_w[v] = w;
						vid_array_h[v] = h;
						v++;
						//alert(vid_array_src.length)

						$("<div class='bg-image' id='vidHolder_"+v+"'></div>").appendTo('#homeStage');
						
						$('.bg-image').width(window_width);				

						break;
						case 'flash' :
						var window_width =  $(window).width();
						var window_height = $(window).height();

						var medRect = $(this).find('medRect').text();
						var skyscraper = $(this).find('skyscraper').text();
						var leaderboard = $(this).find('leaderboard').text();
						
						var title = $(this).find('title').text();
						var unit = $(this).find('unit').text();
						var w = $(this).find('w').text();
						var h = $(this).find('h').text();
						var size = w+"x"+h;

						if (medRect != ''){
							w=300;
							h=250;
							var digitalVar = "work/"+path+"/swf/"+medRect;
							var medRect_src = "<div id='flash'><div id='closeButton'><a href='#' onclick='overlay(); return false;'><div id='close'></div></a></div><div id='flashContent'><object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' width=\'"+w+"\' height=\'"+h+"\' id=\'"+digitalVar+"\' align='middle'><param name='movie' value=\'"+digitalVar+".swf' /><param value='internal' name='allowNetworking'><param value='never' name='allowScriptAccess'><param name='quality' value='high' /><param name='bgcolor' value='#ffffff' /><param name='play' value='true' /><param name='loop' value='true' /><param name='wmode' value='transparent' /><param name='scale' value='showall' /><param name='menu' value='true' /><param name='devicefont' value='false' /><param name='salign' value='' /><param name='allowScriptAccess' value='sameDomain' /><!--[if !IE]>--><object type='application/x-shockwave-flash' data=\'"+digitalVar+".swf' width=\'"+w+"\' height=\'"+h+"\'><param value='internal' name='allowNetworking'><param value='never' name='allowScriptAccess'><param name='movie' value=\'"+digitalVar+".swf' /><param value='internal' name='allowNetworking'><param value='never' name='allowScriptAccess'><param name='quality' value='high' /><param name='bgcolor' value='#ffffff' /><param name='play' value='true' /><param name='loop' value='true' /><param name='wmode' value='transparent' /><param name='scale' value='showall' /><param name='menu' value='true' /><param name='devicefont' value='false' /><param name='salign' value='' /><param name='allowScriptAccess' value='sameDomain' /><!--<![endif]--><a href='http://www.adobe.com/go/getflash'><img src='http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif' alt='Get Adobe Flash player' /></a><!--[if !IE]>--></object><!--<![endif]--></object></div></div>";
						} else {
							medRect_src = "";
						}

						if (skyscraper != ''){
							//w=160;
							//h=600;
							//var digitalVar = "work/"+path+"/swf/"+skyscraper;
							//var skyscraper_src = "<div id='flash'><div id='closeButton'><a href='#' onclick='overlay(); return false;'><div id='close'></div></a></div><div id='flashContent'><object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' width=\'"+w+"\' height=\'"+h+"\' id=\'"+digitalVar+"\' align='middle'><param name='movie' value=\'"+digitalVar+".swf' /><param name='quality' value='high' /><param name='bgcolor' value='#ffffff' /><param name='play' value='true' /><param name='loop' value='true' /><param name='wmode' value='transparent' /><param name='scale' value='showall' /><param name='menu' value='true' /><param name='devicefont' value='false' /><param name='salign' value='' /><param name='allowScriptAccess' value='sameDomain' /><!--[if !IE]>--><object type='application/x-shockwave-flash' data=\'"+digitalVar+".swf' width=\'"+w+"\' height=\'"+h+"\'><param name='movie' value=\'"+digitalVar+".swf' /><param name='quality' value='high' /><param name='bgcolor' value='#ffffff' /><param name='play' value='true' /><param name='loop' value='true' /><param name='wmode' value='transparent' /><param name='scale' value='showall' /><param name='menu' value='true' /><param name='devicefont' value='false' /><param name='salign' value='' /><param name='allowScriptAccess' value='sameDomain' /><!--<![endif]--><a href='http://www.adobe.com/go/getflash'><img src='http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif' alt='Get Adobe Flash player' /></a><!--[if !IE]>--></object><!--<![endif]--></object></div></div>";
							skyscraper_src = "";
						} else {
							skyscraper_src = "";
						}

						if (leaderboard != ''){
							//w=728;
							//h=90;
							//var digitalVar = "work/"+path+"/swf/"+leaderboard;
							//var leaderboard_src = "<div id='flash'><div id='closeButton'><a href='#' onclick='overlay(); return false;'><div id='close'></div></a></div><div id='flashContent'><object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' width=\'"+w+"\' height=\'"+h+"\' id=\'"+digitalVar+"\' align='middle'><param name='movie' value=\'"+digitalVar+".swf' /><param name='quality' value='high' /><param name='bgcolor' value='#ffffff' /><param name='play' value='true' /><param name='loop' value='true' /><param name='wmode' value='transparent' /><param name='scale' value='showall' /><param name='menu' value='true' /><param name='devicefont' value='false' /><param name='salign' value='' /><param name='allowScriptAccess' value='sameDomain' /><!--[if !IE]>--><object type='application/x-shockwave-flash' data=\'"+digitalVar+".swf' width=\'"+w+"\' height=\'"+h+"\'><param name='movie' value=\'"+digitalVar+".swf' /><param name='quality' value='high' /><param name='bgcolor' value='#ffffff' /><param name='play' value='true' /><param name='loop' value='true' /><param name='wmode' value='transparent' /><param name='scale' value='showall' /><param name='menu' value='true' /><param name='devicefont' value='false' /><param name='salign' value='' /><param name='allowScriptAccess' value='sameDomain' /><!--<![endif]--><a href='http://www.adobe.com/go/getflash'><img src='http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif' alt='Get Adobe Flash player' /></a><!--[if !IE]>--></object><!--<![endif]--></object></div></div>";
							leaderboard_src = "";
						} else {
							leaderboard_src = "";
						}
						// LOAD INTO ARRAYS
						flash_array[i] = "<div class='leaderboard'>"+leaderboard_src+"</div><div class='skyscraper'>"+skyscraper_src+"</div><div class='medRect'>"+medRect_src+"</div><p><span class='title'>"+title+"</span><br />"+size+"<br />"+unit+"</p>";
						$("<div class='bg-image' ><div id="+i+" class='digital'></div></div>").appendTo('#homeStage');
						$('.bg-image').width(window_width);
						centerDigital();
						break;
						default:
						break;
					}
					
					projectArrayW[i-1] = w;
					projectArrayH[i-1] = h;
					
				});


				
			
			} //IF CLOSE

        });
	}).complete(function(){
		thumbHeight();
			// IF 1ST PROJECT = VIDEO | LOAD INITIAL VIDEO
		jQuery.each(vid_array, function(index, value){
				if (currentImg == value){
					var z = index+1;
					var child = $("#vidHolder_"+z).is(":empty");
					if (child == true) {
						loadVideo(index);
					}
				}

		});

	}); //get close
	
	// set Thumbnail height after quick delay to allow XML LOAD
	//var t =setTimeout('thumbHeight();',800);
}


// CLICKING PROJECTS
currentImg = 1;
function projectClick(x) {
	var window_width = $(window).width();
	var distance = x;

	var v = currentImg - distance;
	//COMING SOON FIX
    if (client=="stoli" && distance=='3'){
    	v = 0;
    }

	if (v > 0) {
	// Move backwards
		var electricSlide = '+='+(v*window_width);

	} else {
	// Move forwards
		var electricSlide = '-='+(v*window_width*-1);
	}
	
	// Animate
	if (v != 0) {
		// EMPTY FLASH
			var tempVar = $("#"+currentImg).attr('class');
			if (tempVar == 'digital'){
				$('#'+currentImg).empty();		
			}
			$("#videoBox").remove();

		 $('#homeStage').animate({
			    left: electricSlide
			  }, 400, function() {
			    // Animation complete.
			  var tempVar = $("#"+currentImg).attr('class');
			    if (tempVar == 'digital'){
			    	$("#"+currentImg+" .leaderboard").show();
					$("#"+currentImg+" .skyscraper").show();
					$("#"+currentImg+" .medRect").show();
			    }
			  //FIX ZOOMED-OUT
			  var checkIt = $('#'+currentImg).attr('class');
			if (checkIt == 'zoomOut') {
				var window_height = $(window).height();
				var window_width = $(window).width();
				$('#'+currentImg).removeClass();
				$('#'+currentImg).addClass('spread');
				var x = currentImg-1;
				w = projectArrayW[x];
				h = projectArrayH[x];
				$('#'+currentImg).width(w);
				$('#'+currentImg).height(h);
				$('#'+currentImg).css('margin-top',0);
				$('#'+currentImg).css('margin-left',0);
				setZoomBtn();
			}
		 });
	currentImg = distance;
	
	// SET CAMPAIGN
	var tempName = "images/n_"+client+"_"+campaign[currentImg]+".png";
	$("#client_name").attr('src',tempName);

	// FIX IE6
		var fail = 0;
		if (jQuery.browser.msie) {
  			if(parseInt(jQuery.browser.version) == 6) {
    		 fail = 1;
  			}
		}
		if (fail == 1) {
			$('footer img').supersleight();
		}

	setZoomBtn();
	// LOAD VIDEO
		jQuery.each(vid_array, function(index, value){
			var z = index+1;
			var child = $("#vidHolder_"+z).is(":empty");
				if (currentImg == value){
					if (child == true) {
						loadVideo(index);
						if(footer==1){
					footer=0;
		
					$('footer').animate({
				    top: '+='+th
				  }, 400, function() {
			    	// Animation complete.
			    	$('#thumbnailHeader').removeClass();
					$('#thumbnailHeader').addClass('arrowDown');
			  	});
					}
					}
				}
	});

	// LOAD FLASH
	var tempVar = $("#"+currentImg).attr('class');
	if (tempVar == 'digital'){
		$(flash_array[currentImg]).appendTo('#'+currentImg);
						
	}
	}
}
function nextProject() {
	if(currentImg != maxImg){

			// EMPTY FLASH
			var tempVar = $("#"+currentImg).attr('class');
			if (tempVar == 'digital'){
				$('#'+currentImg).empty();		
			}
			$("#videoBox").remove();

		var window_width = $(window).width();
		
		$('#homeStage').animate({
			    left: '-='+window_width
			  }, 800, function() {
			    // Animation complete.
		  var tempVar = $("#"+currentImg).attr('class');
			    if (tempVar == 'digital'){
			    	$("#"+currentImg+" .leaderboard").show();
					$("#"+currentImg+" .skyscraper").show();
					$("#"+currentImg+" .medRect").show();
			    }
			//FIX ZOOMED-OUT
			var checkIt = $('#'+currentImg).attr('class');
			if (checkIt == 'zoomOut') {
				var window_height = $(window).height();
				var window_width = $(window).width();
				$('#'+currentImg).removeClass();
				$('#'+currentImg).addClass('spread');
				var x = currentImg-1;
				w = projectArrayW[x];
				h = projectArrayH[x];
				$('#'+currentImg).width(w);
				$('#'+currentImg).height(h);
				$('#'+currentImg).css('margin-top',0);
				$('#'+currentImg).css('margin-left',0);
				setZoomBtn();
			}
		 });
		currentImg++;
		
		// SET CAMPAIGN
		var tempName = "images/n_"+client+"_"+campaign[currentImg]+".png";
		$("#client_name").attr('src',tempName);

		// FIX IE6
		var fail = 0;
		if (jQuery.browser.msie) {
  			if(parseInt(jQuery.browser.version) == 6) {
    		 fail = 1;
  			}
		}
		if (fail == 1) {
			$('footer img').supersleight();
		}

		if (currentImg == maxImg){
			$("#rightArrow").hide();
		}
		setZoomBtn();

		// LOAD VIDEO
		jQuery.each(vid_array, function(index, value){
				if (currentImg == value){
					var z = index+1;
					var child = $("#vidHolder_"+z).is(":empty");
					if (child == true) {
						loadVideo(index);
					}
				}
		});
		var tempVar = $("#"+currentImg).attr('class');
	if (tempVar == 'digital'){
		$(flash_array[currentImg]).appendTo('#'+currentImg);
		}					
	

	}
}
function prevProject() {
	if (currentImg != 1){
		// EMPTY FLASH
			var tempVar = $("#"+currentImg).attr('class');
			if (tempVar == 'digital'){
				$('#'+currentImg).empty();		
			}
			$("#videoBox").remove();

		var window_width = $(window).width();
		
		 $('#homeStage').animate({
			    left: '+='+window_width
			  }, 800, function() {
			    // Animation complete.
			     var tempVar = $("#"+currentImg).attr('class');
			    if (tempVar == 'digital'){
			    	$("#"+currentImg+" .leaderboard").show();
					$("#"+currentImg+" .skyscraper").show();
					$("#"+currentImg+" .medRect").show();
			    }
			//FIX ZOOMED-OUT
			var checkIt = $('#'+currentImg).attr('class');
			if (checkIt == 'zoomOut') {
				var window_height = $(window).height();
				var window_width = $(window).width();
				$('#'+currentImg).removeClass();
				$('#'+currentImg).addClass('spread');
				var x = currentImg-1;
				w = projectArrayW[x];
				h = projectArrayH[x];
				$('#'+currentImg).width(w);
				$('#'+currentImg).height(h);
				$('#'+currentImg).css('margin-top',0);
				$('#'+currentImg).css('margin-left',0);
				setZoomBtn();
			}
		 });
		currentImg--;

			// SET CAMPAIGN
			var tempName = "images/n_"+client+"_"+campaign[currentImg]+".png";
			$("#client_name").attr('src',tempName);
		
		// FIX IE6
		if (jQuery.browser.msie) {
  			if(parseInt(jQuery.browser.version) == 6) {
    		 fail = 1;
  			}
		}
		if (fail == 1) {
			supersleight.init();
		}


		if (currentImg == 1){
			$("#leftArrow").hide();
		}
		setZoomBtn();
		// LOAD VIDEO
		jQuery.each(vid_array, function(index, value){
				if (currentImg == value){
					var z = index+1;
					var child = $("#vidHolder_"+z).is(":empty");
					if (child == true) {
						loadVideo(index);
					}
				}
		});
	
	// LOAD FLASH
	var tempVar = $("#"+currentImg).attr('class');
	if (tempVar == 'digital'){
		$(flash_array[currentImg]).appendTo('#'+currentImg);
						
	}
}
}

function replayFlash(){
	zoomVar = 1;
	var t =setTimeout('fixZoom();',300);
	$('#'+currentImg).empty();
	$(flash_array[currentImg]).appendTo('#'+currentImg);
}

// Load for work.html
function loadWork() {
	
	// Load XML
	 $.get('xml/work.xml', function(d){
		 
		 // Load Client Thumbnails
		 var i = 0;
		 var n = 0;
    	$(d).find('client').each(function(n) {
			i ++;
			var $xml = $(this);
			var name = $xml.find('name').text();
			var path = $xml.find('path').text();
			var date = $xml.find('date').text();
			var thumb = 'thumbs/'+path+'/th_main.jpg';
			$("<div class='big_thumb_box' id="+i+"><a href='project.php?client="+path+"' onmouseover='hoverOn("+i+");' onmouseout='hoverOff("+i+");'><img id="+ i +" src="+thumb+" width='200' height='132' alt='print' class="+date+" /><div id=\'h"+i+"\' class='hoverThumb'>"+name+"</div></div></a>").appendTo('#big_thumb_slide');
        });
         
	}).complete(function(){
		if (jQuery.browser.msie) {
  		if(parseInt(jQuery.browser.version) == 6) {
    		 fail = 1;
  		}
	}
	if (fail == 0) {
		
		$('#big_thumb_slide').jScrollPane();
	}
	}); //get close
	
}


function selectWork(x){
	switch (x){
		case 'all' :
			$('.all_nav').attr('id','current');
			$('.current_nav').attr('id','');
			$('.previous_nav').attr('id','');

			$('.current').parent().fadeTo(400,1);
			$('.previous').parent().fadeTo(400,1);
		break;

		case 'current' :
			$('.all_nav').attr('id','');
			$('.current_nav').attr('id','current');
			$('.previous_nav').attr('id','');
		
			$('.current').parent().fadeTo(400,1);
			$('.previous').parent().fadeTo(400,.2);
		break;

		case 'previous' :
			$('.all_nav').attr('id','');
			$('.current_nav').attr('id','');
			$('.previous_nav').attr('id','current');

			$('.previous').parent().fadeTo(400,1);
			$('.current').parent().fadeTo(400,.2);
		break;
	}

}

// Load Clients
function loadClients() {
	
		// Load XML
		 $.get('xml/clients.xml', function(d){
		 
		 // Load Client Thumbnails
		 var i = 0;
		 var n = 0;
    	$(d).find('client').each(function(n) {
			i ++;
			var $xml = $(this);
			var name = $xml.find('name').text();
			var group = $xml.find('group').text();
			var path = $xml.find('path').text();
			var url = $xml.find('url').text();
			var thumb = 'clients/'+path+'.jpg';
			if (url != ''){
				$("<a href='project.php?client="+url+"' ><img id="+ i +" src="+thumb+" width='117' height='90' alt='print' class='client_thumb' /></a>").appendTo('#'+group);
        	} else {
        		$("<img id="+i+" src="+thumb+" width='117' height='90' alt='print' class='client_thumb' />").appendTo('#'+group);
        	}
 		   });
         
	}).complete(function(){
		if (jQuery.browser.msie) {
  		if(parseInt(jQuery.browser.version) == 6) {
    		 fail = 1;
  		}
	}
	if (fail == 0) {
		
		$('#clients').jScrollPane();
	}
	}); //get close
	
}
function loadCSWork() {
	// Load XML
	 $.get('xml/casestudies.xml', function(d){
		 
		 // Load Client Thumbnails
		 var i = 0;
		 var n = 0;
    	$(d).find('client').each(function(n) {
			i++;
			var $xml = $(this);
			var name = $xml.find('name').text();
			var src = $xml.find('src').text();
			var thumb = 'casestudies/thumbs/'+src+'.jpg';
			$("<div class='big_thumb_box' id="+i+"><a href='case_studies.php?client="+i+"' onmouseover='hoverOn("+i+");' onmouseout='hoverOff("+i+");'><img id="+ i +" src="+thumb+" width='200' height='132' alt='print' class='big_thumb' /><div id=\'h"+i+"\' class='hoverThumb'>"+name+"</div></div></a>").appendTo('#big_thumb_slide');
        
		}); //get close
    }).complete(function(){
			//$('#big_thumb_slide').jScrollPane();
		}); //get close;
         
	
}
//
// LOAD PROJECTS
//
var currentImg = 1;
var maxImg = 0;
function loadCS(startHere){
	// Load XML
	currentImg = startHere;

	var window_width =  $(window).width();
	var window_height =  $(window).height();
	 $.get('xml/casestudies.xml', function(d){		 
		 // Load Client Thumbnails
		 var i = 0;
		 vid_array_src[i] = 0;
		vid_array_w[i] = 0;
		vid_array_h[i] = 0;

		numItems++;
    	$(d).find('client').each(function(n) {
			
			// SCRUB XML FOR CLIENT
			var $xml = $(this);
					i ++;
					maxImg++;
					var name = $(this).find('name').text();
					var src = $(this).find('src').text();
					var w = $(this).find('w').text();
  					var h = $(this).find('h').text();

							
					// SET THUMBNAIL
					$('#thumbnails').append("<a href='#'  onclick='csClick(\""+i+"\");return false;'><img src='casestudies/thumbs/"+src+".jpg' width='116' height='74' class='thumbnail'/></a>");
					
					// LOAD WORK
					image_width = w;
					image_height = h;
					w=window_width;
					h = (window_width * image_height)/image_width;
					h = Math.round(h);

					src = "casestudies/"+src;
						
					vid_array_src[i] = src;
					vid_array_w[i] = w;
					vid_array_h[i] = h;
												
					$('.bg-image').width(window_width);
				

        });
	}); //get close
	
	// set Thumbnail height after quick delay to allow XML LOAD
	var t =setTimeout('thumbHeight();',800);

	// LOAD VIDEO
	var t =setTimeout('doIt();',800);
	
}

function doIt(){
	var window_width = $(window).width();
	var window_height = $(window).height();
	var i = currentImg;
	var src = vid_array_src[i];
	var vid_width = vid_array_w[i];
	var vid_height = vid_array_h[i];

	// RESIZE VIDEO
				var ratio = window_width/window_height;
				var ratio2 = vid_width/vid_height;
				
				if (ratio > ratio2){
					w = window_width;
					h = (w * vid_height)/vid_width;
					var leftVar = 0;
				} else {
					h = window_height;
					w = (h * vid_width)/vid_height;
					var leftVar = (w-window_width)/2;
					leftVar = -1*leftVar;
				}
						
	$("<div class='bg-image'><div id='videoBox' class='video-js-box hu-css'><!-- Using the Video for Everybody Embed Code http://camendesign.com/code/video_for_everybody --><video id=\'video_main\'class='video-js' width="+w+" height="+h+" controls='none' autoplay preload='none' poster='images/spacer_black.png'><source src='"+src+".mp4' type='video/mp4; codecs=\"avc1.42E01E, mp4a.40.2\"' /><source src='"+src+".webm' type='video/webm; codecs=\"vp8, vorbis\"' /><source src='"+src+".ogv' type='video/ogg; codecs=\"theora, vorbis\"' /><!-- Flash Fallback. Use any flash video player here. Make sure to keep the vjs-flash-fallback class. --><object id='flash_fallback_1' class='vjs-flash-fallback' width="+w+" height="+h+" type='application/x-shockwave-flash' data='js/flowplayer-3.2.7.swf'><param name='movie' value='js/flowplayer-3.2.7.swf' /><param name='allowfullscreen' value='true' /><param name='wmode' value='transparent' /><param name=\"flashvars\" value=\'config=\{\"playlist\"\:\[\"images/spacer_black.png\", \{\"url\": \""+src+".mp4\",\"autoPlay\":true,\"autoBuffering\":true\}\]\}' />><!-- Image Fallback. Typically the same as the poster image. --><img src='images/spacer_black.png' width="+w+" height="+h+" alt='Poster Image' title='No video playback capabilities.' /></object></video></div></div>").appendTo('#homeStage');
						
	$('.bg-image').width(window_width);

	// SET TOP VAR
	topVar = (h-window_height)/2;
	topVar = topVar*-1;
	$("#videoBox").css('top',topVar);

	// After load : initialize videoJS
	var myPlayer = VideoJS.setup('video_main');

	// TURN SOUND OFF
    myPlayer.volume(100);

	var t =setTimeout('playVideo();',800);

	var controlH = .5*window_height;
	controlH = controlH*-1;
						
	var centerPlay = (window_height/2);

	$(".hu-css .vjs-controls > div").hide();
	$(".hu-css div.vjs-big-play-button").hide();	
}
function loadVideo(i){
	$("#videoBox").remove();
	var window_width = $(window).width();
	var window_height = $(window).height();
	var src = vid_array_src[i];
	var vid_width = vid_array_w[i];
	var vid_height = vid_array_h[i];
	var z = i+1;
	i = currentImg;

	// RESIZE VIDEO
				var ratio = window_width/window_height;
				var ratio2 = vid_width/vid_height;

				if (ratio > ratio2){
					w = window_width;
					h = (w * vid_height)/vid_width;
					var leftVar = 0;
				} else {
					h = window_height;
					w = (h * vid_width)/vid_height;
					var leftVar = (w-window_width)/2;
					leftVar = -1*leftVar;
				}
	

	$("<div id='videoBox' class='video-js-box hu-css'><!-- Using the Video for Everybody Embed Code http://camendesign.com/code/video_for_everybody --><video id=\'video_"+i+"\'class='video-js' width="+w+" height="+h+" autoplay><source src='"+src+".mp4' type='video/mp4; codecs=\"avc1.42E01E, mp4a.40.2\"' /><source src='"+src+".webm' type='video/webm; codecs=\"vp8, vorbis\"' /><source src='"+src+".ogv' type='video/ogg; codecs=\"theora, vorbis\"' /><!-- Flash Fallback. Use any flash video player here. Make sure to keep the vjs-flash-fallback class. --><object id='flash_fallback_1' class='vjs-flash-fallback' width="+w+" height="+h+" type='application/x-shockwave-flash' data='js/flowplayer-3.2.7.swf'><param name='movie' value='js/flowplayer-3.2.7.swf' /><param name='allowfullscreen' value='true' /><param name='wmode' value='transparent' /><param name=\"flashvars\" value=\'config=\{\"playlist\"\:\[\"images/spacer_black.png\", \{\"url\": \""+src+".mp4\",\"autoPlay\":true,\"autoBuffering\":true\}\]\}' />><!-- Image Fallback. Typically the same as the poster image. --><img src='images/spacer_black.png' width="+w+" height="+h+" alt='Poster Image' title='No video playback capabilities.' /></object></video></div>").appendTo('#vidHolder_'+z);
						
	$('.bg-image').width(window_width);
	$('.bg-image').height(window_height);

	topVar = (h-window_height)/2;
	topVar = topVar*-1;
	$("#videoBox").css('top',topVar);

	// After load : initialize videoJS
	var myPlayer = VideoJS.setup('video_'+i);

	// TURN SOUND OFF
    myPlayer.volume(100);

    var t =setTimeout('playProject('+i+');',800);

	var controlH = .6*h;
	controlH = controlH*-1;
						
	var centerPlay = (window_height/2);

	$(".hu-css .vjs-controls > div").css('top',controlH);
	$(".hu-css div.vjs-big-play-button").css('top',controlH);	
}


// CLICKING PROJECTS
function csClick(x) {
	var window_width = $(window).width();


	var v = currentImg - x;
	if (v > 0) {
		// Move backwards
		var electricSlide = '+='+window_width;

	} else {
		// Move forwards
		var electricSlide = '-='+window_width;
	}
	currentImg = x;
	// Animate
	if (v != 0) {
		$("#videoBox").remove();

		 $('#homeStage').animate({
			    left: electricSlide
			  }, 800, function() {
			     // Animation complete.
			    $('#homeStage').empty();
			    $('#homeStage').css('left','0px');
			    doIt();
		 });
		 if(footer==1){
				footer=0;
		
				$('footer').animate({
			    top: '+='+th
			  }, 400, function() {
		    	// Animation complete.
		    	$('#thumbnailHeader').removeClass();
				$('#thumbnailHeader').addClass('arrowDown');
	  	});
	}
	}

}
function nextCS() {
	var window_width = $(window).width();
	if(currentImg != maxImg){
		$("#videoBox").remove();
		currentImg++;
		if (currentImg == maxImg){
			$("#rightArrow").hide();
		}
		$('#homeStage').animate({
			    left: '-='+window_width
			  }, 800, function() {
			    // Animation complete.
			    $('#homeStage').empty();
			    $('#homeStage').css('left','0px');
			    doIt();

		 });
	}
}
function prevCS() {
	var window_width = $(window).width();
	if(currentImg != 1){
		$("#videoBox").remove();
		currentImg--;
		if (currentImg == 1){
			$("#leftArrow").hide();
		}
		$('#homeStage').animate({
			    left: '+='+window_width
			  }, 800, function() {
			    // Animation complete.
			    $('#homeStage').empty();
			    $('#homeStage').css('left','0px');
			    doIt();

		 });
	}
}

var fail = 0;
function sizeThumbDiv(){
	if (jQuery.browser.msie) {
  		if(parseInt(jQuery.browser.version) == 6) {
    		 fail = 1;
  		}
	}
	if (fail == 0) {
		var window_height = $(window).height();
		var x = window_height - 174;
		$('#thumb_pane').css('height',x);
	}
}
function sizeClientsDiv(){
	var window_height = $(window).height();
	var x = window_height - 174;
	$('#clients').css('height',x);
}

function hoverOn(i) {
	$("#h"+i).css('top','-41px');
	$("#"+i).css("background-image","url('images/thumbBG.png')");
}
function hoverOff(i) {
	$("#h"+i).css('top','0px');
	$("#"+i).css('background-image','');
}

function playVideo(){
	var pauseVar = '#video_main' 
	if ($(pauseVar)[0] != null){
		$(pauseVar)[0].player.play();
	}
}

function playProject(i){
	var pauseVar = '#video_'+i; 
	if ($(pauseVar)[0] != null){
		$(pauseVar)[0].player.play();
	}
}

function playHome(){	

	var pauseVar = '#video_main'; 
	if ($(pauseVar)[0] != null){
		$(pauseVar)[0].player.play();
	}
}


function centerDigital(){
	var window_height = $(window).height();
	var box_height = $('.digital').height();
	var x = (window_height-box_height)/2;
	Math.round(x);
	x = x-20;
	$('.digital').css('margin','0 auto');
	$('.digital').css('top',x);
}

// DELAY LIFE SAVER
var delay = (function(){
  var timer = 0;
  return function(callback, ms){
    clearTimeout (timer);
    timer = setTimeout(callback, ms);
  };
})();

