﻿var Geometry = {};

if (window.innerWidth) {
	Geometry.getViewportWidth = function() { return window.innerWidth; };
	Geometry.getViewportHeight = function() { return window.innerHeight; };
	Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
	Geometry.getVerticalScroll = function() { return window.pageYOffset; };
}
else if (document.documentElement && document.documentElement.clientWidth) {
	Geometry.getViewportWidth = function() { return document.documentElement.clientWidth; };
	Geometry.getViewportHeight = function() { return document.documentElement.clientHeight; };
	Geometry.getHorizontalScroll = function() { return document.documentElement.scrollLeft; };
	Geometry.getVerticalScroll = function() { return document.documentElement.scrollTop; };
}
else if (document.body.clientWidth) {
	Geometry.getViewportWidth = function() { return document.body.clientWidth; };
	Geometry.getViewportHeight = function() { return document.body.clientHeight; };
	Geometry.getHorizontalScroll = function() { return document.body.scrollLeft; };
	Geometry.getVerticalScroll = function() { return document.body.scrollTop; };
}


var Gallery = {};

Gallery.FullImage = function(closeText) {
	this.imagewin = document.createElement("div");
	this.imagewin.style.position = "absolute";
	this.imagewin.style.display = "none";
	this.imagewin.className = "bigimage";
	
	var d = document.createElement("div");
	d.className = "close";
	d.appendChild(document.createTextNode(closeText));
	this.imagewin.appendChild(d);
	var a = document.createElement("a");
	a.setAttribute("href","#");
	var self = this;
	a.onclick = function() { self.Hide(); return false; };
	
	this.image = document.createElement("img");
	this.image.className = "pic";
	a.appendChild(this.image);
	this.imagewin.appendChild(a);
}

Gallery.FullImage.prototype.Show = function(imgsrc, width, height) {
	if (this.imagewin.style.display == "block") {
		this.Hide();
		return;
	}
	this.image.setAttribute("src", imgsrc);
	var x = Geometry.getHorizontalScroll() + ((Geometry.getViewportWidth() - width) / 2);
	var y = Geometry.getVerticalScroll() + ((Geometry.getViewportHeight() - height) / 2);
	if (y < Geometry.getVerticalScroll()) y = Geometry.getVerticalScroll();
	if (x < Geometry.getHorizontalScroll()) x = Geometry.getHorizontalScroll();
	this.imagewin.style.top = y + "px";
	this.imagewin.style.left = x + "px";
//	this.imagewin.style.width = width + "px";
//	this.imagewin.style.height = height + "px";
	this.imagewin.style.display = "block";
	
	this.image.style.width = width + "px";
	this.image.style.height = height + "px";
	
	if (this.imagewin.parentNode != document.body) {
		document.body.appendChild(this.imagewin);
		}
}

Gallery.FullImage.prototype.Hide = function() {
	this.imagewin.style.display = "none";
}


