jQuery.extend( jQuery.easing,
{
	easeIn: function (x, t, b, c, d) {
		return jQuery.easing.easeInQuad(x, t, b, c, d);
	},
	easeOut: function (x, t, b, c, d) {
		return jQuery.easing.easeOutQuad(x, t, b, c, d);
	},
	easeInOut: function (x, t, b, c, d) {
		return jQuery.easing.easeInOutQuad(x, t, b, c, d);
	},
	expoin: function(x, t, b, c, d) {
		return jQuery.easing.easeInExpo(x, t, b, c, d);
	},
	expoout: function(x, t, b, c, d) {
		return jQuery.easing.easeOutExpo(x, t, b, c, d);
	},
	expoinout: function(x, t, b, c, d) {
		return jQuery.easing.easeInOutExpo(x, t, b, c, d);
	},
	bouncein: function(x, t, b, c, d) {
		return jQuery.easing.easeInBounce(x, t, b, c, d);
	},
	bounceout: function(x, t, b, c, d) {
		return jQuery.easing.easeOutBounce(x, t, b, c, d);
	},
	bounceinout: function(x, t, b, c, d) {
		return jQuery.easing.easeInOutBounce(x, t, b, c, d);
	},
	elasin: function(x, t, b, c, d) {
		return jQuery.easing.easeInElastic(x, t, b, c, d);
	},
	elasout: function(x, t, b, c, d) {
		return jQuery.easing.easeOutElastic(x, t, b, c, d);
	},
	elasinout: function(x, t, b, c, d) {
		return jQuery.easing.easeInOutElastic(x, t, b, c, d);
	},
	backin: function(x, t, b, c, d) {
		return jQuery.easing.easeInBack(x, t, b, c, d);
	},
	backout: function(x, t, b, c, d) {
		return jQuery.easing.easeOutBack(x, t, b, c, d);
	},
	backinout: function(x, t, b, c, d) {
		return jQuery.easing.easeInOutBack(x, t, b, c, d);
	}
});

jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
	def: 'easeOutQuad',
	swing: function (x, t, b, c, d) {
		//alert(jQuery.easing.default);
		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
	},

	easeInQuint: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t*t + b;
	},
	easeOutQuint: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t*t*t + 1) + b;
	},
	easeInOutQuint: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
		return c/2*((t-=2)*t*t*t*t + 2) + b;
	},
	
	easeInOutBounce: function (x, t, b, c, d) {
		if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
		return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
	}
});


(function($){
	$.fn.kwicks = function(options) {
		var defaults = {
			duration: 200,
			spacing: 0
		};
		var o = $.extend(defaults, options);
	
		return this.each(function() {
			obj = $(this);
			var kwicks = obj.children('li');
			var normWidth = (kwicks.eq(0).css('width')).replace(/px/,'');
			var minWidth = ((normWidth * kwicks.size()) - o.maxWidth) / (kwicks.size() - 1);
			obj.css({
				width : (normWidth * kwicks.size()) + (o.spacing * (kwicks.size() - 1)) + 'px',
				height : kwicks.eq(0).css('height')
			});
			
			// pre calculate left values for all kwicks but the first and last
			var preCalcLefts = new Array();
			for(i = 0; i < kwicks.size(); i++) {
				preCalcLefts[i] = new Array();
				for(j = 1; j < kwicks.size() - 1; j++) {
					if(j < kwicks.size() - 1) {
						if(i == j) {
							preCalcLefts[i][j] = j * minWidth + (j * o.spacing);
						} else {
							preCalcLefts[i][j] = (j <= i ? (j * minWidth) : (j-1) * minWidth + o.maxWidth) + (j * o.spacing);
						}
					}
				}
			}
			
			// loop through all kwick elements
			kwicks.each(function(i) {
				var kwick = $(this);
				if(i == 0) {
					kwick.css('left', '0px');
				} else if(i == kwicks.size() - 1) {
					kwick.css('right', '0px');
				} else {
					kwick.css('left', (i * normWidth) + (i * o.spacing));
				}
				kwick.css({
					margin: 0,
					position: 'absolute'
				});
				
				kwick.mouseover(function() {
					// calculate previous width and left values
					var prevWidths = new Array();
					var prevLefts = new Array();
					for(j = 0; j < kwicks.size(); j++) {
						prevWidths[j] = kwicks.eq(j).css('width').replace(/px/, '');
						prevLefts[j] = kwicks.eq(j).css('left').replace(/px/, '');
					}
					kwicks.stop().removeClass('active');;
					kwick.addClass('active').animate({width: o.maxWidth}, {
						step: function(now) {
							// calculate animation completeness as percentage
							var percentage = (now - prevWidths[i])/(o.maxWidth - prevWidths[i])
							// adjsut other elements based on percentage
							kwicks.each(function(j) {
								if(j > 0 && j < kwicks.size() - 1) { // if not the first or last kwick
									kwicks.eq(j).css('left', prevLefts[j] - ((prevLefts[j] - preCalcLefts[i][j]) * percentage) + 'px');
								}
								if(j != i) {
									kwicks.eq(j).css('width', prevWidths[j] - ((prevWidths[j] - minWidth) * percentage) + 'px');
								}
							});
						},
						duration: o.duration,
						easing: o.easing
					});
				});
			});
			obj.bind("mouseleave", function() {
				var prevWidths = new Array();
				var prevLefts = new Array();
				for(i = 0; i < kwicks.size(); i++) {
					prevWidths[i] = kwicks.eq(i).css('width').replace(/px/, '');
					prevLefts[i] = kwicks.eq(i).css('left').replace(/px/, '');
				}
				kwicks.removeClass('active').stop().eq(0).animate({width: normWidth}, {
					step: function(now) {
						var percentage = (now - prevWidths[0])/(normWidth - prevWidths[0]);
						for(i = 1; i < kwicks.size(); i++) {
							var _k_width = ((prevWidths[i] - normWidth) * percentage);
							if(!isNaN(_k_width))
								kwicks.eq(i).css('width', prevWidths[i] - _k_width + 'px');
							if(i < kwicks.size() - 1) {
								var _k_left = ((prevLefts[i] - ((i * normWidth) + (i * o.spacing))) * percentage);
								if(!isNaN(_k_left))
									kwicks.eq(i).css('left', prevLefts[i] - _k_left + 'px');
							}
						}
					},
					duration: o.duration,
					easing: o.easing
				});
			});
		});
	};
	
})(jQuery);

;



//Calling Functions to Animate Navigation MenuItems

function main_kwicks(){
	jQuery('.kwicks').kwicks({  
        maxWidth: 190,  
		duration: 800,  
        easing: 'easeOutQuint'  
    });  
}

 
$(document).ready(function(){					
	 main_kwicks();
});
