// emota.com - Javascript Document

/*------------------------------------------------------------------------------------------------*/
	
// Removing all pageTracker code for development
	
//Cufon.replace('#subNavMenu li');
	
/*
********************************
||	START - Variable Declaration
*********************************
*/
	
var projMenu = false; // Tracks the Creations menu state - Boolean
var cwMenu = null; // Tracks the current clients Projects menu - Number
var clientList = []; // Array to hold all of the clients. Builds client menu - Array
var bioList = []; // Array to hold all of the bios. Builds bio menu - Array
var mediaPlayer;
var emMediaPlayer;
var demoPlayer;
var currVidSel;
var creationSNMenu = false; // Holds the currently selected sub nav menu item
	
/*
********************************
||	END - Variable Declaration
*********************************
*/
// [ Client Reference/URL , Displayed Name ]
clientList[0] = ["levis", "Levi's"];
clientList[1] = ["sdac", "San Diego Ad Club"];
clientList[2] = ["temp", "Tempur-Pedic"];
clientList[3] = ["dockers", "Dockers"];
clientList[4] = ["qmt", "Qualcomm MEMS Tech."];
clientList[5] = ["zandra", "Zandra Rhodes"];
clientList[6] = ["cr", "Charlotte Russe"];
clientList[7] = ["blanch", "Ken Blanchard"];
clientList[8] = ["nik", "NIK Software"];
clientList[9] = ["usao", "USAopoly"];
clientList[10] = ["transc", "TranscenDance"];
clientList[11] = ["sbcs", "SBCS"];
clientList[12] = ["sung", "Sungevity"];
clientList[13] = ["tnw", "The Nervous Wreckords"];
clientList[14] = ["emota", "emota Inc."];
clientList[15] = ["vtea", "Vida Tea"];
clientList[16] = ["people", "People’s Liberation"];
clientList[17] = ["mdbd", "Motion Graphics"];
	
