
$(function(){  







	//////////////////////////////////////////////////////////////////
	// HOME IMAGE PRELOADER
	//////////////////////////////////////////////////////////////////

	// Helper function, used below.
	// Usage: ['img1.jpg','img2.jpg'].remove('img1.jpg');
	Array.prototype.remove = function(element) {
	  for (var i = 0; i < this.length; i++) {
	    if (this[i] == element) { this.splice(i,1); }
	  }
	};
	
	// Usage: $(['img1.jpg','img2.jpg']).preloadImages(function(){ ... });
	// Callback function gets called after all images are preloaded
	$.fn.preloadImages = function(callback) {
	  checklist = this.toArray();
	  this.each(function() {
	  	//console.log(this);
	    $('<img>').attr({ src: this }).load(function() {
	      checklist.remove($(this).attr('src'));
	      if (checklist.length == 0) { callback(); }
	    });
	  });
	};






	$('.shareHeader').click(function() {
		return false;
	});


	/*

	$('#accreds').css({ opacity: 0.4 });
	$('#accreds').hover(function() {
		$(this).css({ opacity: 1 });
	},function() {
		$(this).css({ opacity: 0.4 });
	});
	*/
	
	

	//////////////////////////////////////////////////////////////////
	// MOBILE SNIFFER
	//////////////////////////////////////////////////////////////////
	
	var isIOS = false;
	if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
		isIOS = true;
	}
	
	
	
	
	
	

	//////////////////////////////////////////////////////////////////
	// BACKGROUND IMAGE SWITCHER
	//////////////////////////////////////////////////////////////////
	$('#introCopy').fadeIn();

	//HIDE EVEYTHING INITIALLY
	$('#home #backgroundImage').css({ opacity: 0 });
	$('#home .newFlag').animate({top: "-5", opacity: 0},0);

	$('#home #backgroundImageTop').css({ opacity: 0 });
	$('#backgroundImagesArray img').css({ display: 'none' });
	$('#backgroundImagesTop').css({ opacity: 0.8 });

	//CHECK TO SEE WHAT THE NAV ITEMS ARE (HOME OR NOT)
	if($('#introCopy ul a').length != 0) {
		//IS HOME PAGE
		$listItems = $('#introCopy li');
		//$listItems.append('<br/>');
		$listItems = $('#introCopy li a:not(h2 a)').parent();
		$navItems = $listItems;
		$backgroundImage = $('#backgroundImage');
		$backgroundImageTop = $('#backgroundImageTop');
		var origSrc = $backgroundImage.attr('src');
	} else if($('#peopleintroCopy').length != 0) {
		//IS PEOPLE PAGE
		$listItems = $('#invis');
		$navItems = $('#peopleintroCopy a');
		$backgroundImage = $('#personImage');
		$backgroundImageTop = $('#personImage');
		$navItems.click(function(){
			return false;
		});
		var origSrc = "";
	} else {
		//IS NORMAL PAGE
		$listItems = $('#invis');
		$navItems = $('#introCopy a');
		$backgroundImage = $('#backgroundImage');
		$backgroundImageTop = $('#backgroundImageTop');
		var origSrc = $backgroundImage.attr('src');
	}
	$introCopy = $('#introCopy');

	//SET INITIAL DATA VALUES FOR NAV ITEMS
	$navItems.css({ opacity: 0.2 });
	$navItems.each(function(index) {
	    var bgImg = $('#backgroundImagesArray img').eq(index).attr('src');
		$(this).data('bgImg', bgImg);
		$(this).data('index', index);
		$(this).data('ready', false);
	});
	$homeCopy = $('#homeCopy');
	
	//DO THE SWITCHEROO
	var imgSrc;
	$navItems.hover(
		function () {
			if(($(this).data('ready') == true && $(this).data('bgImg')) || ($(this).data('ready') == true && $homeCopy.length != 0)) {
				$navItems.removeClass('selected');
				$(this).addClass('selected');
				if($homeCopy.length == 0) {
					imgSrc = $(this).data('bgImg');
					$backgroundImage.attr('src',imgSrc).css({ opacity: 1 }).parent().addClass('active');
					$backgroundImageTop.attr('src',imgSrc).css({ opacity: 1 }).parent().addClass('active');
				}
				$navItems.addClass('notSelected');
				$(this).removeClass('notSelected');
				$introCopy.addClass('active');
				/*
				if($homeCopy.length != 0 && $('body').hasClass('mobile') != true) {
					$homeCopy.css({ opacity: 0 });
				}
				*/
				if(isIOS) {
					window.location = $(this).attr("href");
				}
				//$('.introCopy li.ready').not(this).fadeTo(0, 0.5);
			}
		}, 
		function () {
			if(($(this).data('ready') == true && $(this).data('bgImg')) || ($(this).data('ready') == true && $homeCopy.length != 0)) {
				if(origSrc) {
					$backgroundImage.attr('src',origSrc).parent().removeClass('active');
					$backgroundImageTop.attr('src',origSrc).parent().removeClass('active');
				}
				$('#home #backgroundImage').css({ opacity: 0 });
				$('#home #backgroundImageTop').css({ opacity: 0 });
				$navItems.removeClass('notSelected');
				$introCopy.removeClass('active');
				
				/*
				if($homeCopy.length != 0) {
					$homeCopy.css({ opacity: 1 });
				}
				*/
			}
		}
	);
	
	
	
	IE7 = (navigator.appVersion.indexOf("MSIE 7.")==-1) ? false : true;
	IE8 = (navigator.appVersion.indexOf("MSIE 8.")==-1) ? false : true;
	
	if(!IE7 && !IE8) {

		//////////////////////////////////////////////////////////////////
		// MOVIE SHOW HIDE
		//////////////////////////////////////////////////////////////////
		
		$("#introCopy ul li:eq(2) a").fancybox({
			'href'				:	'#homeVideo',
			'overlayOpacity'	:	0.85,
			'overlayColor'		:	'#3A3F52',
			'autoDimensions'	:	false,
			'width'				:	'100%',
			'height'			:	'100%',
			'hideOnOverlayClick':	true,
			'autoScale'			:	true,
			'padding'			: 	0,
			'onStart'			: 	function() {
			
				wHeight = $(window).height() - 80;
				wWidth = $(window).width() - 80;
			    $("#homeVideo").html('<iframe title="YouTube video player" src="http://www.youtube.com/embed/jLLmC4wkt28?autoplay=1&autohide=1&color2=c9e529&rel=0" width="'+ wWidth +'" height="'+ wHeight +'" frameborder="0" style="width: 100%; height: '+ wHeight +'px; background-color: #000;" allowfullscreen></iframe>');
			    //$("#homeVideo iframe").attr({'height':wHeight, 'width': wWidth});
			}
		});
		
		if(window.location.hash == "#play") { 
	       $("#introCopy ul li:eq(1) a").click();
	    }
		
		$("#playMovie").fancybox({
			'href'				:	'#homeVideo',
			'overlayOpacity'	:	0.85,
			'overlayColor'		:	'#3A3F52',
			'autoDimensions'	:	false,
			'width'				:	'100%',
			'height'			:	'100%',
			'hideOnOverlayClick':	true,
			'autoScale'			:	true,
			'padding'			: 	0,
			'onStart'			: 	function() {
			
				wHeight = $(window).height() - 80;
			    $("#homeVideo").html('<iframe title="YouTube video player" src="http://www.youtube.com/embed/jLLmC4wkt28" width="900" height="'+ wHeight +'" frameborder="0" style="width: 100%; height: '+ wHeight +'px; background-color: #000;" allowfullscreen></iframe>');
			}
		});
		 
		
		$('#mainContent a[href$="jpg"], #mainContent a[href$="jpeg"], a[href$="png"], a[href$="gif"]').fancybox({
			'overlayOpacity'	:	0.85,
			'overlayColor'		:	'#3A3F52',
			'autoDimensions'	:	false,
			'width'				:	'100%',
			'height'			:	'100%',
			'hideOnOverlayClick':	true,
			'autoScale'			:	true,
			'padding'			: 	0
		});

	}

	

	//////////////////////////////////////////////////////////////////
	// CLIENT GRID BUSINESS
	//////////////////////////////////////////////////////////////////
	
	$('#mainContent.filterList a.clientItem .clientTitle').fadeOut(0);

	$('#mainContent.filterList').isotope({ 
		itemSelector : 'a.clientItem'
	});
	$('#mainContent.filterList a.clientItem').each(function() {
		hrefVal = $(this).attr("href");
		$(this).data("hrefVal",hrefVal);
	});
	$('#introCopy.filter a').click(function(){
		var selector = $(this).attr("title");
		
		$('#mainContent.filterList a.clientItem').each(function() {
			hrefVal = $(this).data("hrefVal") + "?cat=" + selector;
			$(this).attr("href", hrefVal);
		});
		if(selector != "*") {
			selector = '.' + selector;
		}
		//alert(selector);
		$('#mainContent.filterList').isotope({ 
			itemSelector : 'a.clientItem',
			filter: selector
		});
		return false;
	});
	
	
	$('#introCopy.filter a').hover(function(){
		var selector = $(this).attr("title");
		//alert(selector);
		$('#mainContent.filterList a.clientItem:not(.'+selector+')').fadeTo(50, 0.3);
	},function(){
		var selector = $(this).attr("title");
		$('#mainContent.filterList a.clientItem:not(.'+selector+')').fadeTo(50, 1);
	});
	
	

	$('#viewSelect a#viewGrid').click(function(){
		$('#mainContent.filterList a.clientItem .clientTitle').fadeOut(200);
		
		$('#mainContent.filterList a.clientItem').css({
			width: 100,
			height: 100
		});
		
		
		$('#mainContent.filterList').isotope({ 
			layoutMode : 'cellsByRow',
			cellsByRow : {
				columnWidth : 110,
				rowHeight : 110
			}
		}).removeClass('listView');
		  //	$('#mainContent.filterList').isotope( 'reLayout' );
		
		
	  	return false;
	});
	$('#viewSelect a#viewList').click(function(){
	  	$('#mainContent.filterList a.clientItem').css({
			height: 30,
			width: 540
		});
		$('#mainContent.filterList a.clientItem .clientTitle').fadeIn(200);

		$('#mainContent.filterList').isotope({ 
			itemSelector : 'a.clientItem',
	  		layoutMode : 'straightDown'
	  	}).addClass('listView');

	  	return false;
	});



	
	
	//////////////////////////////////////////////////////////////////
	// HIDE LOGO WHEN CONTENT IS SCROLLED UP
	//////////////////////////////////////////////////////////////////
	
	
	$(window).scroll(function () { 
		if($(this).scrollTop() > 30) {
			$('.scroll h1').fadeOut('fast');
		} else {
			$('.scroll h1').fadeIn('fast');
		}
	});
	
	
	


	
	
	//////////////////////////////////////////////////////////////////
	// DROPDOWN FUNCTIONS
	//////////////////////////////////////////////////////////////////
	
	
	$('.navDropDownPanel').css({display: 'block'}).slideUp(0);
	$('.navDropDown li').hover(
		function() {
			$(this).find('.navDropDownPanel').slideDown(200);	
		},function() {
			$('.navDropDownPanel').stop(true, true); // ADDED BY DAVE
			$(this).find('.navDropDownPanel').slideUp(200);	
		}
	);
	
	// ANIMATE LAST DD DROPING DOWN
	/*
	$('.navDropDown').last().animate({
		opacity: 0,
		marginTop: '-=20'
	},0).delay(1200).animate({
		opacity: 1,
		marginTop: '+=20'
	},400);
	*/
	

	
	
	//////////////////////////////////////////////////////////////////
	// SCALE BACKGROUND IMAGES
	//////////////////////////////////////////////////////////////////
	
	var resizeBackgrounds = function() {
	
		//if($('#container:not(.contactMap) #backgroundImages').length > 0)
		var bg = $('#container #backgroundImages');
		var bg2 = $('#container #backgroundImagesTop');
		
		//Gather browser and current image size
		var imagewidth = bg.width();
		var imageheight = bg.height();
		var imagewidth = 1280;
		var imageheight = 800;
		var browserwidth = $(window).width();
		var browserheight = $(window).height();
		var offset;
		
		$('#caseStudyContainer .caseStudyPage').css({'width': browserwidth + 10});
		$('#caseStudyContainer .caseStudyPage.hasVideo').css({'height': browserheight});



		//Define image ratio
		var ratio = imageheight/imagewidth;
		//ratio = 0.75;
		//alert(ratio);
		
		
		if (browserwidth > 1140) {
			$('body').addClass('wide');
		} else {
			$('body').removeClass('wide');
		}
		if (browserwidth < 960 && browserwidth >= 640 ) {
			$('body').addClass('narrow');
		} else {
			$('body').removeClass('narrow');
		}
		if (browserwidth < 640) {
			$('body').addClass('mobile');
		} else {
			$('body').removeClass('mobile');
		}
		
		var csImgFullscreen = $('.caseStudyPage img.fullscreen');

		//Resize image to proper ratio 
		if ((browserheight/browserwidth) > ratio){
		    bg.height(browserheight);
		    bg.width(browserheight / ratio);
		    bg2.width(browserheight / ratio);
		    bg.children().height(browserheight);
		    bg.children().width(browserheight / ratio);
		    bg2.children().height(browserheight);
		    bg2.children().width(browserheight / ratio);
		    
		    //csImgFullscreen.height(browserheight);
		    //csImgFullscreen.width(browserheight / ratio);
		} else {
		    bg.width(browserwidth);
		    bg2.width(browserwidth);
		    bg.height(browserwidth * ratio);
		    bg.children().width(browserwidth);
		    bg.children().height(browserwidth * ratio);
		    bg2.children().width(browserwidth);
		    bg2.children().height(browserwidth * ratio);
		    
		    csImgFullscreen.width(browserwidth + 10);
		    csImgFullscreen.height(browserwidth * ratio);
		}
	}
	resizeBackgrounds();		
	
	


	//////////////////////////////////////////////////////////////////
	// CASE STUDY PAGES
	//////////////////////////////////////////////////////////////////
	
	if($('#caseStudyContainer').length != 0) {
		//$('.page-1 #introCopy').css('top', $('.page-1 h2').offset().top + $('.page-1 h2').height() + 20);
		
		$('#caseStudyContainer img, #caseStudyContainer p').delay(900).fadeIn(400);
		
		var scrolledIntoViewIndex = 0;
		function isScrolledIntoView(elem,xpos) {
			//console.log(xpos);
		    //var docViewLeft = $(window).scrollLeft();
			//console.log($(elem).attr('id'));
		    var elemLeft = $(elem).position().left;
		    var elemWidth = $(elem).width();
			if(xpos > elemLeft && xpos < (elemLeft + (elemWidth))) {
				scrolledIntoViewIndex = $(elem).index();
			}
			//return ((elemLeft < docViewLeft + 400) && (elemLeft > docViewLeft - 400));
		}
		
		var closeToEdge = true;
		var closeToLeftEdge = true;
		var closeToRightEdge = true;
		function isCloseToEdge(elem,xpos) {
		    var elemLeft = $(elem).position().left;
		    var elemWidth = $(elem).width();
			//console.log('elemLeft + (elemWidth/5): ' + elemLeft + (elemWidth/5));
			if(xpos > (elemLeft + elemWidth - 30) || xpos < (elemLeft + 30)) {
				closeToEdge = true;
			} else {
				closeToEdge = false;
			}
			if(xpos < (elemLeft + (elemWidth/5))) {
				closeToLeftEdge = true;
			} else {
				closeToLeftEdge = false;
			}
			if(xpos > (elemLeft + elemWidth - (elemWidth/5))) {
				closeToRightEdge = true;
			} else {
				closeToRightEdge = false;
			}
		
			
		}
		
		
		var pagesWidth = 0;
		var currentPage = 0;
		var slidePos = 0;
		var totalPages = 0;
	
	
		
		$clicker = $('.clicker')
		$clicker.mousemove(function(e) {
			wHeight = $(window).height();
			wWidth = $(window).width();
			mouseX = e.pageX;
			mouseY = e.pageY;
			
			if(mouseY < wHeight-100) {
				yPos = mouseY;
			} else {
				yPos = wHeight-100
			}
			
			if (mouseX  < 300) {
				$(this).css({
					'cursor' : 'pointer'
				});
				$('#arrowLeft').css({
					'backgroundPosition' : '-70px left'
				});	
				$('#arrowRight').css({
					'backgroundPosition' : 'top left'
				});	
			
			} else {
				if(mouseX > wWidth - 300) {
					$(this).css({
						'cursor' : 'pointer'
					});
					$('#arrowLeft').css({
						'backgroundPosition' : 'top left'
					});	
					$('#arrowRight').css({
						'backgroundPosition' : '-70px left'
					});	
				} else {
					$(this).css({
						'cursor' : 'auto'
					});
					$('#arrowLeft').css({
						'backgroundPosition' : 'top left'
					});	
					$('#arrowRight').css({
						'backgroundPosition' : 'top left'
					});	
				}
			}
		}).mouseleave(function(){
			$('#arrowLeft').css({
				'backgroundPosition' : 'top left'
			});	
			$('#arrowRight').css({
				'backgroundPosition' : 'top left'
			});	
		}).click(function(e){
	
				if (e.pageX  > 500) {
					currentPage ++;
				} else {
					currentPage --;
				}
				if(currentPage < 0) {
					currentPage = 1;
				}
				if(currentPage > totalPages-1) {
					currentPage = totalPages-1;
				}
				if(currentPage < 1) {
					$('#arrowLeft').css({
						'display' : 'none'
					});	
				} else {
					$('#arrowLeft').css({
						'display' : 'block'
					});
				}
				if(currentPage > totalPages-2) {
					$('#arrowRight').css({
						'display' : 'none'
					});	
				} else {
					$('#arrowRight').css({
						'display' : 'block'
					});
				}
				
				$whichPage = $('#caseStudyContainer .caseStudyPage').eq(currentPage);
				if($whichPage.length == 0) {
					currentPage = 0;
					$whichPage = $('#caseStudyContainer .caseStudyPage').eq(currentPage);
				}
				slidePos = $whichPage.position().left;
	
				siteScrollPaneAPI.scrollTo(slidePos + 5, 0, true)
				
				return false;
				
		   	});
		
		$('#caseStudyContainer .caseStudyPage').each(function() {
			pagesWidth += ($(window).width()+100);
			totalPages ++;
			//console.log("pagesWidth: " + pagesWidth);
		});
		
		$('#caseStudyContainer').disableTextSelect();
		
		/*
			var mouseThrow = 0
			var mouseDistanceOld = 0;
			var mouseVelocity = 0;
			var mouseDistance = 0;
		$('#caseStudyContainer').mousedown(function(e) {
			mouseThrow = 0
			var mouseInitPos = e.pageX;
			var pageInitPos = siteScrollPaneAPI.getContentPositionX();
			mouseDistanceOld = 0;
			mouseVelocity = 0;
			mouseDistance = 0;
			
			$(".caseStudy .jspPane").bind('mousemove', function(e) {
			
				var mouseDistance = mouseInitPos - e.pageX;
				mouseVelocity = 5 * (mouseDistance - mouseDistanceOld);
				if(mouseVelocity < 90 && mouseVelocity > -90) {
					mouseVelocity = 0;
				}
				//console.log('mm')
				//mouseVelocity = (0 - mouseVelocity)/5;
				
				//$(".shareHeader").text("velocity: " + mouseVelocity);
				mouseDistanceOld = mouseDistance;
				siteScrollPaneAPI.scrollTo(pageInitPos + mouseDistance, 0, false);
				
				//mouseThrow =  (pageInitPos + mouseDistance) + (mouseVelocity/5);
				mouseThrow =  (mouseVelocity*2);
				
				
			});
		});
	
		
		$('#caseStudyContainer').mouseup(function(e) {
		
	
			$(".caseStudy .jspPane").unbind('mousemove');
			//console.log('stopped');
	
						if(scrollDirection == 'left' && closeToEdge == false) {
							currentPage ++;
						}
						if(scrollDirection == 'right' && closeToEdge == true) {
							currentPage ++;
						}
			
			//$(".caseStudy .jspDrag").html("<span>&mdash; " + (currentPage + 1) + " of " + totalPages + " &mdash; </span>");
	
			
			//siteScrollPaneAPI.scrollByX2(mouseThrow, true);
			
			$whichPage = $('#caseStudyContainer .caseStudyPage').eq(currentPage);
			slidePos = $whichPage.position().left + 5;
	
			siteScrollPaneAPI.scrollTo(slidePos, 0, true);
			
		});
		*/
		
		
		/*
		$(window).scroll(function () { 
			$('body:not(.mobile) #caseStudyContainer .caseStudyPage').each(function(index){
				if (isScrolledIntoView($(this))) {
					//$('.navDropDown a').html(index);
					currentPage = index;
					$whichPage = $('#caseStudyContainer .caseStudyPage').eq(currentPage);	
					$whichPage.stop(true).fadeTo(100, 1);
					$('#caseStudyContainer .caseStudyPage').not($('#caseStudyContainer .caseStudyPage').eq(currentPage)).stop(true).fadeTo(100, 0.5);	
				}
			});
			$('.mobile #caseStudyContainer .caseStudyPage').fadeTo(0, 1);
		});
		*/
		
		$('#caseStudyContainer').width(pagesWidth);
	}
	
	
	//////////////////////////////////////////////////////////////////
	// CUSTOM SCROLLBARS
	//////////////////////////////////////////////////////////////////
	

	$('.scroll-pane').jScrollPane();
		
	var scrollDirection = 'left';
	var prevScrollPositionX = 0;
		
	$('.caseStudy .scroll-pane-arrows')
		.bind(
			'jsp-initialised',
			function(event, isScrollable)
			{
				//$(".caseStudy .jspDrag").html("<span>&laquo; Drag me &raquo;</span>");
				$(".caseStudy .jspDrag").html("<span>&mdash; Page " + (scrolledIntoViewIndex + 1) + " of " + totalPages + " &mdash; </span>");
				
				$(".jspHorizontalBar").mouseup(function() {
					$(".caseStudy .jspPane").unbind('mousemove');
					//console.log(mouseDistanceOld);
					currentPage = scrolledIntoViewIndex;
					if(scrollDirection == 'left' && closeToLeftEdge == true) {
						currentPage ++;
					}
					if(scrollDirection == 'right' && closeToRightEdge == false) {
						currentPage ++;
					}
					
					$whichPage = $('#caseStudyContainer .caseStudyPage').eq(currentPage);
					slidePos = $whichPage.position().left + 5;
			
					siteScrollPaneAPI.scrollTo(slidePos, 0, true);
				});
				
				
				
				$('#arrowRight').css({
					'display' : 'block'
				});	
			}
		)
		.bind(
			'jsp-scroll-x',
			function(event, scrollPositionX, isAtTop, isAtBottom)
			{
				if(scrollPositionX > prevScrollPositionX) {
					scrollDirection = 'left';
				} else {
					scrollDirection = 'right';
				}
				//console.log(scrollDirection);
				prevScrollPositionX = scrollPositionX;
				
				//isCloseToEdge($('#caseStudyContainer .caseStudyPage').eq(currentPage),scrollPositionX);
				$('#caseStudyContainer .caseStudyPage').each(function() {
					isScrolledIntoView($(this),scrollPositionX);
					$(this).find('.pageCopy').css({'left' : 47 + ($(this).position().left - scrollPositionX)*0.5});
				});
				$(".caseStudy .jspDrag").html("<span>&mdash; Page " + (scrolledIntoViewIndex + 1) + " of " + totalPages + " &mdash; </span>");
			}
		);
	
	var scrollSettings = {
			showArrows: true,
			horizontalGutter: 10,
			autoReinitialise: true,
			verticalArrowPositions: 'os',
			verticalDragMinHeight: 60,
			mouseWheelSpeed: 20
	}
	if($('.caseStudy .scroll-pane-arrows').length != 0) {
		scrollSettings = {
			showArrows: false,
			horizontalGutter: 10,
			autoReinitialise: false,
			verticalArrowPositions: 'os',
			horizontalDragMinWidth: 160,
			mouseWheelSpeed: 20,
			animateScroll: true,
			animateDuration: 1200,
			animateEase: 'easeInOutQuad'
			//hijackInternalLinks: true
		}
	}
	
	var siteScrollPane = $('.scroll-pane-arrows').jScrollPane(scrollSettings);
	
	if(siteScrollPane) {
		//console.log('setting up API obj');
		var siteScrollPaneAPI = siteScrollPane.data('jsp');
		

		
	}
	
	
	
	
			
	$('.scroll .scroll-pane-arrows')
		.bind(
			'jsp-scroll-y',
			function(event, scrollPositionY, isAtTop, isAtBottom)
			{
				if(scrollPositionY >  80) {
					$('body:not(#home) h1').css('top', -scrollPositionY + 100  );
				} else {
					$('body:not(#home) h1').css('top',20);
				}
				//siteScrollPaneAPI.reinitialise();
			}
		)

	
	
	//MAKE THE RIHGT HAND SIDE CONTENT TOP MATCH THE TITLE BOTTOM
	var contentTopPos = $('#introCopy').offset().top - 25
	//$('.scroll #mainContent').css('top',contentTopPos);
	//$('.scroll #mainContent').css('padding-bottom',contentTopPos);
	


	if($('#homeCopy').length != 0) {
	
		
		//////////////////////////////////////////////////////////////////
		// HOMEPAGE COPY SHOW/HIDE
		//////////////////////////////////////////////////////////////////
		
		
		$('.homeCopySub').css({ opacity: 0.0 });
		$('.homeCsLink-0').hover(
			function () {
				$('.homeCopySub').fadeTo(200, 1);
			}, 
			function () {
				$('.homeCopySub').fadeTo(200, 0);
			}
		);
		
		
		
		
		//$('#navTop li.page-item-249').before('<li><span class="divider"></span></li>');
		
		
		
	
		
		
		//////////////////////////////////////////////////////////////////
		// HOMEPAGE TWITTER BUSINESS
		//////////////////////////////////////////////////////////////////	
		
		
		
			
		var twit = 0;
		$("#twitterHomeText").html('<span></span>');
		var $twitHolder = $("#twitterHomeText span")
		
		function twitterHomeTextShow() {
			$twitHolder.animate({
				top: -55
			}, 0, function() {
				//$twitHolder.html("&nbsp;" + twitterTextLinks[twit][0]).parent().parent().attr('href',twitterTextLinks[twit][1]);	
				$twitHolder.html("&nbsp;" + twitterTextLinks[twit][0]);	
				if(twit < twitterTextLinks.length - 1) {
					twit ++;
				} else {
					twit = 0;
				}
			});
			$twitHolder.delay(10).animate({
				top: '+=55'
			}, 600);
			$twitHolder.delay(8000).animate({
				top: '+=55'
			}, 600,function() {
				twitterHomeTextShow();
			});
			
		}
		twitterHomeTextShow();
		
		
		
		//////////////////////////////////////////////////////////////////
		// HOMEPAGE CASE STUDY BUSINESS
		//////////////////////////////////////////////////////////////////	
		
		
		
		
		if($("#csHomeText").length != 0) {	
			var cs = 0;
			$("#csHomeText").html('<span></span>');
			var $csHolder = $("#csHomeText span");
			var $csImg = $("#homeCopy img")
			
			function csHomeTextShow() {
				$csHolder.animate({
					top: -140
				}, 0, function() {
					$csHolder.html('<a class="homeCsLink-' + cs + '" href="' + csTextLinks[cs][1] + '">' + csTextLinks[cs][0]) + '</a>';
					var newHeight = $csHolder.height() + 10;
					$('p.homeCopyMain').css({'height':newHeight});	
					$csImg.attr('src', csTextLinks[cs][2]);	
					//console.log(csTextLinks[cs][2])
					if(cs < csTextLinks.length - 1) {
						cs ++;
					} else {
						cs = 0;
					}
				});
				
				$csImg.delay(10).fadeIn(800);
				$csHolder.delay(10).animate({
					top: '+=140'
				}, 800, function() {
				});
				
				$csImg.delay(5000).fadeOut(500);
				$csHolder.delay(5000).animate({
					top: '+=140'
				}, 800, function() {
					csHomeTextShow();
				});
				
			}
			
			var csImages = new Array();
			for(var i=0; i < csTextLinks.length; i++) {
				csImages[i] = csTextLinks[i][2];
				//console.log(csImages[i]);
			}
			
			$(csImages).preloadImages(function(){});
			
			csHomeTextShow();
		}
	}
	
	//////////////////////////////////////////////////////////////////
	// GET URL VARS FOR THEME SWITCHER
	//////////////////////////////////////////////////////////////////
	
	
	
	
	/*
	// Read a page's GET URL variables and return them as an associative array.
	function getUrlVars()
	{
	    var vars = [], hash;
	    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	    for(var i = 0; i < hashes.length; i++)
	    {
	        hash = hashes[i].split('=');
	        vars.push(hash[0]);
	        vars[hash[0]] = hash[1];
	    }
	    return vars;
	}

	var themeLink = "";
	if(getUrlVars()["theme"]) {
		themeLink = 'theme=' + getUrlVars()["theme"];
	}
	
	$('a').each(function(index) {
		thisHref = $(this).attr('href');
		if(thisHref && thisHref.indexOf('?') < 0) {
			$(this).attr('href',$(this).attr('href') + '?' + themeLink);
		} else {
			$(this).attr('href',$(this).attr('href') + '&' + themeLink);
		}
	});
	*/

	
	//////////////////////////////////////////////////////////////////
	// INITIALIZE THE LOADER
	//////////////////////////////////////////////////////////////////
	
	$('#introCopy li').each(function(){
		var delay = $(this).data('index') * 300;
		$(this).delay(delay).fadeTo(300, 1, function() {
			$(this).data('ready',true);
			$(this).addClass('ready');
			$(this).find('.newFlag').delay(100).animate({top: "+8", opacity: 1},200).delay(2000).animate({top: "-5", opacity: 0},200);
		});
	
	});


	
	
	
    QueryLoader.init();
	siteScrollPaneAPI.reinitialise();
	
	$(document).ready(function() {
		resizeBackgrounds();
		siteScrollPaneAPI.reinitialise();
	});	
	$(window).bind("resize", function(){
		resizeBackgrounds();
		siteScrollPaneAPI.reinitialise();
	});
	
	
	
}); 

