jQuery.fn.extend({
	flipIt: function() {
		var container = jQuery(this);
		container.find("li .content").each(function() {
			var list = $(this);
			var listH = list.height();	
			list.css({maxHeight: listH, height: 1, display: "none"});
		});
		
		container.find("li").addClass("flip");
		var active = container.find("li.active .content");
		var active_height = active.css("maxHeight");
		active_height = parseInt(active_height.toString().replace(/\D/gi, ""));
		active.css({height: active_height, display: "block"});
		
		container.find(".tab").hoverIntent({
			sensitivity: 10,
			interval: 100,
			over: function() {
				var target = $(this).parent();
				var oldTarget = target.parent().find(".active");
				
				if(target.attr("class").indexOf("active") == -1 && target.parent().find(".animating").length == 0) {
					
					body_height = target.children(".content").css("maxHeight");
					active_height = target.parent().find(".active").children(".content").css("maxHeight");
				
					body_height = parseInt(body_height.toString().replace(/\D/gi, ""));
					if(typeof active_height != "undefined")
						active_height = parseInt(active_height.toString().replace(/\D/gi, ""));
					else
						active_height = 1;
					
					target.children(".content").css({display: "block"});
					target.addClass("animating");
					oldTarget.addClass("animating");
					target.children(".content").animate({height:body_height}, {
						step: function(now, fx) {
							new_height = active_height * (1-(now/body_height));
							if(new_height < 1)
								new_height = 1;
							oldTarget.children(".content").height(new_height);											
						},
						duration: 300,
						complete: function() {
							oldTarget.removeClass("active");
							oldTarget.children(".content").css({display: "none"});
							oldTarget.find("img").each(function() { this.src = this.src.replace(/_on\./, "_off."); });
							target.addClass("active");
							target.find("img").each(function() { this.src = this.src.replace(/_off\./, "_on."); });
							target.removeClass("animating");
							oldTarget.removeClass("animating");
						}
					});
				}
			},
			timeout: 100,
			out: function() {}
		});
	}
});

jQuery.fn.extend({
	expandY: function(target, startY, endY) {
		var ele = jQuery(this);
		ele.hoverIntent({
			sensitivity: 10,
			interval: 100,
			over: function() {
				
				if($(target).css('margin-top') == endY + "px")
					return;
					
				$(target).animate({marginTop: endY + "px"}, {
					duration: 500,
					complete: function() {
						$(target).find("input")[0].focus();
						$(target).find("img.tab").each(function() { this.src = this.src.replace(/login\./, "close."); });
					}
				});
			},
			timeout: 100,
			out: function() {}
		});
		ele.click(function() {
			if($(target).css('margin-top') != endY + "px")
				return;
			$(target).animate({marginTop: startY + "px"}, {
				duration: 500, 
				complete: function() {
					$(target).find("img.tab").each(function() { this.src = this.src.replace(/close\./, "login."); });
				}
			});
		});
	}
});