// ============================================== //

		// EASING FUNCTIONS //

// ============================================== //

jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
	def: 'easeOutQuad',
	swing: function (x, t, b, c, d) {
		//alert(jQuery.easing.default);
		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
	},
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeInOutQuad: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t + b;
		return -c/2 * ((--t)*(t-2) - 1) + b;
	},
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	}
});

// ============================================== //

		// TIMER FUNCTIONS //

// ============================================== //

jQuery.fn.extend({everyTime:function(interval,label,fn,times,belay){return this.each(function(){jQuery.timer.add(this,interval,label,fn,times,belay)})},oneTime:function(interval,label,fn){return this.each(function(){jQuery.timer.add(this,interval,label,fn,1)})},stopTime:function(label,fn){return this.each(function(){jQuery.timer.remove(this,label,fn)})}});jQuery.extend({timer:{guid:1,global:{},regex:/^([0-9]+)\s*(.*s)?$/,powers:{'ms':1,'cs':10,'ds':100,'s':1000,'das':10000,'hs':100000,'ks':1000000},timeParse:function(value){if(value==undefined||value==null)return null;var result=this.regex.exec(jQuery.trim(value.toString()));if(result[2]){var num=parseInt(result[1],10);var mult=this.powers[result[2]]||1;return num*mult}else{return value}},add:function(element,interval,label,fn,times,belay){var counter=0;if(jQuery.isFunction(label)){if(!times)times=fn;fn=label;label=interval}interval=jQuery.timer.timeParse(interval);if(typeof interval!='number'||isNaN(interval)||interval<=0)return;if(times&&times.constructor!=Number){belay=!!times;times=0}times=times||0;belay=belay||false;if(!element.$timers)element.$timers={};if(!element.$timers[label])element.$timers[label]={};fn.$timerID=fn.$timerID||this.guid++;var handler=function(){if(belay&&this.inProgress)return;this.inProgress=true;if((++counter>times&&times!==0)||fn.call(element,counter)===false)jQuery.timer.remove(element,label,fn);this.inProgress=false};handler.$timerID=fn.$timerID;if(!element.$timers[label][fn.$timerID])element.$timers[label][fn.$timerID]=window.setInterval(handler,interval);if(!this.global[label])this.global[label]=[];this.global[label].push(element)},remove:function(element,label,fn){var timers=element.$timers,ret;if(timers){if(!label){for(label in timers)this.remove(element,label,fn)}else if(timers[label]){if(fn){if(fn.$timerID){window.clearInterval(timers[label][fn.$timerID]);delete timers[label][fn.$timerID]}}else{for(var fn in timers[label]){window.clearInterval(timers[label][fn]);delete timers[label][fn]}}for(ret in timers[label])break;if(!ret){ret=null;delete timers[label]}}for(ret in timers)break;if(!ret)element.$timers=null}}}});if(jQuery.browser.msie)jQuery(window).one("unload",function(){var global=jQuery.timer.global;for(var label in global){var els=global[label],i=els.length;while(--i)jQuery.timer.remove(els[i],label)}});


// ============================================== //

		// PAGE SIZE FUNCTIONS //

// ============================================== //

		_getPageSize = function() {var xScroll, yScroll;if (window.innerHeight && window.scrollMaxY) {xScroll = window.innerWidth + window.scrollMaxX;yScroll = window.innerHeight + window.scrollMaxY;} else if (document.body.scrollHeight > document.body.offsetHeight){xScroll = document.body.scrollWidth;yScroll = document.body.scrollHeight;} else {xScroll = document.body.offsetWidth;yScroll = document.body.offsetHeight;};var windowWidth, windowHeight;if (self.innerHeight) {if(document.documentElement.clientWidth){windowWidth = document.documentElement.clientWidth;} else {windowWidth = self.innerWidth;};windowHeight = self.innerHeight;} else if (document.documentElement && document.documentElement.clientHeight) {windowWidth = document.documentElement.clientWidth;windowHeight = document.documentElement.clientHeight;} else if (document.body) {windowWidth = document.body.clientWidth;windowHeight = document.body.clientHeight;};if(yScroll < windowHeight){pageHeight = windowHeight;} else { pageHeight = yScroll;};if(xScroll < windowWidth){	pageWidth = xScroll;		} else {pageWidth = windowWidth;};arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);return arrayPageSize;};

		_getPageScroll = function() {var xScroll, yScroll;if (self.pageYOffset) {yScroll = self.pageYOffset;xScroll = self.pageXOffset;} else if (document.documentElement && document.documentElement.scrollTop) {yScroll = document.documentElement.scrollTop;xScroll = document.documentElement.scrollLeft;} else if (document.body) {yScroll = document.body.scrollTop;xScroll = document.body.scrollLeft;};arrayPageScroll = new Array(xScroll,yScroll);return arrayPageScroll;};





