jQuery.fn.extend({
	galeria:function(options){
		defaults = {}
		id = document.URL.split('#!/');
		id = ((id[1] == undefined) ? 0 : eval(id[1]-1));
		var w = eval((this.width() - 104)), widths = 0, c = 0, box = '', top = '<div class="set">', bottom = '</div>';
		var sets = [];
		var wt = 42;
		options = jQuery.extend(defaults, options);
		this.find('img').each(function(i){
			widths = widths + wt;
			if(widths > w){
				box += bottom+top;
				sets.push(widths-wt)
				widths = wt;
			}
			box += '<div class="thumbjo" style="background:url('+$(this).attr('src')+')">';
			box += '<img id="'+eval(i+1)+'" src="'+$(this).attr('src')+'"/>';
			box += '</div>';
		}).remove();
		this.append($('<div id="foto-grande" />').append($('<img/>')));
		this.append($('<div id="thumb" />').append($('<div id="slider" />').append(top+box+bottom)));		
		$('#thumb').width(w).before($('<div id="setaesquerda" />')).after($('<div id="setadireita" />'));
		$('#setaesquerda').click(function(){if(c !=0){c--;$('#slider').animate({left:'+='+eval(sets[c])+'px'},2000);}});	
		$('#setadireita').click(function(){if(c < sets.length){$('#slider').animate({left:'-='+eval(sets[c])+'px'},2000);c++;}});	
		$('#slider img').click(function(){
			src = $(this).attr('src').split('-thumb').join('-full');
			$('#foto-grande').find('img').each(function(){
				$(this).fadeOut(function(){
					$(this).attr('src',src).bind('load',function(){
						$('#foto-grande').width($(this).width()).css({'left':'50%','margin-left':'-'+eval($(this).width()/2)+'px'});
						$(this).fadeIn();
					});
				});
			});
		}).eq(id).click();
	}
});
