$(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 :input').val("");
					$('form :textfield').val("");
					$('form :input').removeClass("filled");
					$('form :input').removeClass("focus");
					$('form :textfield').removeClass("filled");
					$('form :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).val($theValue);
				}
			});
			
			// 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();
			
			

		});