(function($){
	
	// ============================================== //

		// NAVIGATION FUNCTIONS //

	// ============================================== //
	
	
	initAjaxNav = function(loadInFirst,projectPage) {

		// =============================================================================== SETUP
		
		var subNavWidth = $('#subnavi_inner').width();
		var subNavHeight = 100;
		var galleryHeight = null;
		var zDepth = 50;
		
		var newHtml = '<div id="ajax_loading"></div><div id="ajax_img_loading"></div><div id="ajax_error"></div>';
		$('#content').append(newHtml);
		
		// Is there a Map Navigation?
		var mapNav = false;
		var mapOpen = false;
		//
		if ($('#page_locations').length) {
			mapNav=true;
		};
		//
		initFooter = function(){
			var thisTarget = $('ul#footnavi');
			if(thisTarget.find('li').length<4){
				thisTarget.append('<li><\/li>');
			};
		};
		//
		updateFooter = function(thisURL, thisTitle, thisLevel, thisId){
			//alert(thisURL+'  '+thisTitle+'  '+thisLevel+'  '+thisId+'  ');
			var thisTarget = $('ul#footnavi');
			var thisItem = thisTarget.find('li').eq(thisLevel);
			//
			thisItem.find('a').data('thisId',thisId);
			//
			if(thisTitle!=null){
				if(thisItem.find('a').length){
					thisItem.find('a').html(thisTitle).attr('href',thisURL);
				}else{
					thisItem.html('&gt; <a href="'+thisURL+'" title="'+thisTitle+'">'+thisTitle+'</a>');
				};
			};
			//
			if(thisTarget.find('li').eq(thisLevel+1).find('a').length){
				thisTarget.find('li').eq(thisLevel+1).html('');
			};
			setFooterLinks();
		};
		//
		setFooterLinks = function(){
			var thisTarget = $('ul#footnavi');
			thisTarget.find('li').eq(2).find('a').unbind('click').click(function() {
				if ($('#base_gallery').length) {
					closeBaseNav($(this).attr('href'),true);
				}else{
					initSubContent($(this).attr('href'),true);
				};
				//
				if(projectPage){
					var subNavId = parseInt($(this).data('thisId'));
					openProjectSub($('#subnavi_inner li').eq(subNavId).find('a'));
				};
				//
				setUrlHash($(this).attr('href'),false);
				thisTarget.find('li').eq(3).html('');
				//
				return false;
			});
			//
			thisTarget.find('li').eq(3).find('a').unbind('click').click(function() {
				toLoad = $(this).attr('href');
				thisTitle = $(this).attr('title');
				/*if($(this).hasClass('flash_link')){
					initFlashPlayer(toLoad,thisTitle);
				}else{
					if(toLoad.substr(toLoad.length-4,toLoad.length)=='.jpg'){
						setCarouselHtml('<li><img class="slide" alt="" src="'+toLoad+'"/><\/li>');
					}else{
						setUrlHash($(this).attr('href'),true);
						closeBaseNav(toLoad,true);
					};
				};*/
				if($(this).hasClass('flash_link')){
					initFlashPlayer(toLoad,thisTitle);
				}else if($(this).hasClass('mov_link')){
					initMoviePlayer(toLoad,thisTitle);
				}else{
					if(toLoad.substr(toLoad.length-4,toLoad.length)=='.jpg'){
						setCarouselHtml('<li><img class="slide" alt="" src="'+toLoad+'"/><\/li>');
					}else{
						setUrlHash($(this).attr('href'),true);
						closeBaseNav(toLoad,true);
					};
				};
				return false;
			});
		};
		//
		subNavClicked = function(thisTarget){
			if(!thisTarget.hasClass('active')){
				$('#ajax_error').hide();
				thisTarget.parent().parent().find('a').not($(this)).removeClass('active');
				thisTarget.addClass('active')
				setUrlHash(thisTarget.attr('href'),false);
				updateFooter(thisTarget.attr('href'),thisTarget.html(),2,thisTarget.parent().index());
				//.substr(0,$(this).attr('href').length-5);// FOR PAGES WITH.HTML AT THE END !!!!!  				
				//
				if ($('#base_gallery').length) {
					closeBaseNav(thisTarget.attr('href'),true);
				}else{
					initSubContent(thisTarget.attr('href'),true);
				};
				//
				if(projectPage){
					openProjectSub(thisTarget);
				};
			};
		};
		//
		initThis = function(){	
			initFooter();
			setHash(true);
			$('#subnavi_inner').find('a').each(function(i) {
				//
				$(this).click(function() {
					subNavClicked($(this));
					return false;	
				});
			});
			//
			if(projectPage){
				$('#subnavi_inner ul li ul li').find('a').each(function(i) {
					$(this).unbind('click').click(function() {
						$(this).parent().parent().find('a.active').removeClass('active');
						$(this).addClass('active');
						//
						var tempString = $(this).attr('href').split("/");
						var newUrl = tempString[tempString.length-2]+'/'+tempString[tempString.length-1];
						setUrlHash(tempString[tempString.length-1],true);
						updateFooter($(this).attr('href'),$(this).html(),3,null);
						//
						if ($('#base_gallery').length) {
							closeBaseNav(newUrl,true);
						}else{
							initSubContent(newUrl,true);
						};
						//
						return false;					   
					});
				});
			};
			//
			if ($('#page_locations').length){
				$('#location_dots li').each(function(i){
					$(this).find('a').data('myId',i).click(function() {	
						var whichNav = $('#subnavi_inner li').eq($(this).data('myId')).find('a');
						//whichNav.hide();
						subNavClicked(whichNav);
						return false;
					});
				});
			};
			//
			$('#subnavi_inner').delay(300).animate({left: 0 }, 800, "easeOutQuad", function(){
				setHash(false);
			});
		};
		//
		openProjectSub = function(thisTarget){
			$('#subnavi_inner').find('ul.navOpen').slideUp().removeClass('navOpen').find('a.active').removeClass('active');
			thisTarget.parent().children('ul:first').addClass('navOpen').slideDown();
		};
		//
		setHash = function(firstLoad){
			if(window.location.hash) {
				var hash = window.location.hash.substr(1);
				var hashSub = null;
				//+'.html';// FOR PAGES WITH.HTML AT THE END !!!!!
				if(hash.indexOf('&') != -1){
					var tempString = hash.split("&");
					hash = tempString[0];
					hashSub = tempString[1];
					var hashLoad = hash+'/'+hashSub;
				}else{
					var hashLoad = hash;
				};
				//
				if(firstLoad){
					$('#subnavi_inner ul li').each(function(){
						var thisUrl = $(this).find('a:first').attr('href');
						if(thisUrl.indexOf('/') != -1){
							var tempString = thisUrl.split("/");
							thisUrl = tempString[tempString.length-1];
						};
						if (thisUrl==hash){
							$(this).find('a:first').addClass('active');
							updateFooter($(this).find('a:first').attr('href'), $(this).find('a:first').html(), 2, $(this).index());
							if(projectPage){// check sub sub nave
								$(this).find('ul:first').css({'display':'block'}).addClass('navOpen').find('li').each(function(){
									var thisSubUrl = $(this).find('a:first').attr('href');	
									if(thisSubUrl.indexOf('/') != -1){
										var tempSubString = thisSubUrl.split("/");
										thisSubUrl = tempSubString[tempSubString.length-1];
									};
									if (thisSubUrl==hashSub){
										$(this).find('a:first').addClass('active');
										updateFooter($(this).find('a:first').attr('href'), $(this).find('a:first').html(), 3, null);
									};
								});
							};
						};
					});
					if(loadInFirst){// If this is a page where content needs to be loaded in at the beginning
						loadAjaxCarousel(hashLoad);
					}else{
						initCarousel();
					};
				}else{
					loadContent(hashLoad);
				};
				//
			}else{
				if(loadInFirst){// If this is a page where content needs to be loaded in at the beginning
					var thisTarget = $('#subnavi_inner ul li:first a');
					thisTarget.addClass('active');
					var toLoadContent = thisTarget.attr('href');
					updateFooter(thisTarget.attr('href'), thisTarget.html(), 2,0);
					//
					if(firstLoad){
						if($('#image_carousel ul li').length){
							initCarousel();
						}else{
							loadAjaxCarousel(toLoadContent);
						}
					}else{
						//initCarousel();
						loadContent(toLoadContent);
					};
				}else{// Else just fade up carousel
					if(firstLoad){
						initCarousel();
					}
				};
			};
		};
		//
		setUrlHash = function(thisURL,subHash){
			if(subHash){
				var oldURL = document.location.href.split("&");
				var tempString = thisURL.split("/");
				var newURL = tempString[tempString.length-1];
				window.location.replace(oldURL[0]+'&'+newURL);
			}else{
				if(thisURL.indexOf('/') != -1){
					var tempString = thisURL.split("/");
					window.location.hash = tempString[tempString.length-1];
				}else{
					window.location.hash = thisURL;	
				};				
			};
		};
		
		// =============================================================================== LOADER IMAGE
		
		showLoader = function(){
			$('#ajax_load_content').stopTime().oneTime(500,function() {
				$('#ajax_loading').show();
			});	
		};
		
		hideLoader = function(){
			$('#ajax_load_content').stopTime();
			$('#ajax_loading').hide();
		};
		
		showImgLoader = function(){
			$('#image_carousel').stopTime().oneTime(500,function() {
				$('#ajax_img_loading').show();
			});	
		};
		
		hideImgLoader = function(){
			$('#image_carousel').stopTime();
			$('#ajax_img_loading').hide();
		};
		
		// =============================================================================== MAIN SUBNAV LOAD
		
		initSubContent = function(toLoad,clickLoad){
			var thisTarget = $('#sub_content');
			//
			if(mapOpen){
				var mapWidth = $('#map_area').width();
				$('#map_item').animate({left: (mapWidth*-1)}, 600, "easeOutQuad",function(){
					$('#map_area').hide();
					closeContent(toLoad,clickLoad);
				});
				mapOpen = false;
			}else{
				closeContent(toLoad,clickLoad);
			};
			//
		};
		
		closeContent = function(toLoad,clickLoad){
			var thisTarget = $('#sub_content');
			//
			var direction = {left: (subNavWidth*-1)};
			var speed = 600;
			//
			if ($('#base_gallery').length) {
				if(projectPage){
					direction = {top: subNavHeight }; 
					speed = 400;
				};
			}
			//
			if(thisTarget.hasClass('open')){
				thisTarget.removeClass('open').animate(direction, speed, "easeOutQuad", function(){
					loadContent(toLoad,clickLoad);																		  
				});
			}else{
				loadContent(toLoad,clickLoad);
			}
		};
		
		loadContent = function(toLoad,clickLoad){
			showLoader();
			var arrowHtml = '<a href="#" class="back_arrow_link" title="Close Pane">Close Pane</a>';
			$('#ajax_load_content').load(toLoad+' #ajax_content', '', 
				function(responseText, textStatus, XMLHttpRequest) {
					hideLoader();
					if(textStatus == 'error') {
						loadContent(toLoad,clickLoad);
						return false;
						//$('#ajax_error').html('<p>There was an error making the AJAX request</p>').show();
					}else{
						if(!$('#base_gallery').length){
							$('#ajax_sub_content').after(arrowHtml);
							$('#sub_content a.back_arrow_link').click(function(){
								closePane();										   
							});
						}
						//
						if(mapNav){
							initMapNav();
						};
						//
						initMore(toLoad,clickLoad);
					};
				});
		};
		
		initMore = function(toLoad,clickLoad){
			if($('#content_300').length){
				
			}else{
				if(!$('#page_practice').length){
					var containerHeight = $('#ajax_sub_content').height();
					if($('#scroll_content').height()>containerHeight){
						$('#ajax_sub_content').after('<p class="content_more"><a href="#">> More</a></p>');
						setMoreLink($('#content_160 p.content_more a'));
					};
				};
			};
			//
			showNewContent(toLoad,clickLoad);
		};
		
		setMoreLink = function(thisTarget){
			var containerHeight = $('#ajax_sub_content').height();
			thisTarget.unbind('click').html('> More').click(function(){
				var tempTarget = $(this);
				$('#scroll_content').animate({ opacity: 0 }, 300, function(){
					$(this).css({'top':(containerHeight*-1)}).animate({ opacity: 1 }, 300);
					setBackLink(tempTarget);
				});	
				return false;
			});
		};
		
		setBackLink = function(thisTarget){
			thisTarget.unbind('click').html('< Back').click(function(){
				var tempTarget = $(this);
				$('#scroll_content').animate({ opacity: 0 }, 300, function(){
					$(this).css({'top':0}).animate({ opacity: 1 }, 300);
					setMoreLink(tempTarget);
				});	
				return false;
			});
		};
		
		showNewContent = function(toLoad,clickLoad){
			//
			var direction = {left: 0 };
			var speed = 800;
			
			if ($('#base_gallery').length) {
				if(projectPage){
					direction = {top: 0 }; 
					speed = 600;
					initBaseNav();
				};
			};
			//
			$('#sub_content').addClass('open').animate(direction, speed, "easeOutQuad",function(){																				 
				if(clickLoad){
					loadAjaxCarousel(toLoad);
				};
				//
				if(!projectPage){
					if ($('#base_gallery').length) {
						initBaseNav();
					};	
				};
			});
		};
		
		closePane = function(){
			if(mapOpen){
				$('#map_item').animate({left: -480}, 600, "easeOutQuad",function(){
					$('#map_area').hide();
					closePaneAnim();
				});
				mapOpen = false;
			}else{
				closePaneAnim();
			};
		};
		
		closePaneAnim = function(){
			$('#sub_content').removeClass('open').animate({left: (subNavWidth*-1) }, 800, "easeOutQuad",function(){
				$('#subnavi_inner a.active').removeClass('active');
				$('#ajax_content').remove();
			});
		};
		
		// =============================================================================== MAP NAV
		
		initMapNav = function(){
        	if($('#sub_content a.maplink').length){
				$('#sub_content a.maplink').click(function(){
					$('#map_area').show();
					$('#map_item').animate({left: 0}, 800, "easeOutQuad");
					mapOpen = true;
					return false;    	
				});
			};
		};
		
		// =============================================================================== BASE NAV
		
		clickBaseNavClose = function(thisTarget){
			thisTarget.unbind('click').click(function() {
				$('#sub_content').animate({top: galleryHeight-18}, 400, "easeOutQuad");
				//
				$('#base_gallery_inner').animate({top: galleryHeight-18}, 400, "easeOutQuad", function(){
					$('#scroll_content').hide();
					$('#base_gallery_inner ul:first').hide();
					thisTarget.addClass('open');
					clickBaseNavOpen(thisTarget);
				});
				//
				return false;
			});
		};
		
		clickBaseNavOpen = function(thisTarget){
			thisTarget.unbind('click').click(function() {
				$('#scroll_content').show();
				$('#base_gallery_inner ul:first').show();
				//
				$('#sub_content').animate({top: 0}, 400, "easeOutQuad");
				//
				$('#base_gallery_inner').animate({top: 0}, 400, "easeOutQuad", function(){
					thisTarget.removeClass('open');
					clickBaseNavClose(thisTarget);
				});
				//
				return false;
			});
			
		};
		
		initBaseNav = function(){
			
			galleryHeight = $('#base_gallery_inner').height();
			var thisTarget = $('#base_gallery_inner');
			var liWidth = parseInt(thisTarget.find('li:first').css('width').replace("px", "")) + parseInt(thisTarget.find('li:first').css('margin-right').replace("px", ""));
			var liTotal = thisTarget.find('li').length;
			var liTotalWidth = liWidth*liTotal;
			thisTarget.find('ul').css({'width' : liTotalWidth});
			thisTarget.scrollLeft(0);
			//
			if (projectPage){
				var arrowHtml = '<a href="#" class="down_arrow_link" title="Close Pane">Close Pane</a>';
				thisTarget.append(arrowHtml);
				//
				clickBaseNavClose(thisTarget.find('a.down_arrow_link'));
			};
			//
			thisTarget.find('ul li:first a').addClass('active');
			thisTarget.find('ul li a').click(function() {
				//
				$('#ajax_error').hide();
				$(this).parent().parent().find('li a.active').removeClass('active');
				$(this).addClass('active');
				var toLoad = $(this).attr('href')+' #ajax_sub_content';
				//
				if (!projectPage){
					setUrlHash($(this).attr('href'),true);
					updateFooter($(this).attr('href'),$(this).attr('title'),2,null);
					$('#ajax_sub_content_holder').animate({ opacity: 0 }, 300, function(){
						loadBaseNav(toLoad);
						loadAjaxCarousel(toLoad);
					});
				}else{//If I'm in a project page
					toLoad = $(this).attr('href');
					thisTitle = $(this).attr('title');
					/*if($(this).hasClass('flash_link')){
						initFlashPlayer(toLoad,thisTitle);
					}else{
						if(toLoad.substr(toLoad.length-4,toLoad.length)=='.jpg'){
							setCarouselHtml('<li><img class="slide" alt="" src="'+toLoad+'"/><\/li>');
						}else{
							setUrlHash($(this).attr('href'),true);
							closeBaseNav(toLoad,true);
						};
					};*/
					if($(this).hasClass('flash_link')){
						initFlashPlayer(toLoad,thisTitle);
					}else if($(this).hasClass('mov_link')){
						initMoviePlayer(toLoad,thisTitle);
					}else{
						if(toLoad.substr(toLoad.length-4,toLoad.length)=='.jpg'){
							setCarouselHtml('<li><img class="slide" alt="" src="'+toLoad+'"/><\/li>');
						}else{
							setUrlHash($(this).attr('href'),true);
							closeBaseNav(toLoad,true);
						};
					};
				};
				return false;	
			});
			//
			thisTarget.animate({top: 0 }, 600, "easeOutQuad",function(){
				setBaseNavScroll();												  
			});
		};
		//
		loadBaseNav = function(toLoad){
			showLoader();
			var thisTarget = $('#ajax_sub_content_holder');
			thisTarget.load(toLoad, '', 
				function(responseText, textStatus, XMLHttpRequest) {
					hideLoader();
					if(textStatus == 'error') {
						loadBaseNav(toLoad);
						return false;
						//$('#ajax_error').html('<p>There was an error making the AJAX request</p>').show();
					}else{
						thisTarget.animate({ opacity: 1 }, 400);
					}
				}
			);
		};
		//
		closeBaseNav = function(toLoad,clickLoad){
			var thisTarget = $('#base_gallery_inner');
			thisTarget.unbind('mousemove');
			if(projectPage){
				initSubContent(toLoad,clickLoad);
			};
			thisTarget.animate({top: galleryHeight }, 400, "easeOutQuad", function(){
				if(!projectPage){
					initSubContent(toLoad,clickLoad);
				};
			});
		};
		//
		setBaseNavScroll = function(){
			var thisTarget = $('#base_gallery_inner');
			//
			var liTotalWidth = thisTarget.find('ul').width();
			var scrollWidth = thisTarget.width();
			//
			if (liTotalWidth>scrollWidth){
				var offset = thisTarget.offset();
				var mousepos = 1;
				//
				thisTarget.mousemove(function(e) {
					var x = e.pageX - offset.left;
					var diff = (x - mousepos);
					if (diff > 10 || diff < -10) {
						mousepos = x;	
						//
						scrollPos = (((scrollWidth-100) - liTotalWidth) * (x/(scrollWidth-100)) *-1) -100;
						$(this).stop().animate({scrollLeft: scrollPos }, 200); // easing
						//$(this).scrollLeft(scrollPos); // no easing
					}
				});
			};
		};
		
		// ============================================== //

			// FLASH PLAYER //
	
		// ============================================== //
	
		positionFlash = function(){
			// Get page sizes
			var arrPageSizes = _getPageSize();
			// Style overlay and show it
			$('#jquery-overlay-outer').css({
				width:		arrPageSizes[0],
				height:		arrPageSizes[1]
			});
			$('#jquery-overlay').css({
				width:		arrPageSizes[0],
				height:		arrPageSizes[1]-105
			});
			//
			var thisOffset = $('#image_carousel').offset();
			//
			$('#jquery-lightbox').css({
				top:	20,
				left:	(thisOffset.left)
			});
		};
		//
		
		initFlashPlayer = function(swfPath, thisTitle){
			
			//var str = swfPath.split('.com');
			//newSwfPath = "../.."+str[1];
			
			var str = swfPath.split('/');
	  		//str[1]);
			var flashURL = 'http://hoarelealighting.com/projects/flash_player?'+str[str.length-1];
			//
			window.open(flashURL,'CGIWindow','width=1024,height=796');
		};
		
		
		
		// ============================================== //

			// MOVIE PLAYER //
	
		// ============================================== //
		
		initMoviePlayer = function(movPath, thisTitle){
			//
			$('body').append('<div id="jquery-overlay-outer"><div id="jquery-overlay"><\/div><\/div><div id="jquery-lightbox"><div id="lightbox-content"><div id="lightbox-flash"><\/div><\/div><a href=# title="Close window"><\/a><\/div>');
			
			// Get page sizes
			
			var arrPageSizes = _getPageSize();
			//
			$('#jquery-overlay').css({
				opacity:			0,
				width:				arrPageSizes[0],
				height:				arrPageSizes[1]-105
			}).animate({opacity: 1}, 250);
			//
			var thisOffset = $('#image_carousel').offset();
			//
			$('#jquery-lightbox').css({
				top:	5,
				left:	(thisOffset.left)
			});
			//
			$('#jquery-overlay,#jquery-lightbox,#jquery-lightbox a').click(function() {
				closeMoviePlayer();
				return false;	
			});
			//
			$('#lightbox-content').click(function() {
				return false;						
			});
			//
			$(window).resize(function() {
				positionFlash();
			});
			//
			loadMovPlayer('lightbox-flash',movPath);
		};
		
		loadMovPlayer = function(playerId,movPath){
				/*jwplayer("lightbox-flash").setup({ 
					flashplayer: "http://hoareleacgi.com/includes/flash/jwplayer.swf", 
					file: "http://hoareleacgi.com/images/movie_files/test_video.mp4", 
					height: 270, 
					width: 480 
				});*/
				
				var str = movPath.split('www.');
				var newMovPath = "http://"+str[1];
				
				jwplayer(playerId).setup({ 
					flashplayer: "http://hoareleacgi.com/includes/flash/jwplayer.swf", 
					file: newMovPath,
					bufferlength: 10,
					skin: "http://www.hoareleacgi.com/includes/flash/modieus.zip",
					controlbar: 'over',
					stretching:'fill',
					autoplay: 'true',
					height: 540, 
					width: 960 
				});
			
			 $('#jquery-lightbox').show();
			 
        };
		
		closeMoviePlayer = function() {
			$('#jquery-lightbox').remove();
			$('#jquery-overlay').fadeOut(function() { $('#jquery-overlay').remove(); });
			// Show some elements to avoid conflict with overlay in IE. These elements appear above the overlay.
			$('embed, object, select').css({ 'visibility' : 'visible' });
		};
		
		
		
		
		// ============================================== //

			// IMAGE CAROUSEL //
	
		// ============================================== //

		loadAjaxCarousel = function(toLoad){
			var thisTarget = $('#image_carousel ul');
			//alert(toLoad);
			processGet = function(data){
				var newHtml = jQuery.trim($('#image_carousel ul',data).html());// trim white space
				setCarouselHtml(newHtml);
			};
			$.get(toLoad, processGet);
		};
		//
		setCarouselHtml = function(newHtml){
			var thisTarget = $('#image_carousel ul');
			//
			var liVar = newHtml.substring(0,4);
			if(liVar =='<li>' || liVar =='<LI>'){// If carousel images exist
				thisTarget.find('li').addClass('removeMe');
				var oldHtml = thisTarget.html();
				thisTarget.html(oldHtml+newHtml);
				initCarousel();
			};
		};
		//
		initCarousel = function(){
			zDepth++;
			var thisTarget = $('#image_carousel ul');
			var captionTarget = $('#caption_carousel ul');
			thisTarget.stopTime();
			//
			thisTarget.find('li:not(.removeMe)').hide().animate({ opacity: 0 }, 0.001, function(){
				$(this).css({ 'position' : 'absolute', 'top' : 0, 'left' : 0 });																		
			});
			if(captionTarget.length){
				captionTarget.find('li:not(.removeMe)').hide().animate({ opacity: 0 }, 0.001, function(){
					$(this).css({ 'position' : 'absolute', 'top' : 0, 'left' : 0 });																		
				});
				//
				 $('#image_carousel').after('<div id="caption_bg"></div>');
			};
			//
			showImgLoader();
			var img = new Image();
			$(img).load(function () {
				hideImgLoader();
				thisTarget.oneTime(100, function(){
					thisTarget.show().find('li:not(.removeMe)').eq(0).css({'z-index':zDepth}).show().animate({ opacity: 1 },800,function(){
						$(this).css({'filter':'none'});
						var thisStrap = $(this).find('p');
						if(thisStrap.length){
							$(this).find('div').animate({ opacity: 0 }, 0.001, function(){
								$(this).delay(800).show().animate({ opacity: .5 },800);															
							});
							thisStrap.animate({ opacity: 0 }, 0.001, function(){
								$(this).delay(800).show().animate({ opacity: 1 },800);
							});
						};
						//
						thisTarget.find('li.removeMe').remove();
						if(thisTarget.find('li').length>1){
							setCarousel();
						}
					});				  
				});
			}).attr('src', thisTarget.find('li:not(.removeMe)').eq(0).find('img:first').attr('src'));
		};
		//
		setCarousel = function(){
			var thisTarget = $('#image_carousel ul');
			var captionTarget = $('#caption_carousel ul');
			var imgArray = [];
			var imgArrayLoaded = [];
			var arrayItem = 0;
			var arrayLoadItem = 1;
			var arrayLength = 0;
			var speed = 4000; // Time between slides
			if($('#page_home').length){
				speed = 6000;
			};
			var fadeSpeed = 800; // Speed slide fades up
			var prevItem = null;
			var prevCaption = null;
			//	
			thisTarget.find('li').each(function(i) {
				imgArray.push($(this).find('img').attr('src'));
				if(i!=0){
					imgArrayLoaded.push(false);
					$(this).find('img').attr({'src': ''});
				}else{
					imgArrayLoaded.push(true);
				}
			});
			//
			arrayLength = imgArray.length;
			//
			loadImage = function(){// load each main image in sequence
				//
				var nextImage = imgArray[arrayLoadItem];
				var img = new Image();
				//
				$(img).load(function () {
					imgArrayLoaded[arrayLoadItem] = true;
					thisTarget.find('li').eq(arrayLoadItem).find('img').attr({'src': imgArray[arrayLoadItem]});
					//
					if(arrayLoadItem==1){
						advanceImage();
					};
					if(arrayLoadItem<arrayLength){
						arrayLoadItem++;
						loadImage();
					};
				}).attr('src', nextImage);
			};
			//
			advanceImage = function(){
				prevItem = thisTarget.find('li').eq(arrayItem);
				if(captionTarget.length){
					prevCaption = captionTarget.find('li').eq(arrayItem);
				};
				//
				if(arrayItem<(arrayLength-1)){
					arrayItem++
				}else{
					arrayItem = 0
				}
				startImgTimer();
			};
			//
			startImgTimer = function(){
				thisTarget.oneTime(speed, function() {
					if(imgArrayLoaded[arrayItem]){
						revealImage();	
					}else{
						startImgTimer();
					}
				});
			};
			//
			revealImage = function(){
				zDepth++;
				thisTarget.find('li').eq(arrayItem).css({ 'z-index' : zDepth}).show().animate({ opacity: 1 }, fadeSpeed, function(){
					prevItem.hide().animate({ opacity: 0 }, 0.001);
					$(this).css({'filter':'none'});
					var thisStrap = $(this).find('p');
					if(thisStrap.length){
						prevItem.find('div').hide().animate({ opacity: 0 }, 0.001);
						prevItem.find('p').hide().animate({ opacity: 0 }, 0.001);
						$(this).find('div').animate({ opacity: 0 }, 0.001, function(){
							$(this).delay(800).show().animate({ opacity: .5 },800);															
						});
						thisStrap.animate({ opacity: 0 }, 0.001, function(){
							$(this).delay(800).show().animate({ opacity: 1 },800);
						});
					};
					advanceImage();
				});
			};
			//
			loadImage();
		};
		//
		initThis();
	};
	
	initFlashEmbed = function(){
		var str = window.location.href.split('?');
		//
		//newSwfPath = "../.."+str[1];
		var swfPath = '../images/flash_files/'+str[1];
		//
		var flashvars = {};
		//
		var params = {
			wmode:"transparent",
			play:"true",
			loop:"true",
			scale:"showall",
			menu: "false",
			devicefont: "false",
			allowScriptAccess: "sameDomain"
		};
		//
		var attributes = {};
		//
		swfobject.embedSWF(swfPath, "flash_embed", "1024", "768", "9.0.0",'', flashvars, params, attributes);
	};
	
	
})(jQuery);


$(document).ready(function(){
	var loadInFirst = true;
	var projectPage = false;

	
	if ($('#page_locations').length) {
		loadInFirst = false;
	}
	if ($('#page_projects').length) {
		projectPage = true;
		loadInFirst = false;
	}
	//
	if ($('#subnavi').length) {
		if ($('#page_people').length) {
		}else{
			initAjaxNav(loadInFirst,projectPage);
		};
	};
	//
	if ($('#page_home').length) {
		initAjaxNav(true,false);
	};
	//
	if ($('#page_flash_player').length) {
		initFlashEmbed()
	};
});

