var swap_image = function(e, m) {
	$("#main_gallery_image").attr('src', 'images/wait.gif');
	var cur_img = m ? m : this;
	var new_img = cur_img.src.replace('-thumb', '');
	var img = new Image();
	img.src = new_img;
	$("#main_gallery_image").attr('src', new_img);
	return false;
};

var swap_subproj = function(e, _id) {
	var id =  _id ? _id : this.id;
	var _prefix = '#' + id;
	$("#thumbs").html( $(_prefix + '_thumbs').html() );
	$("#main_image_caption").html( $( _prefix + '_desc').html()  );
	$("#thumbs .thumbnail").each(function(i) {
		if ( i == 0 ) {
			swap_image(null, this);
		} 
		$(this).bind("click", swap_image);
	});
	$(".subp_link").each(function(i) { 
		this.id == id ? $(this).addClass('active') : $(this).removeClass('active');
	} );
	return false;
};

$(document).ready(function() {
	$(".thumbnail", ".thubnail:hidden").each(function(i) { 
		$(this).bind("click", swap_image); 
	} );
	$(".subp_link").each(function(i) {
		$(this).bind("click", swap_subproj );
		if ( i == 0 ) {
			swap_subproj(null, this.id);
		}
	});
});