
function gallery() {
	this.time = 3; // time in seconds to show each pic
	this.playing = false;
}

gallery.prototype.layout = function() {
var ot = '';
ot += '<style>\
	.galBtn {\
	background-color:transparent;\
	position:absolute;\
	font-size:20px;\
	z-index:11;\
	cursor:pointer;\
	}\
	</style>';
ot += myBox.top('galleryWindow','white');
ot += '<img style="border: 1px solid white;" id="galleryImg" src="" border="0"/>';
ot += '<div class="galBtn" id="galleryHide" onclick="myGallery.hide()"><img src="'+om+'/img/close15.png" width="15" height="15" border="0" onmouseover="myBox.mouseOn(this)" onmouseout="myBox.mouseOff(this)"></div>';
ot += '<div class="galBtn" id="galleryPrior" onclick="myGallery.prior()"><img src="'+om+'/img/prior24.png" border="0" onmouseover="myBox.mouseOn(this)" onmouseout="myBox.mouseOff(this)"></div>';
ot += '<div class="galBtn" id="galleryNext" onclick="myGallery.next()"><img src="'+om+'/img/next24.png" border="0" onmouseover="myBox.mouseOn(this)" onmouseout="myBox.mouseOff(this)"></div>';
ot += '<div class="galBtn" id="galleryPlay" onclick="myGallery.play()"><img id="galleryPlayImg" src="'+om+'/img/play24.png" border="0" onmouseover="myBox.mouseOn(this)" onmouseout="myBox.mouseOff(this)"></div>';
ot += myBox.end('white');
ot += '\
	<div id="btnPreload" style="width:0;height:0;overflow:hidden;visibility:hidden;">\
	<img alt="" src="'+om+'/img/close15on.png" />\
	<img alt="" src="'+om+'/img/prior24on.png" />\
	<img alt="" src="'+om+'/img/next24on.png" />\
	<img alt="" src="'+om+'/img/play24on.png" />\
	<img alt="" src="'+om+'/img/stop24.png" />\
	<img alt="" src="'+om+'/img/stop24on.png" />\
	</div>\
	';
document.write(ot);
}

gallery.prototype.show = function() {
	myBox.hazeOn();
	if (!this.images) {
		this.images = document.getElementById('galleryPreload').getElementsByTagName('a');
		this.showImg = document.getElementById('galleryImg');
		this.idx = 0;
	}
	var sc = myAll.scr();
	var el = myBox.showById('galleryWindow',30,sc[1]+50);
	if (el) {
		el.placeGadget('galleryHide',20,20);
		el.placeGadget('galleryPrior',20,-25);
		el.placeGadget('galleryNext',50,-25);
		el.placeGadget('galleryPlay',80,-25);
		this.showImg.src = this.images[this.idx].href;
	}
}

gallery.prototype.hide = function() {
	myBox.hazeOff();
	this.stop();
	myBox.hideById('galleryWindow');
}

gallery.prototype.next = function() {
	this.stop();
	this.nextSub();
}

gallery.prototype.nextSub = function() {
	var max = this.images.length - 1;
	var i = this.idx + 1;
	if (i > max) i = 0;
	this.idx = i;
	this.showImg.src = this.images[i].href;
}

gallery.prototype.prior = function() {
	this.stop();
	var max = this.images.length - 1;
	var i = this.idx - 1;
	if (i < 0) i = max;
	this.idx = i;
	this.showImg.src = this.images[i].href;
}

gallery.prototype.play = function() {
	if (!this.playImg) this.playImg = document.getElementById('galleryPlayImg');
	this.playing = this.playing ? false : true;
	if (this.playing == true) {
		this.playImg.src = om+'/img/stop24.png';
		this.playImg.offSrc = om+'/img/stop24.png';
		this.playImg.onSrc = om+'/img/stop24on.png';
		this.playSub();
	}
	else this.stop();
}

gallery.prototype.playSub = function() {
	this.nextSub();
	setTimeout(galleryPlay,this.time * 1000);
}

gallery.prototype.stop = function() {
	if (!this.playImg) this.playImg = document.getElementById('galleryPlayImg');
	this.playing = false;
	this.playImg.src = om+'/img/play24.png';
	this.playImg.offSrc = om+'/img/play24.png';
	this.playImg.onSrc = om+'/img/play24on.png';
}

function galleryPlay() {if (myGallery.playing == true) myGallery.playSub();}

if (window.myAll) {
	gallery.prototype.layout();
	window.myGallery = new gallery();
	if (window.dbg) dbg.trace("sucessfully loaded lib.gallery.js");
}
