$(document).ready(function(){
	
	// ADD BODY CLASS FOR BROWSER DETECT
	var body = $("body");
	body.addClass($.client.browser);
	body.addClass($.client.os);
	
	// TAKE THIS OUT WHEN YOU GO LIVE!!!!!!!!!!
	//if ($.client.browser == 'Safari'){
	// body.addClass('iOS');
	//	}
	///////////////////////////////////////////
	
	// SET UP SOME UNIVERSAL VARIABLES
	
	var overlay = $("#case-study-info");
	var poster = $("#poster-container");
	var links = $("#nav-container li a");
	var projectsLink = $("li#projects a");
	var projects = $("li#projects");
	var projectsSublink = $("div.sub");
	var videoThumb = $(".image-row li");
	var sections = $("li#projects ul li");
	var ipadSections = $("#ipad-projects div");
	var sectionsUl = $("li#projects ul");
	var loading = $(".content-loading");
	var content = $("#case-projects-container");
	var video = $("#video-container");
	var active = $("a.active");
	var mobile = false;
	var ipad = false;
	var iphone = false;
	
	// IPAD OVERLAY IN AND OUT FUNCTIONS
	
	function ipadOverlayOut(){
		$("#case-study-info").removeClass('mobile-move-in');
		$("#case-study-info").addClass('mobile-move-out');
		$("#close-case").fadeOut(100);
		$("#re-open").delay(100).fadeIn(100);
		$("#case-internal").addClass('itsOut');
	}
	
	function ipadOverlayIn(){
		$("#case-study-info").removeClass('mobile-move-out');
		$("#case-study-info").addClass('mobile-move-in');
		$("#re-open").fadeOut(100);
		$("#close-case").delay(100).fadeIn(100);		
		$("#case-internal").removeClass('itsOut');
	}
	
	function ipadClearNavAjax(){
		$("#bio-container-wrapper").empty();
		$("#contact-container-wrapper").empty();
	}
	
	// AND UNIVERSAL ACTIONS NEEDED BEFORE THE CLICK FUNCTIONS
	
	function browserOverlayOut(){
		$("#close-case").fadeOut(100);
		$("#re-open").delay(100).fadeIn(100);
		$("#case-study-info").animate({"left":"-279px"}, 250);
		$("#case-internal").addClass('itsOut');
	}
	
	function browserOverlayIn(){
		$("#re-open").fadeOut(100);
		$("#close-case").delay(100).fadeIn(100);
		$("#case-study-info").animate({"left":"0px"}, 250);
		$("#case-internal").removeClass('itsOut');
	}
	
	function showLoading(){
		loading.css({visibility:"visible"}).css({opacity:"1"}).css({display:"block"});
	}
	//hide loading bar
	function hideLoading(){
		loading.fadeOut(500);
	};

	if (navigator.userAgent.match(/Android/i) || navigator.userAgent.match(/webOS/i)){ 
		var mobile = true;
	}
	if (navigator.userAgent.match(/iPad/i)){
		var ipad = true;
	}
	if (navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i)){
		var iphone = true;
	}
	
	
	
	// ........................THIS BEGINS THE IPAD STUFF........................//
	
	
	
	if (ipad == true || mobile == true) {
						
			body.addClass('iOS');
			
			$("#poster-container").addClass('fade-in');		
					
			$("#project-posters").remove();
			
			// FIX THE OVERLAY TO STAY OUT AND THEN COME IN
			window.setTimeout(function(){
				overlay.css({left:'0px'});
				overlay.addClass('mobile-move-in');
				$("#re-open").fadeOut(100);
				$("#close-case").delay(100).fadeIn(100);
				},
			1000);
			
			// PUT CLASSES ON THE NAV ITEMS
			$("#case-nav-container").addClass('html-fade');
			//$("#contact-container-wrapper").addClass('html-fade');
			//$("#bio-container-wrapper").addClass('html-fade');
			
			// SET UP THE OPEN/CLOSE ACTIONS FOR THE CASE STUDY CONTAINER
			$("#close-case").click(function(){
				ipadOverlayOut();
			});

			// OPEN LEFT TRAY
			$("#re-open").click(function(){
				ipadOverlayIn();
			});

			// FUNCTION FOR CLOSING THE TRAY
			function infoMoveOut() {
				overlay.removeClass("mobile-move-in").addClass("mobile-move-out");
			}
			
			// FUNCTION FOR OPENING THE TRAY							
			function infoMoveIn() {
				setTimeout( function() {
					overlay.removeClass("mobile-move-out").addClass("mobile-move-in");
				}, 1000 );
			}
			
			// MAKE THE MENUS STICKY & SET UP AJAX FOR TOP MENU
			links.live('click', function(){
				
				$(".active").removeClass('active');
				
				// MOVE IN OVERLAY AND CHANGE OPEN BUTTON TO CLOSE
				$(".mobile-move-out").removeClass("mobile-move-out").addClass("mobile-move-in");
				$("#re-open").fadeOut(100);
				$("#close-case").delay(100).fadeIn(100);
				
				// CLEAR OUT THE EXISTING AJAX
				 ipadClearNavAjax();
				
				//LOAD SOME AJAX!
				switch(this.id){
					case "projects-anchor":
						if($("#projects-anchor").hasClass('active')){
						}
						else{
							//$(".fade-in").removeClass('fade-in');
							$("#case-projects-container").removeClass('fade-in');
							$("#projects-anchor").addClass('active');
							$("#case-nav-container").addClass('fade-in');
							$("#contact-container-wrapper").removeClass('fade-in');
						}
					break;	
				
					case "bio-anchor":
						if($("#bio-anchor").hasClass('active')){
						}
						else{
							ipadOverlayOut();
							$(".fade-in").removeClass('fade-in');
							$("#initial-slide-wrapper").removeClass('fade-in-wrapper');
							$("#bio-anchor").addClass('active');
							$("#poster-container").addClass('fade-in');
							
							setTimeout( function() {
								$("#bio-container-wrapper").load("ajax/bio.html");//load the case-study information
								ipadOverlayIn();
							}, 500);
						}
					break;

					case "contact-anchor":
						if($("#contact-anchor").hasClass('active')){
							//alert('contact has already been loaded');
						}
						else{
							ipadOverlayOut();
							$(".fade-in").removeClass('fade-in');
							$("#initial-slide-wrapper").removeClass('fade-in-wrapper');
							$("#contact-anchor").addClass('active');
							$("#poster-container").addClass('fade-in');				
						
							setTimeout( function() {
								$("#contact-container-wrapper").load("ajax/contact.html"); //load the case-study information
								ipadOverlayIn();
							}, 500);
						}
					break;
				}
				
			});
			
			// SWITCH OUT AND SET INITIAL VIDEOS WHEN CLICKING ON PROJECTS SUBMENU
			projectsSublink.live('click', function(){	
				$(".active").removeClass('active');
				$("#case-nav-container").removeClass('fade-in');
				$("#initial-slide-wrapper").removeClass('fade-in-wrapper');
				$("#video-container").addClass('fade-in-video');				
				
				//SET TIMEOUT CHANGE Z-INDEX OF initalslidewrapper

				$("#initial-slide-wrapper").css("z-index","100");
				
				switch(this.id){
					
					case "a-good-life":
							showLoading();
							content.load("ajax/case/info-a-good-life.html", hideLoading).hide().fadeIn(1500); //load the case-study information
							video.load("ajax/videos/mobile/a-good-life-mobile-poster.html", hideLoading).hide().fadeIn(1500); //load the video
							$("#case-projects-container").addClass('fade-in');
					break;
				
					case "skittles":
						if($("#skittles").hasClass('active')){
							//alert('projects have already been loaded');
						}
						else{
							showLoading();
							content.load("ajax/case/info-skittles-race.html", hideLoading).hide().fadeIn(1500); //load the case-study information
							video.load("ajax/videos/mobile/skittles-race-mobile-poster.html", hideLoading).hide().fadeIn(1500); //load the video
							$("#case-projects-container").addClass('fade-in');
							
						}
					break;
					
					case "absolut":
						if($("#absolut").hasClass('active')){
							//alert('projects have already been loaded');
						}
						else{
							showLoading();
							content.load("ajax/case/info-absolut-orient.html", hideLoading).hide().fadeIn(1500); //load the case-study information
							video.load("ajax/videos/mobile/absolut-orient-mobile-poster.html", hideLoading).hide().fadeIn(1500); //load the video
							$("#case-projects-container").addClass('fade-in');
							
						}
					break;
					
					case "british-airways":
						if($("#british-airways").hasClass('active')){
							//alert('projects have already been loaded');
						}
						else{
							showLoading();
							content.load("ajax/case/info-british-airways.html", hideLoading).hide().fadeIn(1500); //load the case-study information
							video.load("ajax/videos/mobile/british-airways-film-mobile-poster.html", hideLoading).hide().fadeIn(1500); //load the video
							$("#case-projects-container").addClass('fade-in');
							
						}
					break;
					
					case "nissan":
						if($("#nissan").hasClass('active')){
							//alert('projects have already been loaded');
						}
						else{
							showLoading();
							content.load("ajax/case/info-nissan-jtz.html", hideLoading).hide().fadeIn(1500); //load the case-study information
							video.load("ajax/videos/mobile/nissan-jtz-mobile-poster.html", hideLoading).hide().fadeIn(1500); //load the video
							$("#case-projects-container").addClass('fade-in');
							
						}
					break;
					
					case "connect-edu":
						if($("#connect-edu").hasClass('active')){
							//alert('projects have already been loaded');
						}
						else{
							showLoading();
							content.load("ajax/case/info-connect-edu.html", hideLoading).hide().fadeIn(1500); //load the case-study information
							video.load("ajax/videos/mobile/connect-edu-mobile-poster.html", hideLoading).hide().fadeIn(1500); //load the video
							$("#case-projects-container").addClass('fade-in');
							
						}
					break;
					
					case "adidas":
						if($("#adidas").hasClass('active')){
							//alert('projects have already been loaded');
						}
						else{
							showLoading();
							content.load("ajax/case/info-adidas.html", hideLoading).hide().fadeIn(1500); //load the case-study information
							video.load("ajax/videos/mobile/adidas-mobile-poster.html", hideLoading).hide().fadeIn(1500); //load the video
							$("#case-projects-container").addClass('fade-in');
							
						}
					break;
					
					case "skateboarding":
						if($("#skateboarding").hasClass('active')){
							//alert('projects have already been loaded');
						}
						else{
							showLoading();
							content.load("ajax/case/info-skateboarding.html", hideLoading).hide().fadeIn(1500); //load the case-study information
							video.load("ajax/videos/mobile/skateboarding-mobile-poster.html", hideLoading).hide().fadeIn(1500); //load the video
							$("#case-projects-container").addClass('fade-in');
							
						}
					break;
					
					case "underdogs":
						if($("#underdogs").hasClass('active')){
							//alert('projects have already been loaded');
						}
						else{
							showLoading();
							content.load("ajax/case/info-underdogs.html", hideLoading).hide().fadeIn(1500); //load the case-study information
							video.load("ajax/videos/mobile/underdogs-mobile-poster.html", hideLoading).hide().fadeIn(1500); //load the video
							$("#case-projects-container").addClass('fade-in');
							
						}
					break;
					
					case "a-good-life":
						if($("#a-good-life").hasClass('active')){
							//alert('projects have already been loaded');
						}
						else{
							showLoading();
							content.load("ajax/case/info-underdogs.html", hideLoading).hide().fadeIn(1500); //load the case-study information
							video.load("ajax/videos/mobile/underdogs-mobile-poster.html", hideLoading).hide().fadeIn(1500); //load the video
							$("#case-projects-container").addClass('fade-in');
							
						}
					break;
					
				}
			
			});
			
			videoThumb.live('click', function(){	
				$(".active").removeClass('active');
				$("#case-projects-container").removeClass('fade-in');
				$("#initial-slide-wrapper").removeClass('fade-in-wrapper');
				$("#video-container").addClass('fade-in-video');
				$("#poster-container").removeClass('fade-in');
				
				//SET TIMEOUT CHANGE Z-INDEX OF  initalslidewrapper

				$("#initial-slide-wrapper").css("z-index","100");
								
					switch(this.id){
						
						case "skittles-race-vid":
							if($("#skittles-race-vid").hasClass('active')){
								//alert('projects have already been loaded');
							}
							else{
								setTimeout( function() {
									showLoading();
									content.load("ajax/case/info-skittles-race.html", hideLoading); //load the case-study information
									video.load("ajax/videos/mobile/skittles-race-mobile-poster.html", hideLoading); //load the video
									$("#case-projects-container").addClass('fade-in');
								}, 750);
							}
						break;
					
						case "skittles-vaporize-vid":
							if($("#skittles-vaporize-vid").hasClass('active')){
								//alert('projects have already been loaded');
							}
							else{
								setTimeout( function() {
									showLoading();
									content.load("ajax/case/info-skittles-vaporize.html", hideLoading); //load the case-study information
									video.load("ajax/videos/mobile/skittles-vaporize-mobile-poster.html", hideLoading); //load the video
									$("#case-projects-container").addClass('fade-in');
								}, 750);

							}
						break;
						
						case "skittles-shaolin-vid":
							if($("#skittles-shaolin-vid").hasClass('active')){
								//alert('projects have already been loaded');
							}
							else{
								setTimeout( function() {
									showLoading();
									content.load("ajax/case/info-skittles-shaolin.html", hideLoading); //load the case-study information
									video.load("ajax/videos/mobile/skittles-shaolin-mobile-poster.html", hideLoading); //load the video
									$("#case-projects-container").addClass('fade-in');
								}, 750);

							}
						break;
					
						case "absolut-orient-vid":
							if($("#absolut-orient-vid").hasClass('active')){
								//alert('projects have already been loaded');
							}
							else{
								setTimeout( function() {
									showLoading();
									content.load("ajax/case/info-absolut-orient.html", hideLoading); //load the case-study information
									video.load("ajax/videos/mobile/absolut-orient-mobile-poster.html", hideLoading); //load the video
									$("#case-projects-container").addClass('fade-in');
								}, 750);
							}
						break;
					
						case "absolut-differently-vid":
							if($("#absolut-differently-div").hasClass('active')){
								//alert('projects have already been loaded');
							}
							else{
								setTimeout( function() {
									showLoading();
									content.load("ajax/case/info-absolut-differently.html", hideLoading); //load the case-study information
									video.load("ajax/videos/mobile/absolut-differently-mobile-poster.html", hideLoading); //load the video
									$("#case-projects-container").addClass('fade-in');
								}, 750);
							}
						break;
					
						case "absolut-exceptional-vid":
							if($("#absolut-exceptional-div").hasClass('active')){
								//alert('projects have already been loaded');
							}
							else{
								setTimeout( function() {
									showLoading();
									content.load("ajax/case/info-absolut-exceptional.html", hideLoading); //load the case-study information
									video.load("ajax/videos/mobile/absolut-exceptional-mobile-poster.html", hideLoading); //load the video
									$("#case-projects-container").addClass('fade-in');
								}, 750);							
							}
						break;
					
						case "british-airways-film-vid":
							if($("#british-airways-film-vid").hasClass('active')){
								//alert('projects have already been loaded');
							}
							else{
								setTimeout( function() {
									showLoading();
									content.load("ajax/case/info-british-airways.html", hideLoading); //load the case-study information
									video.load("ajax/videos/mobile/british-airways-film-mobile-poster.html", hideLoading); //load the video
									$("#case-projects-container").addClass('fade-in');
								}, 750);														
							}
						break;
					
						case "british-airways-teaser-vid":
							if($("#british-airways-teaser-vid").hasClass('active')){
								//alert('projects have already been loaded');
							}
							else{
								setTimeout( function() {
									showLoading();
									content.load("ajax/case/info-british-airways-teaser.html", hideLoading); //load the case-study information
									video.load("ajax/videos/mobile/british-airways-teaser-mobile-poster.html", hideLoading); //load the video
									$("#case-projects-container").addClass('fade-in');
								}, 750);																					
							}
						break;
					
						case "nissan-co2-vid":
							if($("#nissan-co2-vid").hasClass('active')){
								//alert('projects have already been loaded');
							}
							else{
								setTimeout( function() {								
									showLoading();
									content.load("ajax/case/info-nissan-co2.html", hideLoading); //load the case-study information
									video.load("ajax/videos/mobile/nissan-co2-mobile-poster.html", hideLoading); //load the video
									$("#case-projects-container").addClass('fade-in');
								}, 750);																					
							}
						break;
					
						case "nissan-jtz-vid":
							if($("#nissan-jtz-vid").hasClass('active')){
								//alert('projects have already been loaded');
							}
							else{
								setTimeout( function() {																
									showLoading();
									content.load("ajax/case/info-nissan-jtz.html", hideLoading); //load the case-study information
									video.load("ajax/videos/mobile/nissan-jtz-mobile-poster.html", hideLoading); //load the video
									$("#case-projects-container").addClass('fade-in');
								}, 750);																												
							}
						break;
				}
			});
			
	}
	
	
	
	// ........................THIS BEGINS THE IPHONE STUFF........................//
	
	
	
	else if (iphone == true){
		
		body.addClass('iOS');
		
		$("#poster-container").addClass('fade-in');		
				
		$("#project-posters").remove();
		
		// FIX THE OVERLAY TO STAY OUT AND THEN COME IN
		window.setTimeout(function(){
			overlay.css({left:'0px'});
			overlay.addClass('mobile-move-in');
			$("#re-open").fadeOut(100);
			$("#close-case").delay(100).fadeIn(100);
			},
		1000);
		
		// PUT CLASSES ON THE NAV ITEMS
		$("#case-nav-container").addClass('html-fade');
		
		// SET UP THE OPEN/CLOSE ACTIONS FOR THE CASE STUDY CONTAINER
		$("#close-case").click(function(){
			ipadOverlayOut();
		});

		// OPEN LEFT TRAY
		$("#re-open").click(function(){
			ipadOverlayIn();
		});

		// FUNCTION FOR CLOSING THE TRAY
		function infoMoveOut() {
			overlay.removeClass("mobile-move-in").addClass("mobile-move-out");
		}
		
		// FUNCTION FOR OPENING THE TRAY							
		function infoMoveIn() {
			setTimeout( function() {
				overlay.removeClass("mobile-move-out").addClass("mobile-move-in");
			}, 1000 );
		}
		
		// MAKE THE MENUS STICKY & SET UP AJAX FOR TOP MENU
		links.live('click', function(){
			
			$(".active").removeClass('active');
			
			// MOVE IN OVERLAY AND CHANGE OPEN BUTTON TO CLOSE
			$(".mobile-move-out").removeClass("mobile-move-out").addClass("mobile-move-in");
			$("#re-open").fadeOut(100);
			$("#close-case").delay(100).fadeIn(100);
			
			// CLEAR OUT THE EXISTING AJAX
			 ipadClearNavAjax();
			
			//LOAD SOME AJAX!
			switch(this.id){
				case "projects-anchor":
					if($("#projects-anchor").hasClass('active')){
					}
					else{
						//$(".fade-in").removeClass('fade-in');
						$("#case-projects-container").removeClass('fade-in');
						$("#projects-anchor").addClass('active');
						$("#case-nav-container").addClass('fade-in');
						$("#contact-container-wrapper").removeClass('fade-in');
					}
				break;	
			
				case "bio-anchor":
					if($("#bio-anchor").hasClass('active')){
					}
					else{
						ipadOverlayOut();
						$(".fade-in").removeClass('fade-in');
						$("#initial-slide-wrapper").removeClass('fade-in-wrapper');
						$("#bio-anchor").addClass('active');
						$("#poster-container").addClass('fade-in');
						
						setTimeout( function() {
							$("#bio-container-wrapper").load("ajax/bio.html");//load the case-study information
							ipadOverlayIn();
						}, 500);
					}
				break;

				case "contact-anchor":
					if($("#contact-anchor").hasClass('active')){
						//alert('contact has already been loaded');
					}
					else{
						ipadOverlayOut();
						$(".fade-in").removeClass('fade-in');
						$("#initial-slide-wrapper").removeClass('fade-in-wrapper');
						$("#contact-anchor").addClass('active');
						$("#poster-container").addClass('fade-in');				
					
						setTimeout( function() {
							$("#contact-container-wrapper").load("ajax/contact.html"); //load the case-study information
							ipadOverlayIn();
						}, 500);
					}
				break;
			}
			
		});
		
		// SWITCH OUT AND SET INITIAL VIDEOS WHEN CLICKING ON PROJECTS SUBMENU
		projectsSublink.live('click', function(){	
			$(".active").removeClass('active');
			$("#case-nav-container").removeClass('fade-in');
			$("#initial-slide-wrapper").removeClass('fade-in-wrapper');
			$("#video-container").addClass('fade-in-video');				
			
			//SET TIMEOUT CHANGE Z-INDEX OF initalslidewrapper

			$("#initial-slide-wrapper").css("z-index","100");
			
			switch(this.id){
				
				case "a-good-life":
						showLoading();
						content.load("ajax/case/info-a-good-life.html", hideLoading).hide().fadeIn(1500); //load the case-study information
						video.load("ajax/videos/iphone/a-good-life-iphone-poster.html", hideLoading).hide().fadeIn(1500); //load the video
						$("#case-projects-container").addClass('fade-in');
				break;
			
				case "skittles":
					if($("#skittles").hasClass('active')){
						//alert('projects have already been loaded');
					}
					else{
						showLoading();
						content.load("ajax/case/info-skittles-race.html", hideLoading).hide().fadeIn(1500); //load the case-study information
						video.load("ajax/videos/iphone/skittles-race-iphone-poster.html", hideLoading).hide().fadeIn(1500); //load the video
						$("#case-projects-container").addClass('fade-in');
						
					}
				break;
				
				case "absolut":
					if($("#absolut").hasClass('active')){
						//alert('projects have already been loaded');
					}
					else{
						showLoading();
						content.load("ajax/case/info-absolut-orient.html", hideLoading).hide().fadeIn(1500); //load the case-study information
						video.load("ajax/videos/iphone/absolut-orient-iphone-poster.html", hideLoading).hide().fadeIn(1500); //load the video
						$("#case-projects-container").addClass('fade-in');
						
					}
				break;
				
				case "british-airways":
					if($("#british-airways").hasClass('active')){
						//alert('projects have already been loaded');
					}
					else{
						showLoading();
						content.load("ajax/case/info-british-airways.html", hideLoading).hide().fadeIn(1500); //load the case-study information
						video.load("ajax/videos/iphone/british-airways-film-iphone-poster.html", hideLoading).hide().fadeIn(1500); //load the video
						$("#case-projects-container").addClass('fade-in');
						
					}
				break;
				
				case "nissan":
					if($("#nissan").hasClass('active')){
						//alert('projects have already been loaded');
					}
					else{
						showLoading();
						content.load("ajax/case/info-nissan-jtz.html", hideLoading).hide().fadeIn(1500); //load the case-study information
						video.load("ajax/videos/iphone/nissan-jtz-iphone-poster.html", hideLoading).hide().fadeIn(1500); //load the video
						$("#case-projects-container").addClass('fade-in');
						
					}
				break;
				
				case "connect-edu":
					if($("#connect-edu").hasClass('active')){
						//alert('projects have already been loaded');
					}
					else{
						showLoading();
						content.load("ajax/case/info-connect-edu.html", hideLoading).hide().fadeIn(1500); //load the case-study information
						video.load("ajax/videos/iphone/connect-edu-iphone-poster.html", hideLoading).hide().fadeIn(1500); //load the video
						$("#case-projects-container").addClass('fade-in');
						
					}
				break;
				
				case "adidas":
					if($("#adidas").hasClass('active')){
						//alert('projects have already been loaded');
					}
					else{
						showLoading();
						content.load("ajax/case/info-adidas.html", hideLoading).hide().fadeIn(1500); //load the case-study information
						video.load("ajax/videos/iphone/adidas-iphone-poster.html", hideLoading).hide().fadeIn(1500); //load the video
						$("#case-projects-container").addClass('fade-in');
						
					}
				break;
				
				case "skateboarding":
					if($("#skateboarding").hasClass('active')){
						//alert('projects have already been loaded');
					}
					else{
						showLoading();
						content.load("ajax/case/info-skateboarding.html", hideLoading).hide().fadeIn(1500); //load the case-study information
						video.load("ajax/videos/iphone/skateboarding-iphone-poster.html", hideLoading).hide().fadeIn(1500); //load the video
						$("#case-projects-container").addClass('fade-in');
						
					}
				break;
				
				case "underdogs":
					if($("#underdogs").hasClass('active')){
						//alert('projects have already been loaded');
					}
					else{
						showLoading();
						content.load("ajax/case/info-underdogs.html", hideLoading).hide().fadeIn(1500); //load the case-study information
						video.load("ajax/videos/iphone/underdogs-iphone-poster.html", hideLoading).hide().fadeIn(1500); //load the video
						$("#case-projects-container").addClass('fade-in');
						
					}
				break;
				
				case "a-good-life":
					if($("#a-good-life").hasClass('active')){
						//alert('projects have already been loaded');
					}
					else{
						showLoading();
						content.load("ajax/case/info-underdogs.html", hideLoading).hide().fadeIn(1500); //load the case-study information
						video.load("ajax/videos/iphone/underdogs-iphone-poster.html", hideLoading).hide().fadeIn(1500); //load the video
						$("#case-projects-container").addClass('fade-in');
						
					}
				break;
				
			}
		
		});
		
		videoThumb.live('click', function(){	
			$(".active").removeClass('active');
			$("#case-projects-container").removeClass('fade-in');
			$("#initial-slide-wrapper").removeClass('fade-in-wrapper');
			$("#video-container").addClass('fade-in-video');
			$("#poster-container").removeClass('fade-in');
			
			//SET TIMEOUT CHANGE Z-INDEX OF  initalslidewrapper

			$("#initial-slide-wrapper").css("z-index","100");
							
				switch(this.id){
					
					case "skittles-race-vid":
						if($("#skittles-race-vid").hasClass('active')){
							//alert('projects have already been loaded');
						}
						else{
							setTimeout( function() {
								showLoading();
								content.load("ajax/case/info-skittles-race.html", hideLoading); //load the case-study information
								video.load("ajax/videos/iphone/skittles-race-iphone-poster.html", hideLoading); //load the video
								$("#case-projects-container").addClass('fade-in');
							}, 750);
						}
					break;
				
					case "skittles-vaporize-vid":
						if($("#skittles-vaporize-vid").hasClass('active')){
							//alert('projects have already been loaded');
						}
						else{
							setTimeout( function() {
								showLoading();
								content.load("ajax/case/info-skittles-vaporize.html", hideLoading); //load the case-study information
								video.load("ajax/videos/iphone/skittles-vaporize-iphone-poster.html", hideLoading); //load the video
								$("#case-projects-container").addClass('fade-in');
							}, 750);

						}
					break;
					
					case "skittles-shaolin-vid":
						if($("#skittles-shaolin-vid").hasClass('active')){
							//alert('projects have already been loaded');
						}
						else{
							setTimeout( function() {
								showLoading();
								content.load("ajax/case/info-skittles-shaolin.html", hideLoading); //load the case-study information
								video.load("ajax/videos/iphone/skittles-shaolin-iphone-poster.html", hideLoading); //load the video
								$("#case-projects-container").addClass('fade-in');
							}, 750);

						}
					break;
				
					case "absolut-orient-vid":
						if($("#absolut-orient-vid").hasClass('active')){
							//alert('projects have already been loaded');
						}
						else{
							setTimeout( function() {
								showLoading();
								content.load("ajax/case/info-absolut-orient.html", hideLoading); //load the case-study information
								video.load("ajax/videos/iphone/absolut-orient-iphone-poster.html", hideLoading); //load the video
								$("#case-projects-container").addClass('fade-in');
							}, 750);
						}
					break;
				
					case "absolut-differently-vid":
						if($("#absolut-differently-div").hasClass('active')){
							//alert('projects have already been loaded');
						}
						else{
							setTimeout( function() {
								showLoading();
								content.load("ajax/case/info-absolut-differently.html", hideLoading); //load the case-study information
								video.load("ajax/videos/iphone/absolut-differently-iphone-poster.html", hideLoading); //load the video
								$("#case-projects-container").addClass('fade-in');
							}, 750);
						}
					break;
				
					case "absolut-exceptional-vid":
						if($("#absolut-exceptional-div").hasClass('active')){
							//alert('projects have already been loaded');
						}
						else{
							setTimeout( function() {
								showLoading();
								content.load("ajax/case/info-absolut-exceptional.html", hideLoading); //load the case-study information
								video.load("ajax/videos/iphone/absolut-exceptional-iphone-poster.html", hideLoading); //load the video
								$("#case-projects-container").addClass('fade-in');
							}, 750);							
						}
					break;
				
					case "british-airways-film-vid":
						if($("#british-airways-film-vid").hasClass('active')){
							//alert('projects have already been loaded');
						}
						else{
							setTimeout( function() {
								showLoading();
								content.load("ajax/case/info-british-airways.html", hideLoading); //load the case-study information
								video.load("ajax/videos/iphone/british-airways-film-iphone-poster.html", hideLoading); //load the video
								$("#case-projects-container").addClass('fade-in');
							}, 750);														
						}
					break;
				
					case "british-airways-teaser-vid":
						if($("#british-airways-teaser-vid").hasClass('active')){
							//alert('projects have already been loaded');
						}
						else{
							setTimeout( function() {
								showLoading();
								content.load("ajax/case/info-british-airways-teaser.html", hideLoading); //load the case-study information
								video.load("ajax/videos/iphone/british-airways-teaser-iphone-poster.html", hideLoading); //load the video
								$("#case-projects-container").addClass('fade-in');
							}, 750);																					
						}
					break;
				
					case "nissan-co2-vid":
						if($("#nissan-co2-vid").hasClass('active')){
							//alert('projects have already been loaded');
						}
						else{
							setTimeout( function() {								
								showLoading();
								content.load("ajax/case/info-nissan-co2.html", hideLoading); //load the case-study information
								video.load("ajax/videos/iphone/nissan-co2-iphone-poster.html", hideLoading); //load the video
								$("#case-projects-container").addClass('fade-in');
							}, 750);																					
						}
					break;
				
					case "nissan-jtz-vid":
						if($("#nissan-jtz-vid").hasClass('active')){
							//alert('projects have already been loaded');
						}
						else{
							setTimeout( function() {																
								showLoading();
								content.load("ajax/case/info-nissan-jtz.html", hideLoading); //load the case-study information
								video.load("ajax/videos/iphone/nissan-jtz-iphone-poster.html", hideLoading); //load the video
								$("#case-projects-container").addClass('fade-in');
							}, 750);																												
						}
					break;
			}
		});		
		
	}
	
	
	
	// ........................THIS BEGINS THE BROWSER STUFF........................//
	
	
	
	else {
				
		// TURN OFF THE ROLLOVER IMAGES
		$('.not-current').css({'display':'none'});
		$('#initial-slide-wrapper').remove();
		
		// TURN OFF THE HTML5 STUFF
		$(".fade-in").removeClass("fade-in");
		$(".html5-transition").removeClass("html5-transition");
		$(".html5-transition-fast").removeClass("html5-transition-fast");
		
		// RESET CASE INFO - MOVE TRAY IN AND OUT
		function resetTray() {
			overlay.animate({"left":"-279px"}, 100);
			setTimeout( function() {
				overlay.animate({"left":"0px"}, 100);
			}, 1500);
		}
		
		// FIX THE OVERLAY TO STAY OUT AND THEN COME IN
		window.setTimeout(function(){
			$("#re-open").fadeOut(100);
			$("#close-case").delay(100).fadeIn(100);
			overlay.animate({"left":"0px"}, 250);
			},
		1000);
		
		// SET UP THE OPEN/CLOSE ACTIONS FOR THE CASE STUDY CONTAINER
		$("#close-case").click(function(){
			browserOverlayOut();
		});
		
		// OPEN LEFT TRAY		
		$("#re-open").click(function(){
			browserOverlayIn();
		});	
		
		
		
		// MAKE THE MENUS STICKY & SET UP AJAX FOR TOP MENU
		links.live('click', function(){
			
			//BRING IN OVERLAY
			var left = overlay.css("left");			
			
			$(".js-fade-in").fadeOut(250);
			$(".current-project").fadeOut(250);
			$(".js-fade-in").removeClass('js-fade-in');
			$(".active").removeClass('active');
			
			// MOVE IN OVERLAY AND CHANGE OPEN BUTTON TO CLOSE
			//overlay.animate({"left": "-279px"},200);
			//$("#re-open").fadeOut(100);
			//$("#close-case").delay(100).fadeIn(100);
							
			//LOAD SOME AJAX!
			switch(this.id){
				case "projects-anchor":
					if($("#projects-anchor").hasClass('active')){
						//alert('projects have already been loaded');
					}
					else{
						if (left != '0px'){
							$("#re-open").fadeOut(100);
							$("#close-case").delay(100).fadeIn(100);
							overlay.animate({"left":"0px"}, 250);
						}
						//$('video').get(0).pause();
						//video.addClass('fade-in-video');
						//video.css('display','block');
						$("#case-nav-container").addClass('js-fade-in');
						$(".js-fade-in").fadeIn(1000);
						
						$("#projects-anchor").addClass('active');
						// $("#case-nav-container").load("ajax/nav.html"); //load the case-study information
						
						$("#case-nav-container").fadeIn('slow');
						$("#contact-container-wrapper").fadeOut('slow');
						$("#bio-container-wrapper").fadeOut('slow');
					}
				break;	
			
				case "bio-anchor":
					if($("#bio-anchor").hasClass('active')){
						//alert('bio have already been loaded');
					}
					else{
						//FADE IN POSTER
						poster.css("z-index","200");
						poster.fadeIn(1000);
						
						//need video to pause
						$(video).hide();
						
						if (left != '-279px'){
							$("#close-case").fadeOut(100);
							$("#re-open").delay(100).fadeIn(100);
							overlay.animate({"left":"-279px"}, 250);
						}
						
						$("#bio-anchor").addClass('active');
						$("#bio-container-wrapper").load("ajax/bio.html").hide();//load the case-study information
						
						$("#poster-container").fadeIn('slow');
						
						
						$("#case-nav-container").fadeOut('slow');
						$("#contact-container-wrapper").fadeOut('slow');
						window.setTimeout(function(){
							$("#bio-container-wrapper").show();
							browserOverlayIn();
							},
						250);
					}
				break;

				case "contact-anchor":
					if($("#contact-anchor").hasClass('active')){
						//alert('contact has already been loaded');
					}
					else{
						//FADE IN POSTER
						poster.css("z-index","200");
						poster.fadeIn(1000);
						
						//need video to pause
						$(video).hide();
						
						if (left != '-279px'){
							$("#close-case").fadeOut(100);
							$("#re-open").delay(100).fadeIn(100);
							overlay.animate({"left":"-279px"}, 250);
						}
						
						$("#contact-anchor").addClass('active');
						$("#contact-container-wrapper").load("ajax/contact.html").hide(); //load the case-study information
						
						//$("#contact-container-wrapper").addClass('js-fade-in');
						//$(".js-fade-in").fadeIn(1000);
						
						$("#poster-container").fadeIn('slow');
						
						$("#case-nav-container").fadeOut('slow');
						$("#bio-container-wrapper").fadeOut('slow');
						
						window.setTimeout(function(){
							$("#contact-container-wrapper").show();
							browserOverlayIn();
							},
						250);
					}
				break;
			}	
			//evt.preventDefault(); // assuming your handler has "evt" as the first parameter
			//return false;
		});
		
		
		
		// SWITCH OUT AND SET INITIAL VIDEOS WHEN CLICKING ON PROJECTS SUBMENU
		projectsSublink.live('click', function(){
			$("#case-nav-container").fadeOut('slow');
			$("#initial-slide-wrapper").fadeOut('slow');
			$("#video-container").fadeIn('slow');
					
			showLoading();
			
			//SET TIMEOUT CHANGE Z-INDEX OF initalslidewrapper
			$("#initial-slide-wrapper").css("z-index","100");
			//poster.css("z-index","0");
			poster.fadeOut(1000);
			window.setTimeout(function(){
				poster.css("z-index","0");
				},
			1000);
				
			switch(this.id){
				
				case "skittles":
					if($("#skittles").hasClass('active')){
						//alert('projects have already been loaded');
					}
					else{
						showLoading();
						content.load("ajax/case/info-skittles-race.html", hideLoading).hide().fadeIn(1500); //load the case-study information
						video.load("ajax/videos/skittles-race-flash.html", hideLoading).hide().fadeIn(1500).addClass('fade-in'); //load the video
					}
				break;
				
				case "absolut":
					if($("#absolut").hasClass('active')){
						//alert('projects have already been loaded');
					}
					else{
						showLoading();
						content.load("ajax/case/info-absolut-orient.html", hideLoading).hide().fadeIn(1500); //load the case-study information
						video.load("ajax/videos/absolut-orient-flash.html", hideLoading).hide().fadeIn(1500).addClass('fade-in'); //load the video
					}
				break;
				
				case "british-airways":
					if($("#british-airways").hasClass('active')){
						//alert('projects have already been loaded');
					}
					else{
						showLoading();
						content.load("ajax/case/info-british-airways.html", hideLoading).hide().fadeIn(1500); //load the case-study information
						video.load("ajax/videos/british-airways-film-flash.html", hideLoading).hide().fadeIn(1500); //load the video
					}
				break;
				
				case "nissan":
					if($("#nissan").hasClass('active')){
						//alert('projects have already been loaded');
					}
					else{
						showLoading();
						content.load("ajax/case/info-nissan-jtz.html", hideLoading).hide().fadeIn(1500); //load the case-study information
						video.load("ajax/videos/nissan-jtz-flash.html", hideLoading).hide().fadeIn(1500); //load the video
					}
				break;
				
				case "connect-edu":
					if($("#connect-edu").hasClass('active')){
						//alert('projects have already been loaded');
					}
					else{
						showLoading();
						content.load("ajax/case/info-connect-edu.html", hideLoading).hide().fadeIn(1500); //load the case-study information
						video.load("ajax/videos/connect-edu-flash.html", hideLoading).hide().fadeIn(1500); //load the video
					}
				break;
				
				case "adidas":
					if($("#adidas").hasClass('active')){
						//alert('projects have already been loaded');
					}
					else{
						showLoading();
						content.load("ajax/case/info-adidas.html", hideLoading).hide().fadeIn(1500); //load the case-study information
						video.load("ajax/videos/adidas-flash.html", hideLoading).hide().fadeIn(1500); //load the video
					}
				break;
				
				case "skateboarding":
					if($("#skateboarding").hasClass('active')){
						//alert('projects have already been loaded');
					}
					else{
						showLoading();
						content.load("ajax/case/info-skateboarding.html", hideLoading).hide().fadeIn(1500); //load the case-study information
						video.load("ajax/videos/skateboarding-flash.html", hideLoading).hide().fadeIn(1500); //load the video
					}
				break;
				
				case "underdogs":
					if($("#underdogs").hasClass('active')){
						//alert('projects have already been loaded');
					}
					else{
						showLoading();
						content.load("ajax/case/info-underdogs.html", hideLoading).hide().fadeIn(1500); //load the case-study information
						video.load("ajax/videos/underdogs-flash.html", hideLoading).hide().fadeIn(1500); //load the video
					}
				break;
				
				case "a-good-life":
					if($("#a-good-life").hasClass('active')){
						//alert('projects have already been loaded');
					}
					else{
						showLoading();
						content.load("ajax/case/info-a-good-life.html", hideLoading).hide().fadeIn(1500); //load the case-study information
						video.load("ajax/videos/a-good-life-flash.html", hideLoading).hide().fadeIn(1500); //load the video
						
					}
				break;
				
				}
				evt.preventDefault(); // assuming your handler has "evt" as the first parameter
				return false;
				
		});
	
		videoThumb.live('click', function(){	
			$(".active").removeClass('active');
			$("#case-nav-container").fadeOut('slow');
			$("#initial-slide-wrapper").fadeOut('slow');
			$("#video-container").fadeIn('slow');
			
			//SET TIMEOUT CHANGE Z-INDEX OF  initalslidewrapper

			$("#initial-slide-wrapper").css("z-index","100");
			
			switch(this.id){
				case "skittles-race-vid":
					if($("#skittles-race-vid").hasClass('active')){
						//alert('projects have already been loaded');
					}
					else{
						showLoading();
						content.load("ajax/case/info-skittles-race.html", hideLoading).hide().fadeIn(1500); //load the case-study information
						video.load("ajax/videos/skittles-race-flash.html", hideLoading).hide().fadeIn(1500); //load the video
					}
				break;
				
				case "skittles-vaporize-vid":
					if($("#skittles-vaporize-vid").hasClass('active')){
						//alert('projects have already been loaded');
					}
					else{
						showLoading();
						content.load("ajax/case/info-skittles-vaporize.html", hideLoading).hide().fadeIn(1500); //load the case-study information
						video.load("ajax/videos/skittles-vaporize-flash.html", hideLoading).hide().fadeIn(1500); //load the video
					}
				break;
				
				case "skittles-shaolin-vid":
					if($("#skittles-shaolin-vid").hasClass('active')){
						//alert('projects have already been loaded');
					}
					else{
						showLoading();
						content.load("ajax/case/info-skittles-shaolin.html", hideLoading).hide().fadeIn(1500); //load the case-study information
						video.load("ajax/videos/skittles-shaolin-flash.html", hideLoading).hide().fadeIn(1500); //load the video
					}
				break;
				
				case "absolut-orient-vid":
					if($("#absolut-orient-vid").hasClass('active')){
						//alert('projects have already been loaded');
					}
					else{
						showLoading();
						content.load("ajax/case/info-absolut-orient.html", hideLoading).hide().fadeIn(1500); //load the case-study information
						video.load("ajax/videos/absolut-orient-flash.html", hideLoading).hide().fadeIn(1500); //load the video
					}
				break;
				
				case "absolut-differently-vid":
					if($("#absolut-differently-div").hasClass('active')){
						//alert('projects have already been loaded');
					}
					else{
						showLoading();
						content.load("ajax/case/info-absolut-differently.html", hideLoading).hide().fadeIn(1500); //load the case-study information
						video.load("ajax/videos/absolut-differently-flash.html", hideLoading).hide().fadeIn(1500); //load the video
					}
				break;
				
				case "absolut-exceptional-vid":
					if($("#absolut-exceptional-div").hasClass('active')){
						//alert('projects have already been loaded');
					}
					else{
						showLoading();
						content.load("ajax/case/info-absolut-exceptional.html", hideLoading).hide().fadeIn(1500); //load the case-study information
						video.load("ajax/videos/absolut-exceptional-flash.html", hideLoading).hide().fadeIn(1500); //load the video
					}
				break;
				
				case "british-airways-film-vid":
					if($("#british-airways-film-vid").hasClass('active')){
						//alert('projects have already been loaded');
					}
					else{
						showLoading();
						content.load("ajax/case/info-british-airways.html", hideLoading).hide().fadeIn(1500); //load the case-study information
						video.load("ajax/videos/british-airways-film-flash.html", hideLoading).hide().fadeIn(1500); //load the video
					}
				break;
				
				case "british-airways-teaser-vid":
					if($("#british-airways-teaser-vid").hasClass('active')){
						//alert('projects have already been loaded');
					}
					else{
						showLoading();
						content.load("ajax/case/info-british-airways-teaser.html", hideLoading).hide().fadeIn(1500); //load the case-study information
						video.load("ajax/videos/british-airways-teaser-flash.html", hideLoading).hide().fadeIn(1500); //load the video
					}
				break;
				
				case "nissan-co2-vid":
					if($("#nissan-co2-vid").hasClass('active')){
						//alert('projects have already been loaded');
					}
					else{
						showLoading();
						content.load("ajax/case/info-nissan-co2.html", hideLoading).hide().fadeIn(1500); //load the case-study information
						video.load("ajax/videos/nissan-co2-flash.html", hideLoading).hide().fadeIn(1500); //load the video
					}
				break;
				
				case "nissan-jtz-vid":
					if($("#nissan-jtz-vid").hasClass('active')){
						//alert('projects have already been loaded');
					}
					else{
						showLoading();
						content.load("ajax/case/info-nissan-jtz.html", hideLoading).hide().fadeIn(1500); //load the case-study information
						video.load("ajax/videos/nissan-jtz-flash.html", hideLoading).hide().fadeIn(1500); //load the video
					}
				break;
				
				case "underdogs-trailer-vid":
					if($("#underdogs-trailer-vid").hasClass('active')){
						alert('projects have already been loaded');
					}
					else{
						showLoading();
						content.load("ajax/case/info-underdogs-trailer.html", hideLoading).hide().fadeIn(1500); //load the case-study information
						video.load("ajax/videos/underdogs-trailer-flash.html", hideLoading).hide().fadeIn(1500); //load the video
						$("#case-projects-container").addClass('fade-in');
						
					}
				break;
				
				case "underdogs-vid":
					if($("#underdogs-vid").hasClass('active')){
						alert('projects have already been loaded');
					}
					else{
						showLoading();
						content.load("ajax/case/info-underdogs.html", hideLoading).hide().fadeIn(1500); //load the case-study information
						video.load("ajax/videos/underdogs-flash.html", hideLoading).hide().fadeIn(1500); //load the video
						$("#case-projects-container").addClass('fade-in');
						
					}
				break;
			
			}
		});
	
		// MAKE THE MENUS STICKY
		links.click(function(){
			$(".active").removeClass("active");
			$(this).addClass("active");
		});

		projects.click(function(){
			$(".active").removeClass("active");
			$(this).addClass("active");
		});
		
		// INDIVIDUAL HOVERS

			// SKITTLES
			$("#skittles").hover(
				function() {
					$("#skittles-poster").stop(true, true).fadeIn(500);
				},
				function() {
					$("#skittles-poster").stop(true, true).fadeOut(500);
			});
			
				$('#skittles').click(function() {
					$("#skittles-poster").stop(true, true).fadeOut(500);
				});

			// ABSOLUT	
			$("#absolut").hover(
				function() {
					$("#absolut-poster").stop(true, true).fadeIn(500);
				},
				function() {
					$("#absolut-poster").stop(true, true).fadeOut(500);
			});
			
				$('#absolut').click(function() {
					$("#absolut-poster").stop(true, true).fadeOut(500);
				});
			
			// BRITISH AIRWAYS	
			$("#british-airways").hover(
				function() {
					$("#british-airways-poster").stop(true, true).fadeIn(500);
				},
				function() {
					$("#british-airways-poster").stop(true, true).fadeOut(500);
			});
				
				$('#british-airways').click(function() {
					$("#british-airways-poster").stop(true, true).fadeOut(500);
				});
			
			// NISSAN
			$("#nissan").hover(
				function() {
					$("#nissan-poster").stop(true, true).fadeIn(500);
				},
				function() {
					$("#nissan-poster").stop(true, true).fadeOut(500);
			});
				
				$('#nissan').click(function() {
					$("#nissan-poster").stop(true, true).fadeOut(500);
				});

			// CONNECTEDU
			$("#connect-edu").hover(
				function() {
					$("#connect-edu-poster").stop(true, true).fadeIn(500);
				},
				function() {
					$("#connect-edu-poster").stop(true, true).fadeOut(500);
			});
			
				$('#connect-edu').click(function() {
					$("#connect-edu-poster").stop(true, true).fadeOut(500);
				});

			// ADIDIAS
			$("#adidas").hover(
				function() {
					$("#adidas-poster").stop(true, true).fadeIn(500);
				},
				function() {
					$("#adidas-poster").stop(true, true).fadeOut(500);
			});
			
				$('#adidas').click(function() {
					$("#adidas-poster").stop(true, true).fadeOut(500);
				});

			// SKATEBOARDING
			$("#skateboarding").hover(
				function() {
					$("#skateboarding-poster").stop(true, true).fadeIn(500);
				},
				function() {
					$("#skateboarding-poster").stop(true, true).fadeOut(500);
			});
			
				$('#skateboarding').click(function() {
					$("#skateboarding-poster").stop(true, true).fadeOut(500);
				});
				
			// UNDERDOGS
			$("#underdogs").hover(
				function() {
					$("#underdogs-poster").stop(true, true).fadeIn(500);
				},
				function() {
					$("#underdogs-poster").stop(true, true).fadeOut(500);
			});
			
				$('#underdogs').click(function() {
					$("#underdogs-poster").stop(true, true).fadeOut(500);
				});
			
			// A GOOD LIFE
			$("#a-good-life").hover(
				function() {
					$("#a-good-life-poster").stop(true, true).fadeIn(500);
				},
				function() {
					$("#a-good-life-poster").stop(true, true).fadeOut(500);
			});
			
				$('#a-good-life').click(function() {
					$("#a-good-life-poster").stop(true, true).fadeOut(500);
				});
		
	}
	
});
