$(function(){
	
var HTTP_PATH = "http://www.stoprapenow.org/get-cross/";

// stoprapenow map object
window.SRN.Gallery = {
	images: null,
	current: 0,
	total: 0,
	in_progress: false,
	init: function() {
		alert("Aqui???");
		if ($('div#jqModal').size() === 0)
			return false;
		$('a.country').live('click', function() {
			//$.get(HTTP_PATH + 'data.php','c=' + this.href.replace(HTTP_PATH + '#', ''),null,'jsonp');
			$.get('window.php','c=' + this.href.replace(HTTP_PATH + '#', ''), null,'jsonp');
			return false;
		});
		Shadowbox.init({adapter: 'jquery'});
	},
	setGallery: function(data) {
		if (!$('div#hidden_links a').is('[rel="shadowbox[' + data[0].Country + ']"]')) {
			$('div#hidden_links').html('');
			Shadowbox.clearCache();
			for (var i = 0; i < data.length; i++) {
				Shadowbox.setup(
					$('<a title="' + data[i].Comment + '" rel="shadowbox[' + data[i].Country + ']">picture ' + (i+1) + '</a>')
						.attr('href', HTTP_PATH + 'images/mosaic/pics/' + data[i].PName)
						.appendTo('div#hidden_links'),
					{ description: '<span>' + data[i].Name/* + ',' + data[i].Country*/ + '</span>' }
				);
			}
		}
		$("div#hidden_links a:eq(0)").click();
	},
	next: function() {
		if (this.in_progress)
			return false;
		this.current++;		
		if ((this.current + 1) === this.total)
			$('div#wrapper a.right-arrow').hide();
		$('div#wrapper a.left-arrow').show();
		this.changeImage();
		return false;
	},
	previous: function() {
		if (this.in_progress)
			return false;
		this.current--;
		if (this.current <= 0)
			$('div#wrapper a.left-arrow').hide();
		$('div#wrapper a.right-arrow').show();
		this.changeImage();
		return false;
	},
	changeImage: function(index) {
		index = index || this.current;
		this.in_progress = true;
		var current = this.images[index],
			context = $('');
		if (!current)
			return false;
		(function(current){
			$('div.gallery div.photo img')
				.fadeOut('fast', function(){
					this.src = 'images/mosaic/' + current.photo;
					this.alt = this.title = "Photo sent by " + current.author + " from " + current.country
				});		
			with ($('div#wrapper div.gallery ul.details')) {
				find('li.name').html(current.author);
				find('li.country').html(current.country);
				find('li.description').html(current.description);
			}
		})(current);
	},
	open: function(country) {
	}
}

});