/*
-----------------------------------------------
BrownLedge.org
Script: vdwGallery.js
Author: Ben Glassman
Organization: Vermont Design Works
Created: 13 August 2008
----------------------------------------------- */

vdwGallery = {
	init:function() {
		$jq('#vdwgallery-album-thumbnails').jcarousel({ vertical : true, scroll : 1 });
		$jq('#vdwgallery-photo-thumbnails').jcarousel({
			scroll : 1,
			initCallback: vdwGallery.photoThumbnailsInitCallback
		});
	},
	photoThumbnailsInitCallback : function(carousel) {
		vdwGallery.browser = carousel;
		$jq('#vdwgallery-photo-thumbnails a').bind('click', function() {
			var photo_id = vdwGallery.parsePhotoIdFromUrl($jq(this).attr('href'));
			vdwGallery.loadPhotoHtml(photo_id);
			return false;
		});
	},
	loadPhotoHtml : function(photo_id) {
		$jq.ajax({
			type: "POST",
			url: "/assets/snippets/gallery/get_photo_html.php",
			data: "photo_id=" + photo_id + '&ajax=1',
			success: vdwGallery.replacePhotoHtml,
			cache: false
		});	
	},
	replacePhotoHtml : function(data) {
// 		$jq('.photo_full').remove();
// 		$jq('#content').append(data);
		$jq('#photo-container').html(data);
		vdwGallery.preparePrevNextLinks();
	},
	preparePrevNextLinks : function() {
		$jq('.prev_next_links a').click(function(e) {
			e.preventDefault();
			var photo_id = vdwGallery.parsePhotoIdFromUrl($jq(this).attr('href'));
			vdwGallery.loadPhotoHtml(photo_id);
		});
	},
	parsePhotoIdFromUrl : function(url) {
		return url.substr(url.indexOf('photo_id=') + 9);		
	}
}
$jq(document).ready(vdwGallery.init);