function Gallery(frame1_id, frame2_id, title_id, width, offset) {
	this.photo_names = new Array();
	this.photo_titles = new Array();
	this.photos = new Array();
	this.num_photos = 0;

	this.gallery_width = width;
	this.left_offset = offset;
	this.frame1 = frame1_id;
	this.frame2 = frame2_id;
	this.title = title_id;

	this.active_photo_index = 0;
	this.active_frame = 0;
}

Gallery.prototype.add_photo = function(src, title) {
	this.photo_names.push(src);
	this.photo_titles.push(title);
	this.photos.push(new Image());
	this.num_photos++;
}

Gallery.prototype.get_next_active_photo = function() {
	return (this.active_photo_index + 1) % this.num_photos;
}

Gallery.prototype.get_previous_active_photo = function() {
	return (this.active_photo_index + this.num_photos - 1) % this.num_photos;
}

Gallery.prototype.next_active_frame = function() {
	this.active_frame = (this.active_frame + 1) % 2 ;
}

Gallery.prototype.initialize = function() {
	num_photos = this.num_photos;
	this.photos[num_photos - 1].src = this.photo_names[num_photos - 1];
	this.photos[0].src = this.photo_names[0];
	this.photos[1].src = this.photo_names[1];

	$(frame1).css('background-image', 'url('+ this.photos[0].src +')');
	$(this.title).html(this.photo_titles[0]);
}

Gallery.prototype.navigate_left = function() {
	if (this.active_frame) {
		f1 = this.frame2;
		f2 = this.frame1;
	} else {
		f1 = this.frame1;
		f2 = this.frame2;
	}

	this.active_photo_index = this.get_next_active_photo();
	this.next_active_frame();

	var title = this.title;
	var photo_titles = this.photo_titles;
	var active_photo_index = this.active_photo_index;

	$(f2).css({'background-image': 'url('+ this.photos[active_photo_index].src +')', 'left': this.gallery_width}).show();

	this.photos[this.get_next_active_photo()].src = this.photo_names[this.get_next_active_photo()];

	$(title).fadeOut(150, function(){
		$(title).html(photo_titles[active_photo_index]);
		$(title).fadeIn(150);
	});
	$(f1).animate({'left': this.gallery_width*-1, 'opacity': 0}, 310, function(){$(f1).hide();});
	$(f2).animate({'left': this.left_offset, 'opacity': 1}, 300);
}

Gallery.prototype.navigate_right = function() {
	if (this.active_frame) {
		f1 = this.frame2;
		f2 = this.frame1;
	} else {
		f1 = this.frame1;
		f2 = this.frame2;
	}

	this.active_photo_index = this.get_previous_active_photo();
	this.next_active_frame();

	var title = this.title;
	var photo_titles = this.photo_titles;
	var active_photo_index = this.active_photo_index;

	$(f2).css({'background-image': 'url('+ this.photos[active_photo_index].src +')', 'left': this.gallery_width*-1}).show();

	this.photos[this.get_previous_active_photo()].src = this.photo_names[this.get_previous_active_photo()];

	$(title).fadeOut(150, function(){
		$(title).html(photo_titles[active_photo_index]);
		$(title).fadeIn(150);
	});
	$(f1).animate({'left': this.gallery_width, 'opacity': 0}, 310, function(){$(f1).hide();});
	$(f2).animate({'left': this.left_offset, 'opacity': 1}, 300);
}

