
	$(document).ready(function() {
		
		/* Position Header
		-------------------------------------------------*/

		function positionHeaderBg() {
			var winWidth = $(window).width();
			if(winWidth > 900) {
				var sideDist = (winWidth - 900) / 2;
				var pos = (4096 - 398) - ((winWidth - 900) - sideDist);
			} else {
				var pos = 4096 - 398;
			}
			$("div#header-bg").css({
				"left": "-" + pos + "px",
				"margin": "0"
			});
		}
		positionHeaderBg();
		
		$(window).resize(function() {
			positionHeaderBg();
		});
		
		/* Homepage Image Cycle
		-------------------------------------------------*/
		
		if( $("section#home").length != 0 ) {
			$("div.home-slides").cycle({
				pager	: "div.home-slide-nav",
				activePagerClass : "active",
				timeout: 7000
			});
		}
		
		/* Homepage Equal Height Columns
		-------------------------------------------------*/
		
		function homeEqualCols() {
			var leftCol = $("section#home article.home-latest-news div.home-post-content").height();
			var rightCol = $("section#home article.home-latest-post div.home-post-content").height();
			leftCol < rightCol ? $("section#home article.home-latest-news div.home-post-content").height(rightCol) : null;
			rightCol < leftCol ? $("section#home article.home-latest-post div.home-post-content").height(leftCol) : null;
		}
		homeEqualCols();
		
		/* About Page Cycle
		-------------------------------------------------*/
		
		$('.about-slideshow').cycle({ 
		    timeout: 0, 
		    pager:  '.about-thumbnails',
			pagerEvent: 'mouseover',
			activePagerClass: 'current',
		    pagerAnchorBuilder: function(idx, slide) { 
		        // return selector string for existing anchor 
		        return '.about-thumbnails a:eq(' + idx + ')'; 
		    } 
		});
		
		/* People Page Cycle
		-------------------------------------------------*/
		
		// Check to see if we are on a touch device, 
		// ie. No hover event, and adjust accordingly
		var deviceAgent = navigator.userAgent.toLowerCase();
		var agentID = deviceAgent.match(/(iphone|ipod|ipad)/);
		
		if (agentID) {

	        $('#people .people-slideshow').cycle();

		} else {
			
			$('#people .people-slideshow').cycle({ 
			    timeout: 0, 
			    pager:  '.people-thumbnails',
				pagerEvent: 'mouseover',
				activePagerClass: 'current',
			    pagerAnchorBuilder: function(idx, slide) { 
			        // return selector string for existing anchor 
			        return '.people-thumbnails a:eq(' + idx + ')';
			    } 
			});
			
		}
		
		/* People Thumbnail Links
		-------------------------------------------------*/
		
		$(".people-thumbnails a").click(function() {
			window.location = $(this).attr("href");
		});
		
		/* Camer Page Cycle
		-------------------------------------------------*/
		
		$("#camera .left-col").cycle();
		
		/* Show/Hide Thumbnails
		-------------------------------------------------*/
		
		if( $(".about-thumbnails img").length > 12) {
			$(".about-thumbnails").height("140px");
		}
		
		$(".people-thumbnails").height("140px");
		
		$("a.show-hide-thumbnails").click(function(e) {
			var toShow = $(this).prev(".people-thumbnails, .about-thumbnails");
			var theHeight = toShow.height();
			if(theHeight <= 65) {
				$(this).removeClass("view-more").addClass("hide");
				toShow.animate({
					"height": "140px"
				}, 500);
				$.scrollTo("+=65px", 500);
				e.preventDefault();
			} else {
				$(this).removeClass("hide").addClass("view-more");
				toShow.animate({
					"height": "65px"
				}, 500);
				$.scrollTo("-=65px", 500);
				e.preventDefault();
			}
		});
		
		/* Work Page Search Input Clear
		-------------------------------------------------*/
		
		$("section#work input[type=text]").focus(function() {
			$(this).val() == $(this).attr("title") ? $(this).val("") : null;
		}).blur(function() {
			$(this).val() == "" ? $(this).val($(this).attr("title")) : null;
		});
		
		/* Work Project Thumb
		-------------------------------------------------*/
		
		$("section#work div.work-content div.project:nth-child(4n)").css("margin-right", 0);
		
		/* Work Page Slide Toggle
		-------------------------------------------------*/
		
		$(".work-nav-people").click(function(e) {
			$("#skill").slideUp(500);
			$("#people").delay(500).slideDown(500);
			$(this).addClass("selected");
			$(".work-nav-people").removeClass("selected");
			$(this).addClass("selected");
			$(".work-nav-skill").removeClass("selected");
			removeWork();
			e.preventDefault();
		});
		
		$(".work-nav-skill").click(function(e) {
			$("#people").slideUp(500);
			$("#skill").delay(500).slideDown(500);
			$(this).addClass("selected");
			$(".work-nav-people").removeClass("selected");
			removeWork();
			e.preventDefault();
		});
		
		/* Contact Page Google Maps Init
		-------------------------------------------------*/
		
		if( $("section#contact").length != 0 ) {
			initialize();
		}
		
		/* Work Page Hide Work Detail
		-------------------------------------------------*/
		
		$("div.work-detail").each(function() {
			$(this).hide();
		});
		
		/* AJAX load work onto page
		-------------------------------------------------*/
		
		var winScroll;
		var theVideo;
		var contentHeight = $("div.work-content").height();
		
		$("div.project a").live("click", function(e) {
			
			if(contentHeight < 760) {
				
				$("div.work-content").animate({
					'height' : '750px'
				}, 200);
				
			}
			
			var theURL = $(this).attr("href");
			
			if(contentHeight < 750) {
			
				$("div.work-detail").height(760);
				
			} else {
				
				$("div.work-detail").height(contentHeight - 60);
				
			}
			
			$("div.work-detail").fadeIn("slow");
			
			theURL = theURL + " #work-single";
			
			$("#work-loader").loadShiv(theURL, function() {
			
				/*setTimeout(
					"$('video').mediaelementplayer()",
					500
				);*/
				$('video').VideoJS();
				
			});
			
			$.scrollTo(207, 500);
			
			e.preventDefault();
			
			$("#people, #skill").slideUp();
			winScroll = $(window).scrollTop();
			return winScroll;
		
		});
		
		/* Remove loaded work
		-------------------------------------------------*/
		
		function removeWork() {
			$(".work-detail").fadeOut("fast");
			$.scrollTo(winScroll, 500);
			$("#work-single").remove();
			if(contentHeight < 760) {
				$("div.work-content").animate({
					'height' : contentHeight
				}, 1000);
			}
		}
		
		$("a.icon-grid").live("click", function(e) {
			$(this).parent().parent().fadeOut("fast");
			$.scrollTo(winScroll, 500);
			$("#work-single").remove();
			if(contentHeight < 760) {
				$("div.work-content").animate({
					'height' : contentHeight
				}, 1000);
			}
			e.preventDefault();
		});
		
		$("div.work-credits-top h3 a").live("click", function(e) {
			$("div.work-credits-bottom").slideToggle();
			e.preventDefault();
		});
		
		var titleWidth = $("section#blog-home article.active hgroup h1 span").width();
		$("section#blog-home article.active hgroup h1").css("background-position", (titleWidth+126) + "px 0");
		
		$(".work-share").hide()
		
		$(".work-share-toggle").live("click", function(e) {
			$(".work-share").fadeToggle("slow");
			e.preventDefault();
		});
		
		/* Blog Home Page Equal Columns
		-------------------------------------------------*/
		
		function blogEqualCols() {
			var leftCol = $("#blog section").height();
			var rightCol = $("#blog aside").height();
			leftCol < rightCol ? $("#blog section").height(rightCol) : null;
			rightCol < leftCol ? $("#blog aside").height(leftCol) : null;
		}
		blogEqualCols();
		
		/* Blog Page Equal Columns
		-------------------------------------------------*/
		
		function blogPageCols() {
			var leftCol = $("#blog-page .left-col").height();
			var rightCol = $("#blog-page .right-col").height();
			leftCol < rightCol ? $("#blog-page .left-col").height(rightCol) : null;
			rightCol < leftCol ? $("#blog-page .right-col").height(leftCol) : null;
		}
		blogPageCols();

	});
