$(function() {
	$("#mainmenu a").each(function() {
		var pos = $(this).css("background-position-x") + " bottom";
		if (pos == " bottom") {
			var pos = $(this).css("background-position").replace(" 0%", "") + " bottom";
			var pos = pos.replace(" 0px bottom", " bottom");
		};
		if (pos && pos != " bottom") {
			$("#mainmenu").addClass("fademenu");
			if (!$(this).hasClass($("body").attr("id"))) {
				$(this).append("<div></div>").children("div").css({"background-position": pos, "opacity": 0});
				$(this).hover(
					function() {
						$(this).children("div").stop().fadeTo("fast", 1);
					}, 
					function() {
						$(this).children("div").stop().fadeTo("slow", 0);
					}
				);
			} else {
				$(this).css("background-position", pos);
			}
		}
	});
	$("input, textarea").css("borderColor", "#96d1ec").focus(function() {
		$(this).stop().animate({"borderColor": "#1a6cba"}, "fast");
	}).blur(function() {
		$(this).stop().animate({"borderColor": "#96d1ec"}, "normal");
	});
	$("ul.blockbuttons").find("a").hover(
		function() {
			$(this).stop().animate({"backgroundColor": "#eaf3f8", "borderColor": "#96d1ec"}, "fast");
		}, 
		function() {
			$(this).stop().animate({"backgroundColor": "#ffffff", "borderColor": "#eaf3f8"}, "slow");
		}
	);
	if (!$.support.opacity) { $(".portfoliopanel").addClass("opaque") };
	$("#filterlist a").click(function(event) {
		event.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);
		}
	});
});

// 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);