$(document).ready( function() {
	
			$("ul#mycarousel li a").bind("mouseenter", function(e){
		        var titleHold = $(this).attr("title");
				var altHold = this.alt;
				
				$("span#work-title").html(": "+titleHold);
				
				$(this).removeAttr("title");
				this.alt = "";
				
				$("#holder").attr({
					title: titleHold,
					alt: altHold
				});
		    });
		
			$("ul#mycarousel li a").bind("mouseleave", function(e){
				var titleHold = $("#holder").attr("title");
				var altHold = $("#holder").attr("alt");
				
				$("span#work-title").html("");
				
				$(this).attr({
					title: titleHold,
					alt: altHold
				});
		    });
		
			$("ul#mycarousel li a").bind("mousedown", function(e){
				var titleHold = $("#holder").attr("title");
				var altHold = $("#holder").attr("alt");
				
				$("span#work-title").html("");
				
				$(this).attr({
					title: titleHold,
					alt: altHold
				});
		    });
	
			// Carousel
			
			$("#mycarousel").jcarousel({
				scroll: 8
			});
						
			// Carousel Lightboxing
			
			$('#mycarousel a').lightBox();
	
			// Case studies accordion
			
			$("a[rel='external']").attr("target","_blank");
			$("#content").accordion({
				header: "dt",
				clearStyle: true,
				autoHeight: false,
				animated: "slide",
				alwaysOpen: false,
				active: 200
			});
			
			// Expanding and controlling header
			
			flipHeader=0;
			
			$.showHeader = function () {
				$.hideFooter();
				$("#about-holder").animate( { marginTop:"0" }, { queue:false, duration:510 } );
				$("#header-holder").animate( { marginTop:"302px" }, { queue:false, duration:510 } );
				$("#about-holder a#about-toggle").addClass("active");
				flipHeader=1;
			};
			
			$.hideHeader = function () {
				$("#about-holder").animate( { marginTop:"-302px" }, { queue:false, duration:510 } );
				$("#header-holder").animate( { marginTop:"0" }, { queue:false, duration:510 } );
				$("#about-holder a#about-toggle").removeClass("active");
				flipHeader=0;
			};			
			
			$("#about-holder a#about-toggle").click(function(){
				if(flipHeader!=1){
					$.showHeader();
				} else {
					$.hideHeader();
				}
			});
			
			$("#foot-toggle").click(function () {
				if(flipHeader==1){
					$.hideHeader();
				}
			});
			
			$("a#ie-ok").click(function () {
				$("#ie").fadeOut(2000);
			});
						
			$("#content").click(function () {
				if(flipHeader==1){
					$.hideHeader();
				}
			});
			
			// Expanding and controlling footer
			
			flipFooter=0;
			
			$('#message').hide();
			
			$.showFooter = function () {
				$.hideHeader();
				$("#footer-holder").animate( { margin:"-250px 0 0 0" }, { queue:false, duration:510 } );
				$("#footer-holder").animate( { height:"250px" }, { queue:false, duration:510 } );
				$("#footer div").fadeIn(300);
				$("#foot-toggle").addClass("active");
				if($("#contactForm:hidden")){
					$('#message').hide();
					$('form#contactForm :input').val("");
					$('form#contactForm :textfield').val("");
					$('form#contactForm :input').removeClass("filled");
					$('form#contactForm :input').removeClass("focus");
					$('form#contactForm :textfield').removeClass("filled");
					$('form#contactForm :textfield').removeClass("focus");
					$('#contactForm fieldset').show();
				}
				flipFooter=1;
			};
			
			$.hideFooter = function () {
				$("#footer-holder").animate( { margin:"-56px 0 0 0" }, { queue:false, duration:510 } );
				$("#footer-holder").animate( { height:"100px" }, { queue:false, duration:510 } );
				$("#footer div").fadeOut(500);
				$("#foot-toggle").removeClass("active");
				flipFooter=0;
			};			
			
			//$("#footer-holder").click(function(){
			//	if(flipFooter!=1){
			//		$.showFooter();
			//	} else {
			//		$.hideFooter();
			//	}
			//});
			//
			//$("#elsewhere").click(function(){
			//	if(flipFooter!=1){
			//		$.showFooter();
			//	} else {
			//		$.hideFooter();
			//	}
			//});
			
			$("a#foot-toggle").click(function () {
				if(flipFooter!=1){
					$.showFooter();
				} else {
					$.hideFooter();
				}
			});
			
			$("#header-holder").click(function () {
				if(flipFooter==1){
					$.hideFooter();
				}
				if(flipHeader==1){
					$.hideHeader();
				}
			});
			
			$("#content").click(function () {
				if(flipFooter==1){
					$.hideFooter();
				}
			});
			
			// Contact Form
			
			$("input, textarea").bind('focus', function() {
				$(this).addClass("focus");
			});
			
			$("input, textarea").bind('blur', function() {
				$theValue = $(this).val();
				if($theValue == ""){
					$(this).removeClass("focus");
				}else{
					$(this).removeClass("focus");
					$(this).addClass("filled");
					$(this).value($theValue);
				}
			});
			
			
			$("form#contactForm").validate({
			focusInvalid: false,
			  rules: {
				},
				highlight: function(element, errorClass) {
				     $(element).addClass(errorClass);
				     $(element.form).find("label[for=" + element.id + "]")
				                    .addClass(errorClass);
				  },
				  unhighlight: function(element, errorClass) {
				     $(element).removeClass(errorClass);
				     $(element.form).find("label[for=" + element.id + "]")
				                    .removeClass(errorClass);
				  },
			messages: {
			     name: "Please specify your name",
			     email: {
			       required: "Email address required",
			       email: "Must be a valid email address"
			     }
			   },
				submitHandler: function(form) {
				   	var formString = $('form#contactForm').formSerialize();
					$.ajax({
						type: "POST",
						url: "send.php",
						data: formString,
						success: function(data){
							$("#message").fadeIn(500);
							$("#message").html(data);
							$("form fieldset").fadeOut(500);
						}
					});
					return false;
				}
			});
			
			// Survey Form Validation - Commented Out Until Form is Ready
			
			//$("form#survey-form").validate({
			//	submitHandler: function(form) {
			//	   	var formString = $('form#survey-form').formSerialize();
			//		$.ajax({
			//			type: "POST",
			//			url: "send.php",
			//			data: formString,
			//			success: function(data){
			//			}
			//		});
			//		return false;
			//});
			
			// Case Studies Ajax
			
			$.fn.fillContent = function() {
			    return this.each(function() {
					var myTrigger = this.id;
					var myTriggerID = "#"+myTrigger;
					var myTarget = myTrigger.replace('-dt','');
					var myTargetID = "#"+myTarget;
					var myTargetHTML = "cases/"+myTarget+".html";

					$(myTriggerID).one("click", function () { 
					      $.ajax({
						  url: myTargetHTML,
						  cache: true,
						  success: function(html){
						    $(myTargetID).append(html);
						  }
						});
					});
				});
			};
			
			$("dl.case dt").fillContent();
			
			

		});