jQuery.fn.mypicasa = function(options) {
	
	var $ = window.jQuery;
	var state = this;
	var gallery = $(this);
	var clip = $(this).children('ul');
	
	// insert back and next divs
	gallery.before('<a class="mypicasa_prev disabled" href="javascript:;">&laquo;</a>');
	var prev = gallery.prev(':first');
	gallery.after('<a class="mypicasa_prev disabled" href="javascript:;">&raquo;</a>');
	var next = gallery.next(':first');
	
	var count = clip.children('li').length;
	var thumb_width = clip.children('li').width() + 10;
	var clip_width = count * thumb_width;
	var gallery_width = (options.size * thumb_width)-9;
	
	clip.css('width', clip_width);
	gallery.css('width', gallery_width);
	
	if (clip_width > gallery.width())
		next.toggleClass('disabled');
	
	prev.click(function() {
		if (!state.moving) {
			var left = parseInt(clip.css('left'));
			if (left < 0) {
				var to = left+gallery.width()+9;
				state.moving = true;
				clip.animate({left: to}, function() {
					left = parseInt(clip.css('left'));
					if (left >= 0)
						prev.addClass('disabled');
					if (left + clip.width() > gallery.width())
						next.removeClass('disabled');
					state.moving = false;
				});
			}
		}
	});
	
	next.click(function() {
		if (!state.moving) {
			var left = parseInt(clip.css('left'));
			if (left + clip.width() > gallery.width()) {
				var to = parseInt(clip.css('left'))-(gallery.width()+9);
				state.moving = true;
				clip.animate({left: to}, function() {
					left = parseInt(clip.css('left'));
					if (left < 0)
						prev.removeClass('disabled');
					if (left + clip.width() <= gallery.width())
						next.addClass('disabled');
					state.moving = false;
				});
			}
		}
	});
	
	
};
