var images = new Array();

function custom_random(lower, upper)
{	
	diff = upper - lower;
	rand = Math.round(Math.random() * diff);

	return parseInt(lower) + rand;	
}

function changeImage(image_id)
{
	var anchor = images[image_id];
	var title = $("#" + image_id).attr('alt');
		
	var gallery_id = image_id.substring(4,5);	
	
	$('#gallery_' + gallery_id + ' img')
		.attr('src', anchor)
		.attr('alt', title);				
				
	   $('.captioned_photo p span').html(title);		
}

$(document).ready(function() 
{	
	// Eliminam els elements anchors de les imatges			
	$('.gallery_content a').each(function() {
		var img_id = $(this).children().attr('id');		
		images[img_id] = $(this).attr('href');
		
		$(this)
			.children()
				.appendTo($(this).parent())
				.css({'cursor': 'pointer'})
				.click(function() {				
					changeImage($(this).attr('id'));										
				});
								
		$(this).remove();		
	});				
});