//###################################
// This gallery is powered by jooorooo / http://gnachev.net	#
// For contacts with me, find me on http://web-tourist.net	#
// with nick name jooorooo						#
//###################################
var Gallery = new Object();

Gallery = function (url,w,h) {
	Page.getPageCenterX();
    if(w > Page.width && h < Page.height) {
    var nw = Math.ceil(w/Page.width);
    we = Math.ceil(w/nw);
    he = Math.ceil(h/nw);
    }
    else if(h > Page.height && w < Page.width) {
    var nw = Math.ceil(h/Page.height);
    we = Math.ceil(w/nw);
    he = Math.ceil(h/nw);
    }
    else if(w > Page.width && h> Page.height) {
    var nw = Math.ceil(w/Page.width);
    if(Math.ceil(h/nw) > Page.height) {
    we = Math.ceil(w/Math.ceil(h/Page.height));
    he = Math.ceil(h/Math.ceil(h/Page.height));
    }
    else if(Math.ceil(w/nw) > Page.width) {
    we = Math.ceil(w/nw);
    he = Math.ceil(h/nw);
    }
    else {
    we = Math.ceil(w/nw);
    he = Math.ceil(h/nw);
    }
    }
    else {
    we = w;
    he = h;
    }
	var X = Math.ceil((Page.width-we)/2);
	var Y = Math.ceil((Page.height-he)/2);
	var gall = document.getElementById('gall');
	var gall2 = document.getElementById('gall2');
	gall.style.display = "block";
	gall2.style.display = "block";
	gall2.style.marginTop = Y+'px';
	gall2.style.marginLeft = X+'px';
	gall2.style.width = we; 
	gall2.style.height = he;
	gall2.innerHTML = '<img width="'+we+'" height="'+he+'" title="Click on image to close" alt="Click on image to close" onclick="Hide()" style="cursor: pointer;" src="'+url+'">';  
}

var Hide = new Object();

Hide = function () {
	var gall = document.getElementById('gall');
	var gall2 = document.getElementById('gall2');
	gall.style.display = "none";
	gall2.style.display = "none";
}

var Page = new Object();
Page.width;
Page.height;
Page.top;

Page.getPageCenterX = function () {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
	Page.width = myWidth;
	Page.height = myHeight;
	Page.top = window.document.body.scrollTop;
}
