 $(document).ready(function() {

	// Set everything up - hide and show things	
 	$("#commentform:not(.haserrors,.expanded)").hide();
 	$('input[type="text"]').addClass("idle");
 	$('textarea').addClass("idle");
 	
 	// MouseOver for main navigation (topnav)
	$('img.topnavlink').each(function(){
    	var t=$(this);
	    var src1= t.attr('src');
	    var newSrc = src1.substring("", src1.lastIndexOf('.'));
	    
    	t.hover(function(){
        	$(this).attr('src', newSrc+ '_over.' + /[^.]+$/.exec(src1));
	    }, function(){
    	    $(this).attr('src', newSrc + '.' + /[^.]+$/.exec(src1));
	    });
	});

	$('.teammemberpic').each(function(){
    	var t=$(this);
	    var src1= t.attr('src');
	    var newSrc = src1.substring("", src1.lastIndexOf('.'));
	    
    	t.hover(function(){
        	$(this).attr('src', newSrc+ '_over.' + /[^.]+$/.exec(src1));
	    }, function(){
    	    $(this).attr('src', newSrc + '.' + /[^.]+$/.exec(src1));
	    });
	});

	$('.portfolio_border').each(function(){
    	var t=$(this);
	    var src1= t.attr('src');
	    var newSrc = src1.substring("", src1.lastIndexOf('.'));
	    
    	t.hover(function(){
    		$(this).animate({opacity:0},'fast',function(){
	        	$(this).attr('src', newSrc+ '_over.' + /[^.]+$/.exec(src1));
    	    	$(this).animate({opacity:1},'slow')});
	    }, function(){
    		$(this).animate({opacity:0},'fast',function(){
	    	    $(this).attr('src', newSrc + '.' + /[^.]+$/.exec(src1));
	    	    $(this).animate({opacity:1},200)});
	    });
	});

	// Toggling the comment form on news posts
	$('#leaveacomment').click(function(){
		$('#commentform').slideToggle();
		return false;
	});
	
	// MouseOver effect on news articles
	//$('div.newsstory:not(.current)').hover(
	$('ol#listing.news li').hover(
		function(){
				$(this).animate({backgroundColor:"#eeeef2"},'fast');
		},
		function(){
				$(this).animate({backgroundColor:"#ffffff"},'fast');
		});

	// Highlighting fields on forms when they have focus
	$('input[type="text"]:not(.search-input)').focus(function(){
		$(this).animate({
			borderTopColor:"#666",
			borderRightColor:"#666",
			borderBottomColor:"#666",
			borderLeftColor:"#666"},'fast');
     });  
     $('input[type="text"]:not(.search-input)').blur(function(){
     $(this).animate({
	     	borderTopColor:"#e4e4e4",
			borderRightColor:"#e4e4e4",
			borderBottomColor:"#e4e4e4",
			borderLeftColor:"#e4e4e4"},'fast');
     });
	$('textarea').focus(function() {  
		$(this).animate({
			borderTopColor:"#666",
			borderRightColor:"#666",
			borderBottomColor:"#666",
			borderLeftColor:"#666"},'fast');
     });  
     $('textarea').blur(function() {  
		$(this).animate({
			borderTopColor:"#e4e4e4",
			borderRightColor:"#e4e4e4",
			borderBottomColor:"#e4e4e4",
			borderLeftColor:"#e4e4e4"},'fast');
     });

	// Moving news titles on homepage
	$('a.storytitle').hover(function() {
		$(this).css("background-color","#eeeef2");
		$(this).animate({ paddingLeft : "8px" }, 'fast');
	}, function() {
		$(this).css("background-color","#ffffff");
		$(this).animate({ paddingLeft : "0px" }, 'fast');
	});

/*	$('#accordion .workitem a').hover(function() {
		$(this).animate({ paddingLeft : "8px" }, 'fast');
	}, function() {
		$(this).animate({ paddingLeft : "0px" }, 'fast');
	});
*/
	// Drive the car when you click it!
	$('img.floater#car').click(function(){
		driveCar();
	});
	
	$("#mf085ffbrp_submit").click(function(){
		driveCar();
	});
	
	function driveCar(){
		$("img.floater#car").animate({left: "880px", top: "-120px"},2000);
	};

// Portfolio hide/display things
	
	$(".portfolioimage_large").hide();
	$(".portfolioimage_large:first").addClass("current");
	$(".portfolioimage_large:last").addClass("last");
	$(".portfolioimage_large.current").show();
	$(".portfolioimage_small:first").addClass("currentthumbnail");
	
	$(".portfoliosummary").hide();
	$(".portfoliosummary:first").show().addClass("currentsummary");
//	$(".portfoliosummary:first").addClass("currentsummary");
	
	$(".portfolioimage_small").click(function(){
		$(window).stopTime("portfoliobox");
		if($(this).hasClass("currentthumbnail")){
			// Don't do anything if this is the current thumbnail
		}
		else{
			$(".currentthumbnail").removeClass("currentthumbnail");
			$(this).addClass("currentthumbnail");
			imagetodisplay = "#portfolioimage_large_" + $(this).attr('id');
			$(".current").fadeOut("slow", function(){
				$(".current").removeClass("current");
				$(imagetodisplay).addClass("current");
				$(".current").fadeIn("slow");
			});
			moveSlider();
			portfolioText();
		}
	});

	function moveSlider(){
		var pos = $(".currentthumbnail").position();
		sliderposition = pos.left;
		$("#slider").animate({"left":sliderposition},300);
	};

	function portfolioText(){
		currentportfolio = "#portfoliosummary_" + $(".currentthumbnail").attr("id");
		$(".currentsummary").fadeOut("fast", function(){
			$(".currentsummary").removeClass("currentsummary");
			$(currentportfolio).addClass("currentsummary");
			$(".currentsummary").fadeIn("fast");
		});
	};
	
	$("#accordion").accordion({ animated: "bounceslide", active: $("h3.currentitem")});

 });