/*
 * jQuery Color Animations
 * Copyright 2007 John Resig
 * Released under the MIT and GPL licenses.
 */

(function(jQuery){
	jQuery.each(['backgroundColor', 'borderBottomColor', 'borderLeftColor', 'borderRightColor', 'borderTopColor', 'color', 'outlineColor'], 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);

$(document).ready(function(){
	
	speed = '250';
	colors = ['#660099', '#442200', '#3f8040', '#f98152'];
	menu = $('#menu li');
	defaultColor = menu.find('p').css('color');
	defaultBG = menu.find('h2').css('backgroundColor');
	menu.hover(function() {
		c = colors[eval(menu.index(this))];
		$('h2, .bar', this).animate({'backgroundColor': c}, speed);
		$('p', this).animate({'color': c}, speed);
	}, function () {
		$('h2, .bar', this).animate({'backgroundColor': defaultBG}, speed);
		$('p', this).animate({'color': defaultColor}, speed);
	});
	
	
	
	/*
	function tint(hex) {
		adj = 150;
		result = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(hex);
		rgb = [parseInt(result[1],16), parseInt(result[2],16), parseInt(result[3],16)];
		lumin = rgb[0]*0.30 + rgb[1]*0.59 + rgb[2]*0.11;
		if (lumin > adj) {
			change = parseInt(lumin - adj);
		} else {
			change = parseInt(adj - lumin);
		}
		for (i = 0; i <= 2; i++) {
			rgb[i] = rgb[i] - change;
			if (rgb[i] > 255) rgb[i] = 255;
			if (rgb[i] < 0) rgb[i] = 0;
		}
		return 'rgb(' + rgb.join(',') + ')';
	};
	*/

});