// [ Bio Reference/URL , Displayed Name ]
// bioList[0] = ['em','emota Inc.'];		
bioList[0] = ["ck", "Chris Karcher"];
bioList[1] = ["tp", "Terry Parish"];
bioList[2] = ["bc", "Bekah Christie"];
bioList[3] = ["jb", "Jacinda Buchanan"];
bioList[4] = ["lr", "Lee Regan"];
bioList[5] = ["bk", "Brian Kim"];
bioList[6] = ["as", "Annie Sullivan"];

	
/*------------------------------------------------------------------------------------------------*/

	/*
	********************************
	||	START - JQuery Setup
	*********************************
	*/
	$(document).ready(function() {
		
		emMediaPlayer = flowplayer("emota_player", "swf/flowplayer.commercial-3.2.7.swf",  {
			// player configuration goes here
			
			clip: {
				autoplay: true,
				baseUrl: "http://d5xvrj3ojw0wo.cloudfront.net/production/encoded-videos/",
				onFinish: function() {
					
      				if ( $('#clBG') ){
      					$('#clBG').show();
      				};
      				
      				if ( $('#emBG') ){
      					$('#emBG').show();
      				};
      				
					// Fade in the menu and background graphic
  					$('#videoDisplay').fadeTo(100, 0, function(){
  						$('#emota_player').hide();
  						$('#videoDisplay').css({'z-index':"4"});
  						$('#pageContent').fadeTo('slow', 1).css({'z-index':"10"});
  					});
				},
				onResume: function() {
					$('#emota_player').show();
					
					$('#pageContent').fadeTo('fast', 0, function(){
						$('#pageContent').css({'z-index':"4"});
						$('#vidDisplay').css({'z-index':"10"});
					});
				},
				onPause: function() {
					// Fade in the menu and background graphic
					if ( $('#clBG') ){
						 console.log('clBG found so going that route');
						$('#clBG').hide();
						$('#videoDisplay').css({'z-index':"4"});
						$('#pageContent').fadeTo('fast',1).css({'z-index':"10"});
					} else if ( $('#emBG') ){
						 console.log('emBG found so going that route');
						$('#emBG').hide();
						$('#videoDisplay').css({'z-index':"4"});
						$('#pageContent').fadeTo('fast',1).css({'z-index':"10"});
					} else {
						$('#videoDisplay').fadeTo(600, 0, function(){
  							$('#emota_player').hide();
  							$('#videoDisplay').css({'z-index':"4"});
  							$('#pageContent').fadeTo('fast', 0).css({'z-index':"10"});
  						});
					};
  					
				}
			},
			canvas: {
				backgroundColor: '#e9e9e9',
				backgroundImage: 'url(/images/ui/emota_vidload_bg.jpg)',
				backgroundGradient: 'none'
			},
			play: {
				url: '/images/ui/emota_watermark.png',
				opacity: 0.8,
				label: null,
				replayLabel: 'Replay',
				fadeSpeed: 500,
				rotateSpeed: 50
			}
		});
		
		// Replace Text
		Cufon.replace('#footer h2', {fontFamily: 'helvneue-light'});
		//Cufon.replace('#navmenu li a');
		//Cufon.replace('#subNavMenu li');
		
		$("#navmenu li a, #subNavMenu li").hover(function(){
			$(this).stop(true, true).animate( {color: '#ff341f'}, 400 );
		}, function(){
			$(this).stop(true, true).animate( {color: '#808080'}, 600 );
		});
		
		$("#footer .footerLinks .popTOS").hover(function(){
			$(this).stop(true, true).animate( {color: '#ff341f'}, 200 );
		}, function(){
			$(this).stop(true, true).animate( {color: '#808080'}, 600 );
		}).click(function(){
			switch($(this).text()) {
				case "Privacy Policy":
					$.fn.colorbox({href:"privacypolicy.html", width:'700px', height:'500px;', overlayClose:true});
					// pageTracker._trackEvent('Privacy Policy', 'View');
					break;
				
				case "Terms of Service":
					$.fn.colorbox({href:"tos.html", width:'700px', height:'500px;', overlayClose:true});
					// pageTracker._trackEvent('Terms of Service', 'View');
					break;
			}
			
		});
		
		$("#footer .socialLinks a").hover(function(){
			$(this).parent().css( {cursor:'pointer'} );
			$(this).parent().stop(true, true).animate({backgroundPosition: "(0 16px)"}, {duration:400});
		}, function(){
			$(this).parent().stop(true, true).animate({backgroundPosition: "(0 0)"}, {duration:600});
		});
		
		
		
		$("#footer .socialLinks .fbIcon").click(function(){
			// pageTracker._trackEvent('Social Media', 'Navigation', 'Facebook');
		});
		$("#footer .socialLinks .twIcon").click(function(){
			// pageTracker._trackEvent('Social Media', 'Navigation', 'Twitter');
		});
		$("#footer .socialLinks .wpIcon").click(function(){
			// pageTracker._trackEvent('Social Media', 'Navigation', 'WordPress');
		});
		$("#footer .socialLinks .ytIcon").click(function(){
			// pageTracker._trackEvent('Social Media', 'Navigation', 'YouTube');
		});
		
		
		$('.clNav_previous').fadeTo(100,0);
		$('.clNav_next').fadeTo(100,0);
		
		// pageTracker._trackEvent('Videos_Introductions', 'Play', 'video_loops');
      	
		
		/*-----------------------------------------------------------*/
		// JQuery Address Setups
		/*-----------------------------------------------------------*/
		// $.address.
		
		// JQuery Address Event handlers
		$.address.strict(false).hash('');
		
		setupIntro();
		
	});
	
	/*
	********************************
	||	END - JQuery Setup
	*********************************
	*/
	
