/* 
 * Copyright 2007 Jeremy KUHN
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

zwg.namespace('zwg.widgets.content');

/**
 * PictureViewer Widget library.
 * @ignore
 * @author Jeremy KUHN
 */
zwg.widgets.content.PictureViewer = function(string_album, array_pictures) {
	this._albumId = string_album;
	this._pictureContainer = document.getElementById(string_album+'Image');
	this._pictureComment = document.getElementById(string_album+'Comment');
	this._pictureTitle = document.getElementById(string_album+'Title');
	this._anchor = document.getElementById(string_album+'Anchor');
	this._selectedPictureIndex = -1;
	this._pictures = array_pictures;
	
	if(this._pictures.length > 0) {
		this.next();
	}
}

zwg.widgets.content.PictureViewer.prototype.previous = function() {
	if(this._selectedPictureIndex-1 >= 0) {
		this._selectedPictureIndex--;
	}
	else {
		this._selectedPictureIndex = this._pictures.length-1;
	}
	this._pictureContainer.src = this._pictures[this._selectedPictureIndex].url;
	this._pictureTitle.innerHTML = this._pictures[this._selectedPictureIndex].title;
	this._pictureComment.innerHTML = this._pictures[this._selectedPictureIndex].comment;
}

zwg.widgets.content.PictureViewer.prototype.next = function() {
	if(this._selectedPictureIndex+1 < this._pictures.length) {
		this._selectedPictureIndex++;
	}
	else {
		this._selectedPictureIndex = 0;
	}
	this._pictureContainer.src = this._pictures[this._selectedPictureIndex].url;
	this._pictureTitle.innerHTML = this._pictures[this._selectedPictureIndex].title;
	this._pictureComment.innerHTML = this._pictures[this._selectedPictureIndex].comment;
}

zwg.widgets.content.PictureViewer.prototype.open = function() {
	this._anchor.href = this._pictures[this._selectedPictureIndex].url;
}

