$(function() {
	$("#mainmenu a").each(function() {
		if (!$(this).hasClass($("body").attr("id"))) {
			$("<div></div>").css("opacity", 0).appendTo(this);
		}
	});
	$("#mainmenu").addClass("fademenu").delegate("a", "hover", function(e) {
		$(this).children("div").stop().fadeTo(e.type == "mouseover" ? "fast" : "slow", e.type == "mouseover" ? 1 : 0);
	});
	$("ul.blockbuttons").delegate("a", "hover", function(e) {
		$(this).stop().animate({
			"backgroundColor": e.type == "mouseover" ? "#eaf3f8" : "#ffffff",
			"borderColor": e.type == "mouseover" ? "#96d1ec" : "#eaf3f8"
		}, e.type == "mouseover" ? "fast" : "normal");
	});
	if (!$.support.opacity) { $(".portfoliopanel").addClass("opaque") };
	$("#filterlist").delegate("a", "click", function(e) {
		e.preventDefault();
		var filter = $(this).blur().attr("href").replace("portfolio/", "");
		if (filter == "portfolio") {
			$(".portfoliopanel:hidden").slideDown("normal").fadeTo("normal", 1);
			$(".portfoliopanel").removeClass("first").filter(":first").addClass("first");
		} else {
			$(".portfoliopanel:visible").not("."+filter).fadeTo("normal", 0, function() {
				$(".portfoliopanel").removeClass("first").filter("."+filter+":first").addClass("first");
			}).slideUp("normal", function() {
				$(".portfoliopanel").removeClass("first").filter("."+filter+":first").addClass("first");
			});
			$(".portfoliopanel:hidden").filter("."+filter).slideDown("normal").fadeTo("normal", 1);
		}
	});
	$("input, textarea").css("borderColor", "#96d1ec").live("focusin focusout", function(e) {
		$(this).stop().animate({
			"borderColor": e.type == "focusin" ? "#1a6cba" : "#96d1ec"
		}, e.type == "focusin" ? "fast" : "normal");
	});
});

// Color Fade
(function(jQuery){jQuery.each(['backgroundColor','borderColor','color'],function(i,attr){jQuery.fx.step[attr]=function(fx){if(fx.state==0){fx.start=getColor(fx.elem,attr);fx.end=getRGB(fx.end)}fx.elem.style[attr]="rgb("+[Math.max(Math.min(parseInt((fx.pos*(fx.end[0]-fx.start[0]))+fx.start[0]),255),0),Math.max(Math.min(parseInt((fx.pos*(fx.end[1]-fx.start[1]))+fx.start[1]),255),0),Math.max(Math.min(parseInt((fx.pos*(fx.end[2]-fx.start[2]))+fx.start[2]),255),0)].join(",")+")"}});function getRGB(color){var result;if(color&&color.constructor==Array&&color.length==3)return color;if(result=/rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color))return[parseInt(result[1]),parseInt(result[2]),parseInt(result[3])];if(result=/rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color))return[parseFloat(result[1])*2.55,parseFloat(result[2])*2.55,parseFloat(result[3])*2.55];if(result=/#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color))return[parseInt(result[1],16),parseInt(result[2],16),parseInt(result[3],16)];if(result=/#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color))return[parseInt(result[1]+result[1],16),parseInt(result[2]+result[2],16),parseInt(result[3]+result[3],16)]}function getColor(elem,attr){var color;do{color=jQuery.curCSS(elem,attr);if(color!=''&&color!='transparent'||jQuery.nodeName(elem,"body"))break;attr="backgroundColor"}while(elem=elem.parentNode);return getRGB(color)}})(jQuery);