(function($){
	$.fn.extend({
		list : function() {
			return this.each(function() {
				var el = $(this).data("current", 0),
					next = el.find(".next"),
					prev = el.find(".previous").hide(),
					uls = el.find("ul"),
					locked = false;
				
				uls.first().show();
				
				next.click(function() {
					if (locked) return false;
					locked = true;
					
					var current = el.data("current"),
						c = el.find("ul").eq(current),
						n = el.find("ul").eq(current + 1);
						
					c.animate({ left: 800 }, 'slow', function() {
						$(this).hide();
						next.toggle((current + 1) != uls.length - 1);
						prev.toggle(current + 1 > 0);
						locked = false;
					});
					n.css("left", -800).show().animate({ left: '43' }, 'slow');
					
					el.data("current", current + 1);
					
					return false;
				});
				
				prev.click(function() {
					if (locked) return false;
					locked = true;
					
					var current = el.data("current"),
						c = el.find("ul").eq(current),
						n = el.find("ul").eq(current - 1);
						
					c.animate({ left: -800 }, 'slow', function() {
						$(this).hide();
						next.toggle((current - 1) != uls.length - 1);
						prev.toggle(current - 1 > 0);
						locked = false;
					});
					n.css("left", 800).show().animate({ left: '43' }, 'slow');
					
					el.data("current", current - 1);
					
					return false;
				});				
			});
		},
		grid : function() {
			return this.each(function() {
				var el = $(this).data("current", 0),
					current = 0,
					prev = $('<li><a href="#" class="nav previous"></a></li>').hide(),
					next = $('<li><a href="#" class="nav next"></a></li>'),
					page_buttons = [],
					bar = el.find(".page-bar ul"),
					pages = el.find(".page"),
					active = pages.first().show(),
					locked = false,
					setActive = function(p) {
						current = p;
						
						active.hide();
						active = pages.eq(p).show();
						
						bar.find(".active").removeClass("active");
						page_buttons[p].find("a").addClass("active");
						
						prev.toggle(p != 0);
						next.toggle(p != pages.length - 1);
					};
				
				bar.append(prev);
				for (var i = 0; i < pages.length; i++) {
					page_buttons[i] = $('<li><a href="#" class="' + ((i == 0) ? "active" : "") + '">' + (i+1) + '</a></li>');
					bar.append(page_buttons[i]);
					
					page_buttons[i].find('a').data("page", i).click(function() {
						var p = $(this).data("page");
						setActive(p);
						return false;
					});
				}
				bar.append(next);
				prev.find("a").click(function() {
					setActive(current - 1);
					return false;
				});
				next.find("a").click(function() {
					setActive(current + 1);
					return false;
				});

				/*
				next.click(function() {
					if (locked) return false;
					locked = true;
					
					var current = el.data("current"),
						c = el.find("ul").eq(current),
						n = el.find("ul").eq(current + 1);
						
					c.animate({ left: 800 }, 'slow', function() {
						$(this).hide();
						next.toggle((current + 1) != uls.length - 1);
						prev.toggle(current + 1 > 0);
						locked = false;
					});
					n.css("left", -800).show().animate({ left: '43' }, 'slow');
					
					el.data("current", current + 1);
					
					return false;
				});
				
				prev.click(function() {
					if (locked) return false;
					locked = true;
					
					var current = el.data("current"),
						c = el.find("ul").eq(current),
						n = el.find("ul").eq(current - 1);
						
					c.animate({ left: -800 }, 'slow', function() {
						$(this).hide();
						next.toggle((current - 1) != uls.length - 1);
						prev.toggle(current - 1 > 0);
						locked = false;
					});
					n.css("left", 800).show().animate({ left: '43' }, 'slow');
					
					el.data("current", current - 1);
					
					return false;
				});*/
			});
		},
		placeholder : function(options) {
			if (!options) {
				options = {};
			}
			
			return this.each(function() {
				var input = $(this);
				var wrapper = input.wrap("<span style='position: relative;line-height: 100%;display: inline-block; zoom: 1' />").parent();
				var label = $("<label for='" + input.attr("id") + "'>" + input.attr("placeholder") + "</label>").css({
					opacity : 0.65,
					position : "absolute",
					left : parseInt(input.css("padding-left")) + 2,
					top : options.top ? options.top : (isNaN(parseInt(input.css("top"))) ? 0 : parseInt(input.css("top"))) + parseInt(input.css("margin-top")) + parseInt(input.css("padding-top"))+ parseInt(input.css("border-top-width")),
					"font-size" : input.css("font-size")
				});
				wrapper.css("float", input.css("float"));
				wrapper.append(label);

				if (input.val().length) {
					label.hide();
				}
				
				input.focus(function() {
					$(this).parent().find("label").animate({ opacity: .3 }, "fast");
				}).keydown(function() {
					var t = this;
					setTimeout(function() {
						$(t).parent().find("label").css("display", (t.value.length) ? "none" : "");
					}, 0);
				}).blur(function() {
					$(this).parent().find("label").animate({ opacity: .65 }, "fast");
				}).attr("placeholder", "");
			});
		}		
	});
})(jQuery);