/*------------------------------------------------------------------------------------------------*/
	
	/*
	********************************
	||	START - Methods
	*********************************
	*/
	
	function setupIntro(){
		//Start clicker
		$('.playStart, .replayReel').click(function() {
			// console.log("Intro video should be playing");
  			$('#pageContent').fadeTo('slow', 0.0, function(){
  				
  				$('.landStart').hide();
  				$('#emota_player').show();
				$('#videoDisplay').fadeTo('fast', 1.0,function(){
					playVideoNow("emota_intro_2011_V6_tag_1_mH720.mp4");
					$('#videoDisplay').css({'z-index':"10"});
					$('#pageContent').css({'z-index':"2"});

				});				
			});
		});
		
		
		$('.viewCreations').click(function(){
			updateSectionsMenu($('.creations'));
			$('.creations').animate( {color: '#ff341f'}, 400 );
			$('#subNavMenu').fadeTo('fast', 0, function() {
				$(this).children('[class^="clg"]').remove();
				projectMenu(true);
				generateSubMenu(clientList);
				
			});
			
			$('.creations').click();
			
		});
		
		// console.log('Intro video is ready to play');
		
	}
	
	function playVideoNow(newClip){
		$('#pageContent').fadeTo('fast', 0, function(){
  			$('#emota_player').show();
			$('#videoDisplay').fadeTo('slow', 1,function(){
				//emMediaPlayer.getClip(0).update({url: newClip});
				emMediaPlayer.play({url: newClip});
				$('#videoDisplay').css({'z-index':"10"});
				$('#pageContent').css({'z-index':"2"});
			});				
		});
	}
	
	// ------------------------------------------------------------------------------------------ //
	// CREATE A SUB MENU LOCATED IN THE HEADER
	// ------------------------------------------------------------------------------------------ //
	
	function generateSubMenu(whichList){
		var num = whichList.length;
		if (num == 0) {
   			
		} else {
			 
    		var tc = 9; // Number of clients per group
    		var cn = 3; // Number of clients per list
    		var lcv = 1; // For each DIV group
    		var scv = 1; // For each UL in groups
    		var groupCount = 1;
    		var listCount = 1;
    		var totalNav = '<div class="contain"> <div class="clg'+ listCount +' clgMenu"><ul class="subNav col'+ groupCount +'">';
			if(whichList == bioList){
    			for (i=0; i < whichList.length; i++) {
        		
        			// Create LI's
        			totalNav += '<li class="'+ whichList[i][0] +'">'+ whichList[i][1] +'</li>';
        		
        			// Create UL's
        			if (scv++ % cn == 0 && scv < num) {
        				(groupCount == 3) ? groupCount = 1 : groupCount++;
        				totalNav += '</ul><ul class="subNav col'+ groupCount +'">';
        				scv = 1;
        			};

        			// Create DIV's
        			if (lcv++ % tc == 0 && lcv < num) { // every Nth item, unless we're done
						listCount++
            			totalNav += '</ul></div><div class="clg'+ listCount +' clgMenu"><ul class="subNav col'+ groupCount +'">';
            			lcv = 1;
        			};
    			};
    		} else {
    			for (i=0; i < whichList.length; i++) {
        		
        			// Create LI's
        			totalNav += '<li class="'+ whichList[i][0] +'"><a class="clientLink" href="creations/'+ whichList[i][0] +'.html" rel="address:/creations/'+ whichList[i][0] +'">'+ whichList[i][1] +'</a></li>';
        		
        			// Create UL's
        			if (scv++ % cn == 0 && scv < num) {
        				(groupCount == 3) ? groupCount = 1 : groupCount++;
        				totalNav += '</ul><ul class="subNav col'+ groupCount +'">';
        				scv = 1;
        			};

        			// Create DIV's
        			if (lcv++ % tc == 0 && lcv < num) { // every Nth item, unless we're done
						listCount++
            			totalNav += '</ul></div><div class="clg'+ listCount +' clgMenu"><ul class="subNav col'+ groupCount +'">';
            			lcv = 1;
        			};
    			};
    		}
    		totalNav += '</ul></div></div>';
    		$('#submController').empty().html(totalNav);
    		$('#subNavMenu').fadeTo('slow', 1, function(){
    			var divWidth = $('#header #submController .contain').children().length*370;
   				$('#header #submController .contain').css('width',divWidth);
    			subNavConnect();
    		});
    		
		};
		
		currProject = null;
		
		$("#subNavMenu li").hover(function(){
				$(this).stop(true, true).animate( {color: '#ff341f'}, 400 );
			}, function(){
				$(this).stop(true, true).animate( {color: '#808080'}, 600 );
			}).click(function(){
				updateProjectsMenu($(this))
			});
		
	}
	
	
	// ------------------------------------------------------------------------------------------ //
	// CREATE THE CLIENT LIST MENU FOR THE CREATIONS PAGE
	// ------------------------------------------------------------------------------------------ //
	
	function generateClientMenu(){
		var num = clientList.length;
		if (num == 0) {
   			$('#gclDisplay').append('<div>There are no clients</div>');
		} else {
			var tp = 9; // Number of projects per group
    		var cn = 3; // Number of projects per list
    		var lcv = 1; // For each UL group
    		var scv = 1; // For each LI in projects
    		var groupCount = 1;
    		var totalNav = '<div><ul class="msNav">';
			
    		for (i=0; i < clientList.length; i++) {
				// Create UL's
        		if (scv++ % cn == 0 && scv < num) {
        			totalNav += '<li><a class="clientLink" href="creations/'+ clientList[i][0] +'.html" rel="address:/creations/'+ clientList[i][0] +'" title="'+ clientList[i][0] +'" style="background-image:url(images/clients/medium_thumbs/'+ clientList[i][0] +'_medium_c.jpg);"><img src="images/clients/medium_thumbs/'+ clientList[i][0] +'_medium_bw.jpg" alt="" class="a" /></a></li>';
        			(groupCount == 3) ? groupCount = 1 : groupCount++;
        			
        			scv = 1;
        		} else {
        			totalNav += '<li><a class="clientLink" href="creations/'+ clientList[i][0] +'.html" rel="address:/creations/'+ clientList[i][0] +'" title="'+ clientList[i][0] +'" style="background-image:url(images/clients/medium_thumbs/'+ clientList[i][0] +'_medium_c.jpg);"><img src="images/clients/medium_thumbs/'+ clientList[i][0] +'_medium_bw.jpg" alt="" class="a" /></a></li>';
        		}
        		
        		if(lcv++ % tp == 0 && lcv < num)
        			totalNav += '</ul><ul class="msNav">';

    		}
    		totalNav += '</ul></div>';
    		$('#gclDisplay').html(totalNav);
    		
		}
		
		$('#gclDisplay li a').click(function(){
			var thisName = $(this).attr('title')
			updateProjectsMenu($('.subNav li[class*='+thisName+']'));
		});
		
		currProject = null;
		
		$("#subNavMenu li").hover(function(){
				$(this).children('a').stop(true, true).animate( {color: '#ff341f'}, 400 );
			}, function(){
				$(this).children('a').stop(true, true).animate( {color: '#808080'}, 600 );
			}).click(function(){
				updateProjectsMenu($(this).children('a'))
			});
		
	}
	
	// ------------------------------------------------------------------------------------------ //
	// CREATE A PROJECT MENU ON A CLIENT PAGE
	// ------------------------------------------------------------------------------------------ //
	
	function generateProjects(projectList){
		var num = projectList.length;
		// alert(num);
		if (num == 0) {
   			$('#clpMenu').append('<div>There are no clients</div>');
		} else {
			var tp = 6; // Number of projects per group
    		var cn = 3; // Number of projects per list
    		var lcv = 1; // For each UL group
    		var scv = 1; // For each LI in projects
    		var groupCount = 1;
    		var totalNav = '<div><ul>';

    		for (i=0; i < projectList.length; i++) {
				// Create UL's
				// alert("Time to create a last "+ (scv % cn == 0)+" and "+ (scv < num));
        		if ( scv < num && scv++ % cn == 0) {
        			totalNav += '<li class="last"><div class="projNum" title="'+ i +'" style="background-image: url('+ projectList[i][1] +')"><div style="background-image: url('+ projectList[i][0] +')"  class="tmb"></div></div></li>';
        			(groupCount == 3) ? groupCount = 1 : groupCount++;
        			
        			scv = 1;
        		} else {
        			totalNav += '<li><div class="projNum" title="'+ i +'" style="background-image: url('+ projectList[i][1] +')"><div style="background-image: url('+ projectList[i][0] +')"  class="tmb"></div></div></li>';
        		}
        		
        		if(lcv++ % tp == 0 && lcv < num)
        			totalNav += '</ul><ul>';

    		}
    		totalNav += '</ul></div>';
    		$('#clpMenu').html(totalNav);
    		setupPage();	
		}
	};
	
	
	
	
	function setupPage() {
		$('.clProjectPlay').fadeOut('fast');
		
		var currentProject = null;
		
		$('#clProjects').serialScroll({
			target: '#clpMenu',
			items: 'ul',
			prev: 'div.clpNav-prev',
			next: 'div.clpNav-next',
			axis: 'x',
			duration: 500,
			cycle: false,
			lazy: true,
			onBefore: function( e, elem, $pane, $items, pos ){
				
				e.preventDefault();
				if( this.blur )
					this.blur();
				
				
				if (  pos != $items.length - 1 && pos != 0 ) {
						$('.clpNav-prev').fadeTo(100,1);
						$('.clpNav-next').fadeTo(100,1);
					} else if( pos == 0 && $items.length > 1 ) {
						$('.clpNav-prev').fadeTo(100,0);
						$('.clpNav-next').fadeTo(100,1);
					} else if (pos == $items.length - 1 && $items.length > 1) {
						$('.clpNav-prev').fadeTo(100,1);
						$('.clpNav-next').fadeTo(100,0);
					} else {
						$('.clpNav-prev').fadeTo(100,0);
						$('.clpNav-next').fadeTo(100,0);
					}
			},
			onAfter: function( elem ){

			}
		});
		
		//
		$('#clpMenu div ul li div').each(function(){
			activateProject($(this));
		});
		
		var divWidth = $('#clProjects #clpMenu').children().length*395;

    	$('#clProjects #clpMenu div').first().css('width',divWidth);
		
		$('#clpMenu').trigger('goto',[0]);
		
		//
		function activateProject(tNail){
			$(tNail).children(".tmb").fadeIn('slow');
			$(tNail).hover( function() {
				$(this).children(".tmb").stop(true, true).fadeOut('fast');
			}, function() {
				$(this).children(".tmb").stop(true, true).fadeIn('slow');
			});
		}
		
		//
		function deActivateProject(tNail){
			//// console.log('Current Project is: '+currentProject)
			$(tNail).unbind('mouseenter mouseleave');
			$(tNail).children(".tmb").fadeOut('fast');
			activateProject(currentProject);
			currentProject = tNail;
		}
		
		$('#clpMenu div ul li div.projNum').click( function() {
			
			var pImage = clProjectsTracking[$(this).attr('title')][2];
			var pTitle = clProjectsTracking[$(this).attr('title')][3];
			
			// $.address.value( $.address.path() + clProjectsTracking[$(this).attr('title')][3]);
			// Change Project Title
			$('.clProjectName').html(clProjectsTracking[$(this).attr('title')][3]);
			// Change Project Description
			$('.clProjectDesc').html(clProjectsTracking[$(this).attr('title')][4]);
			// Load New Video
			$('.clProjectPlay').fadeIn('fast');
			currVidSel = clProjectsTracking[$(this).attr('title')][5];
			deActivateProject($(this));
			
		});
  		
  		$('.clProjectPlay').hover(function(){
				$(this).stop(true, true).animate( {color: '#FA1710'}, 400 );
			}, function(){
				$(this).stop(true, true).animate( {color: '#AAAAAA'}, 600 );
			}).click(function() {
  				playVideoNow(currVidSel+'_mH720.mp4');
			});
		
	};
	
	
	// ------------------------------------------------------------------------------------------ //
	// USED TO SYNC BOTH THE GRAPHICAL AND TEXT BASED MENU
	// ------------------------------------------------------------------------------------------ //
	
	function subNavConnect(g) {
		
		$('#header').serialScroll({
			target: '#submController',
			items: '.contain div',
			prev: 'div.clNav_previous',
			next: 'div.clNav_next',
			axis: 'x',
			duration: 500,
			cycle: false,
			lazy: true,
			onBefore: function( e, elem, $pane, $items, pos ){
				//alert($items.length+" and "+pos);

				e.preventDefault();
				if( this.blur )
					this.blur();
				
				if (  pos != $items.length - 1 && pos != 0 ) {
						$('.clNav_previous').fadeTo(100,1);
						$('.clNav_next').fadeTo(100,1);
					} else if( pos == 0 && $items.length > 1 ) {
						$('.clNav_previous').fadeTo(100,0);
						$('.clNav_next').fadeTo(100,1);
					} else if (pos == $items.length - 1 && $items.length > 1) {
						$('.clNav_previous').fadeTo(100,1);
						$('.clNav_next').fadeTo(100,0);
					} else {
						$('.clNav_previous').fadeTo(100,0);
						$('.clNav_next').fadeTo(100,0);
					}
				
				if($(e.target).attr('class') == 'clNav_next' || $(e.target).attr('class') == 'clNav_previous' ){
					clMenusSync('textCL', pos);
				}
			},
			onAfter: function( elem ){
				
			}
		});
		$('#submController').trigger('goto',[0]);
		Cufon.refresh();
	}
	
	
	// ------------------------------------------------------------------------------------------ //
	// USED TO SYNC BOTH THE GRAPHICAL AND TEXT BASED MENU
	// ------------------------------------------------------------------------------------------ //
	
	function clMenusSync(menuInit, elem){
		//alert(elem);
		if(menuInit == 'graphCL'){
			
			$('#submController').trigger( 'goto', [ elem ] );

		} else if (menuInit == 'textCL'){
			
			$('#gclDisplay').trigger( 'goto', [ elem ] );
			
		} else {
			// do nothing
		}
		
	}
	
	
	// ------------------------------------------------------------------------------------------ //
	// HANDLE THE PRELOAD OF NEW CONTENT
	// ------------------------------------------------------------------------------------------ //
	
	function fadeAndLoad(newContent){
		// console.log('... currently fading out current content and loading in new content ...');
		emMediaPlayer.stop();
		$('#videoDisplay').fadeTo(250, 0.0, function(){
  			
  			$('#emota_player').hide();
  			$('#videoDisplay').css({'z-index':"4"});
  			
  		});
  		
		$('#contentDisplay').stop(true, true).fadeTo(800, 0.0, function(){
			$('#pageContent').fadeTo(250, 1.0).css({'z-index':"10"});
			$('#videoDisplay').css({'z-index':"1"});			
			pullAjax(newContent);
		});
		
	};
	
	
	// ------------------------------------------------------------------------------------------ //
	// AJAX CALL TO PULL IN A NEW PAGE
	// ------------------------------------------------------------------------------------------ //
	
	function pullAjax(newPage){
		$.ajax({
	    		cache: false,
	    		url: newPage,
	    		dataType: 'html',
  				complete: function(data) {
  					// console.log("AJAX call complete.\nRequesting: "+newPage);
					if(data.status == 200) {
  						$("#pageContent").empty().html(data.responseText).show();
	    				$('#contentDisplay').stop(true, true).fadeTo(1000, 1.0, function(){
	    					if(newPage == 'about.html'){
	    						setupBios();
	    					} else if(newPage == 'connect.html') {
	    						//addthis.toolbox('#atShare');
	    					} else {
	    				
	    					}
	    				});
	    				
	    			}
	    			
  			}
    	});
	}
	
	
	// ------------------------------------------------------------------------------------------ //
	// SWAP A VIDEO OUT FOR A NEW ONE - reutrn code to be placed into element
	// ------------------------------------------------------------------------------------------ //
	/*
	function swapVideo(newVideo, newBG) {
		// mediaPlayer = null;
		//unbindVideoListeners();
		
		var getVideo = '<video id="'+newVideo+'" class="video-js" width="960" height="540" controls preload="none" poster="'+newBG+'">'+
      			'<source src="http://d5xvrj3ojw0wo.cloudfront.net/production/encoded-videos/'+newVideo+'_mH720.mp4" type=\'video/mp4; codecs="avc1.42E01E, mp4a.40.2"\' />'+
      			'<source src="http://d5xvrj3ojw0wo.cloudfront.net/production/encoded-videos/'+newVideo+'_mH360.mp4" type=\'video/mp4; codecs="avc1.42E01E, mp4a.40.2"\' />'+
      			'<source src="http://d5xvrj3ojw0wo.cloudfront.net/production/encoded-videos/'+newVideo+'_andM320.mp4" />'+
      			'<source src="http://d5xvrj3ojw0wo.cloudfront.net/production/encoded-videos/'+newVideo+'_aaM540.webm" type=\'video/webm; codecs="vp8, vorbis"\' />'+
      			'<source src="http://d5xvrj3ojw0wo.cloudfront.net/production/encoded-videos/'+newVideo+'_abM540.ogg" type=\'video/ogg; codecs="theora, vorbis"\' />'+
      			'<source src="http://d5xvrj3ojw0wo.cloudfront.net/production/encoded-videos/'+newVideo+'_mbM240.3gp" media="handheld"/>'+
      			'<div id="flash_'+newVideo+'" class="vjs-flash-fallback" width="960" height="540" href="http://d5xvrj3ojw0wo.cloudfront.net/production/encoded-videos/'+newVideo+'_mH720.mp4"></div>'+
    		'</video>';
    	
			//mediaPlayer = VideoJS.setup("project_video");
			setTimeout(function(){
				bindVideoListeners(newVideo);
			}, 250);
  		
    	return 	getVideo;
    }
    */
    
    // ------------------------------------------------------------------------------------------ //
	// BIND VIDEO LISTENERS
	// ------------------------------------------------------------------------------------------ //
    /*
    function bindVideoListeners(videoID) {
    	
    	mediaPlayer = VideoJS.setup(videoID, { 
        	controlsHiding: true, 
        	controlsBelow: false, 
       		showControlsAtStart: true,
        	playerFallbackOrder: ["html5","flash","links"]
      	});
    	
    	// Variable for tracking seek of video for menu delays
    	var seekCapture = false;
    	
    	// Set seek to true while seeking
    	$('#'+videoID).bind('seeking', function () {
  			seekCapture = true;
		} );
		
		// Set seek to false when done seeking
		$('#'+videoID).bind('seeked', function () {
			seekCapture = false;
		} );
		
		// Video pause setup
		mediaPlayer.onPause(function(){
			// Set timeout to check if seeking - HACK but only way at the moment
			setTimeout(function(){
				// If not seeking...
				if(!seekCapture){
					// Then fade out the menu
					$('#clMenu').fadeIn('750', function() {
  					// $('#clVideo').fadeTo(100, 0);
  					});
  				}
			},250);
			// console.log('Media is Paused');
		});
		
		// Video ended setup
		mediaPlayer.onEnded(function(){
			// Fade in the menu and background graphic
			setTimeout(function(){
  				$('#clMenu, #clBG').fadeIn('slow', function() {
  					// When above is complete fade out the video
  					$('#clVideo').fadeTo(100, 0);
  				});
  				// If in fullscreen then exit
  				// mediaPlayer.exitFullScreen();
  			},250);
  			// console.log('Media has ended');
		});
		
		// Video play setup
		mediaPlayer.onPlay(function(){
    		// Fade in the video
    		setTimeout(function(){
  				$('#clVideo').fadeTo(100, 1);
  				// Fade out the menu and background graphic
  				$('#clMenu, #clBG').fadeOut('slow');
  			},250);
  			// console.log('Media is Playing');
		});
    	
    }
	*/
    
    // ------------------------------------------------------------------------------------------ //
	// UNBIND VIDEO LISTENERS
	// ------------------------------------------------------------------------------------------ //
    /*
    function unbindVideoListeners() {
    	$('#project_video').unbind("seeking").unbind("seeked");
    	mediaPlayer = undefined;
    }
    */
    
    // ------------------------------------------------------------------------------------------ //
	// BIND INTRO VIDEO LISTENERS
	// ------------------------------------------------------------------------------------------ //
    /*
    function bindIntroVideoListeners() {
    	setTimeout(function(){
			demoPlayer.play();
			// console.log('Media is playing');
		},800);
		
		// Video ended setup
		demoPlayer.onEnded(function(){
			// Fade in the menu and background graphic
  			$('#demo-reel').fadeTo(10, 0, function(){
  				$('#demo-reel').css({'z-index':"4"});
  				$('.landEnd').fadeTo('slow', 1, function(){
  					$(this).css({'z-index':"5"})
  				});
  			});
  			demoPlayer.exitFullScreen();
  			// console.log('Media has ended');
		});
    	
    }
    */
	
	// ---------------------------------------------------------------------------------------------------------------------------------------------------------- //
	//
	// ---------------------------------------------------------------------------------------------------------------------------------------------------------- //
	function projectMenu(state){
	
		// pageTracker._trackEvent('Menu', 'Select', 'Projects')
	}
	
	// ---------------------------------------------------------------------------------------------------------------------------------------------------------- //
	// Tracking system for the projects menu
	// ---------------------------------------------------------------------------------------------------------------------------------------------------------- //
	
	var currProject = null;
	function updateProjectsMenu(newProject){
		// alert($(newProject).attr("class"));
		$(currProject).stop(true, true).removeClass('selProj').animate( {color: '#808080'}, 600 ).hover(function(){
			$(this).stop(true, true).animate( {color: '#ff341f'}, 400 );
		}, function(){
			$(this).stop(true, true).animate( {color: '#808080'}, 600 );
		});
		$(newProject).unbind('mouseenter mouseleave').addClass('selProj');
		currProject = newProject;
	}
	
	// ---------------------------------------------------------------------------------------------------------------------------------------------------------- //
	// Tracking system for the sections menu
	// ---------------------------------------------------------------------------------------------------------------------------------------------------------- //
	
	var currSection = null;
	function updateSectionsMenu(newSection){
		$(currSection).stop(true, true).removeClass('selSection').animate( {color: '#808080'}, 600 ).hover(function(){
			$(this).stop(true, true).animate( {color: '#ff341f'}, 400 );
		}, function(){
			$(this).stop(true, true).animate( {color: '#808080'}, 600 );
		});
		$(newSection).unbind('mouseenter mouseleave').addClass('selSection');
		currSection = newSection;
	}
	
	function rebindSectClick(){
		$('.creations, .connect, .emota').click(function(){
			var mlSel = $(this).attr('class');
			updateSectionsMenu($(this));
			$('#subNavMenu').fadeTo('fast', 0, function() {
				$(this).children('[class^="clg"]').remove();
				if( mlSel == 'creations' ) {
					// Generate the client menu
					generateSubMenu(clientList);
				} else if ( mlSel == 'emota' ) {
					// Generate the bios menu
					generateSubMenu(bioList);
				} else {
					// Dont do anything
				}
			});
			
			fadeAndLoad( $(this).attr('href') );
			
		});
	}
	
	// ---------------------------------------------------------------------------------------------------------------------------------------------------------- //
	// Tracking system for the projects videos menu
	// ---------------------------------------------------------------------------------------------------------------------------------------------------------- //
	
	var currProjVideo = null;
	function updateVideosMenu(newVideo){
		if(currProjVideo != null) {
			$(currProjVideo).stop(true, true).removeClass('selVideo').animate( {color: '#808080'}, 600 ).hover(function(){
				$(this).stop(true, true).animate( {color: '#ff341f'}, 400 );
			}, function(){
				$(this).stop(true, true).animate( {color: '#808080'}, 600 );
			});
		}
		$(newVideo).unbind('mouseenter mouseleave').addClass('selVideo').stop(true, true).animate( {color: '#ff341f'}, 400 );
		currProjVideo = newVideo;
	}
	
	
	
	// ------------------------------------------------------------------------------------------ //
	// CLEAR AND RESET PROJECT MENU
	// ------------------------------------------------------------------------------------------ //
	
	function clearProjMenu(){
		updateProjectsMenu(null);
	}
	
	
	// ------------------------------------------------------------------------------------------ //
	// HANDLE ADDRESS CHANGES - ||**DEPRICATED**||
	// ------------------------------------------------------------------------------------------ //
	
	$.address.change(function(event){
			
			// addressChangeHandler
			var toMatch = event.value; // Our value we are using to compare
			var navtoCreations = /^\/creations$/; // regex for Creations
			var navtoClient = /^\/creations[\/+A-z]/; // regex for Client
			var navtoConnect = /^\/connect$/; // regex for Connect
			var navtoAbout = /^\/emota$/; // regex for About
			var navtoIntro = /^\/intro$/; // regex for Intro
			
			// Create some logs so we can track progress
			// console.log('Change in address requested. Switching to: '+event.value+' \nDetails for match: '+toMatch.match(/^\S+$/)+' \ncreationSNMenu is currently '+creationSNMenu);
			
			// Check for a match to the Creations section
			if( navtoCreations.test(toMatch) ) {
				$('#submController').empty();
				$('#subNavMenu').fadeTo('fast', 0, function() {
					
				});
				$('.creations').css('color', '#ff341f');
				updateSectionsMenu($('.creations'))
    			generateSubMenu(clientList);
    			subNavConnect();
    			// console.log('Match for Creations main page');
    			fadeAndLoad(toMatch +'.html');
    			
    		}
    		
    		// Check for a match to a Client
    		if( navtoClient.test(toMatch) ) {
    			if(!creationSNMenu){
    				// console.log('Loading from an external link')
    				$('#submController').empty();
    				$('#subNavMenu').fadeTo('fast', 0, function() {
						
					});
					$('.creations').css('color', '#ff341f');
					updateSectionsMenu($('.creations'))
    				generateSubMenu(clientList);
    				subNavConnect();
    				$('#subNavMenu li[class*="'+event.pathNames[1]+'"] .clientLink').css('color', '#ff341f');
    				creationSNMenu = true;
    			}
				// console.log('Match for a Client');
				fadeAndLoad(toMatch +'.html');
    			
    		}
    		
    		// Check for a match to the Connect section
    		if( navtoConnect.test(toMatch) ) {
    			$('#submController').empty();
    			$('#subNavMenu').fadeTo('fast', 0, function() {
					
				});
				$('.connect').css('color', '#ff341f');
				updateSectionsMenu($('.connect'));
				// console.log('Match for Connect');
				fadeAndLoad(toMatch +'.html');
				
    		}
    		
    		// Check for a match to the About section
    		if( navtoAbout.test(toMatch) ) {
    			$('#submController').empty();
    			$('#subNavMenu').fadeTo('fast', 0, function() {
					
				});
				$('.emota').css('color', '#ff341f');
				updateSectionsMenu($('.emota'));
				toMatch = 'about';
				generateSubMenu(bioList);
				// console.log('Match for About');
				fadeAndLoad(toMatch +'.html');
				
    		}
    		
    		// Check for a match to the Intro section
    		if( navtoIntro.test(toMatch) ) {
    			$('#submController').empty();
    			$('#subNavMenu').fadeTo('fast', 0, function() {
					
				});
    			$('.intro').click();
    			updateSectionsMenu(null);
    			// console.log('Match for Intro');
    			fadeAndLoad(toMatch +'.html');
    			
    		}
    		
			
		});
    
      
 	/*
	*********************************
	||	END - Methods
	*********************************
	*/

