﻿Type.registerNamespace("Explorica");

Explorica.PhotoGallery = function() {
	Explorica.PhotoGallery.initializeBase(this);
	this._pics = [];
	this._gal = null;
	this._arrows = [];
	this._index = 0;
	this._max = 0;
	this._h = 0;
	this._w = 0;
	this._bc = "";
}

Explorica.PhotoGallery.prototype = {
	initialize: function() {
		Explorica.PhotoGallery.callBaseMethod(this, "initialize");
	},
	dispose: function() {
		for (var i = 0; i < this._arrows; i++) $clearHandlers(this._arrows[i]);
		Explorica.PhotoGallery.callBaseMethod(this, "dispose");
	},
	_determineArrows: function() {
		if (this._atLow()) { this._arrows[0].style.display = "none"; this._arrows[1].style.display = ""; }
		else { this._arrows[0].style.display = ""; this._arrows[1].style.display = "none"; }
		if (this._atHigh()) { this._arrows[2].style.display = "none"; this._arrows[3].style.display = ""; }
		else { this._arrows[2].style.display = ""; this._arrows[3].style.display = "none"; }
	},
	_determinePictures: function() {
		var html = "";
		for (var i = this._index; i < (this._index + this._max) && i < this._pics.length; i++) {
			html += String.format("<div><div><a onclick=\"viewImage('/Handlers/ExploricaMedia.ashx?id={0}', '{0}')\" href=\"javascript:void(0)\"><img src=\"/Handlers/ExploricaMedia.ashx?id={0}&h={1}&w={2}&bc={3}\" onmouseover=\"imgOnMouseOver(this)\" onmouseout=\"imgOnMouseOut(this)\" alt=\"{4}\" title=\"{4}\" border=\"0\" /></a></div><div id =\"{0}\" class=\"caption clr\">{4}</div></div>",
				this._pics[i].key, this._h, this._w, this._bc, this._pics[i].alt);
		}
		this._gal.innerHTML = html;
	},
	_onClickPrev: function() {
		this._index--;
		this._determinePictures();
		this._determineArrows();
	},
	_onClickNext: function() {
		this._index++;
		this._determinePictures();
		this._determineArrows();
	},
	_atLow: function() { return this._index == 0; },
	_atHigh: function() { return (this._index + this._max) >= this._pics.length; },
	setPhotos: function(ar) { this._pics = ar; },
	setGallery: function(g) { this._gal = g; },
	setArrows: function(left, leftdis, right, rightdis) {
		$addHandler(left, "click", Function.createDelegate(this, this._onClickPrev));
		$addHandler(right, "click", Function.createDelegate(this, this._onClickNext));
		this._arrows = [left, leftdis, right, rightdis];
		this._determineArrows();
	},
	set_photoHeight: function(h) { this._h = h; },
	set_photoWidth: function(w) { this._w = w; },
	set_photoBgColor: function(c) { this._bc = c; },
	set_maxPhotoCount: function(m) { this._max = m; },
	get_photoHeight: function() { return this._h; },
	get_photoWidth: function() { return this._w; },
	get_photoBgColor: function() { return this._bc; },
	get_maxPhotoCount: function() { return this._max; }
}

Explorica.PhotoGallery.registerClass("Explorica.PhotoGallery", Sys.Component);

if (typeof (Sys) !== "undefined") Sys.Application.notifyScriptLoaded();
