/* Declare a namespace for the site */
var Site = window.Site || {};

/* Create a closure to maintain scope of the '$'
   and remain compatible with other frameworks.  */
(function($) {
	
	//same as $(document).ready();
	$(function() {
	
		var os = navigator.platform;
		os = os.toLowerCase();
		if (os.indexOf("win") != -1) {
			$("#projects li a").css("line-height", "10px");
		}
	
		var pathname = location.pathname;
		var paths = pathname.split("/");
		var page = paths[1];
		$("#nav-" + page).addClass("selected");
		if (page == "people" || page == "press") {
			$("#nav-studio").addClass("selected");
		}
		/*
		
			Project
		
		*/
		if ($("#projects").length > 0) {
			$("#projects header img").each(function(i) {
				$(this).data("featured", $(this).attr("src"));
			});
			$("#projects a").bind("mouseover", function(e) {
				var img = $(this).parent().parent().parent().children("header").children("img");
				$(img).attr("src", $(this).children("img").attr("src"));
			}).bind("mouseout", function(e) {
				var img = $(this).parent().parent().parent().children("header").children("img");
				$(img).attr("src", $(img).data("featured"));
			});
		}
		/*
		
			Projects
		
		*/
		if ($("#project").length > 0) {
			if ($("#project-images img").length > 1) {
				$("<div>").attr("id", "image-viewer").appendTo("#project-box");
				$("#project-images img").each(function(i) {
					$("<a>").data("img", i).text(i + 1).appendTo("#image-viewer");
				});
				$("<a>").attr("id", "show-all").html("&nbsp;").attr("title", "Show All").appendTo("#image-viewer");
				$("<a>").attr("id", "hide-all").html("&nbsp;").attr("title", "Hide All").appendTo("#image-viewer").hide();
				$("#image-viewer a:not(#show-all, #hide-all)").bind("click", function(e) {
					$("#hide-all").trigger("click");
					$("#project-images img").hide();
					$("#project-images img:eq(" + $(this).data("img") + ")").show();
					$("#image-viewer a").removeClass("selected");
					$(this).addClass("selected");
				});
				$("#image-viewer a:eq(0)").addClass("selected");
				$("#show-all").bind("click", function(e) {
					$("#image-viewer a").removeClass("selected");
					$("#project").addClass("all");
					$("#project-images img").show();
					$("#show-all").hide();
					$("#hide-all").show();
				});
				$("#hide-all").bind("click", function(e) {
					$("#project").removeClass("all");
					$("#project-images img").hide();
					$("#project-images img:eq(0)").show();
					$("#show-all").show();
					$("#hide-all").hide();
				});
			}
			$("#project-credits a").attr("target", "_blank");
		}
		/*
		
			Better Living
		
		*/
		if ($("#better-living").length > 0) {
			$(".better-text a").attr("target", "_blank");
		}
		/*
		
			Contact
		
		*/
		if ($("#contact").length > 0) {
			$("#map-zoom").hide();
			$("#map-link").bind("click", function(e) {
				e.preventDefault();
				$("#map-zoom").show();
				$("#map-link").hide();
			});
			$("#contact-map a").bind("click", function(e) {
				e.preventDefault();
				$("#map-zoom").show();
				$("#map-link").hide();
			});
			$("#back").bind("click", function(e) {
				e.preventDefault();
				$("#map-zoom").hide();
				$("#map-link").show();
			});
		}

	});


	$(window).bind("load", function() {
		
		
	
	});
	
})(jQuery);
