var tbody = null;
var tPicBG = null;
var tPicDiv = null;
var tPicSrc = null;
var closeImg = true;

var leftImg = null;
var rightImg = null;
var leftImg_ = null;
var rightImg_ = null;

window.onload = function() {
	tbody = document.getElementsByTagName("body")[0];
	
	var left_ = "<a href='#' style=' z-index: 9999; position: absolute; left: 1px; height: 100%; min-height: 100%; width:60px; text-align:left;' id='lightboxLeft'  onclick='closeImg = false; showTPic(leftImg,800,600); return false;'><img align='absmiddle' src='/i/lightbox/left.png' style='padding-top: 150px;' id='lightboxLeftImg' /></a>";

	var right_ = "<a href='#' style=' z-index: 9998; position: absolute; right: 1px; height: 100%; min-height: 100%; width:60px; text-align:right; ' id='lightboxRight'  onclick='closeImg = false; showTPic(rightImg,800,600); return false;'><img align='absmiddle' src='/i/lightbox/right.png' style='padding-top: 150px;' id='lightboxRightImg'/></a>";
	
	tbody.innerHTML += "<div id='tPicBG' style='display:none; z-index: 996; position:absolute; top:0px; left:0px; width:100%; filter:alpha(opacity=75);-moz-opacity:.75;opacity:.75; background-color:#FFF'>&nbsp;</div><div id='tPicDiv' style='z-index: 997; position:absolute; display:none; border:2px solid #888; padding:5px; cursor:pointer;  background-color:#FFF; '>"+left_+"<img onClick='hideTPic();' id='tPicSrc' />"+right_+"</div>";
	
	tPicBG = document.getElementById("tPicBG");
	tPicDiv = document.getElementById("tPicDiv");
	tPicSrc = document.getElementById("tPicSrc");
	leftImg_ = document.getElementById("lightboxLeft");
	rightImg_ = document.getElementById("lightboxRight");
	tPicDiv.style.top = '200px';
	tPicDiv.style.left = '300px';


}



	function winSizes(xxx,yyy) {
	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;
	}
	
		if(xxx == undefined || xxx==0) {xxx = (Math.round(myWidth/2) - 400);} 
		else { xxx = (Math.round(myWidth/2) - Math.round(xxx/2)); }
		if(yyy == undefined || yyy==0) {yyy = (Math.round(myHeight/2) - 300) + getScrollPosition();}
		else { yyy = (Math.round(myHeight/2) - Math.round(yyy/2)) + getScrollPosition(); }
	
	
	tPicBG.style.height = document.getElementById("wrapper").clientHeight + 'px';
	tPicDiv.style.left = xxx + 'px';
	tPicDiv.style.top = yyy +'px';
	}
	
	//oldImg, img
	function showTPic(img,xx,yy){
		
		try{
			if(globalGalleriesList != undefined) {	
				var oldImg = "";
				var lb = document.getElementById("lightboxLeft");
				var rb = document.getElementById("lightboxRight");
	
				for (var i=0; i<globalGalleriesList.length;i++) {
					if(img == globalGalleriesList[i]) {
						var xy = globalSizesList[i].split(",");
						xx = xy[0];
						yy = xy[1];
						if( oldImg != "" ) { leftImg = oldImg } else { leftImg = null; }
						if( globalGalleriesList[i+1] != undefined) { rightImg = globalGalleriesList[i+1]; } else { rightImg = null;}
						/*lb.attachEvent = function() {
							showTPic(oldImg,800,600);
						}
						
						if( globalGalleriesList[i+1] != undefined) rb.attachEvent("onclick", showTPic(globalGalleriesList[i+1],800,600) );
						*/
					}
					oldImg = globalGalleriesList[i];
				}
	
			}
		} catch (e) {
		
		}
	
		if(img != undefined) {
			tPicSrc.src = img;
		}
		winSizes(xx, yy);
		
		tPicDiv.style.display = '';
		tPicBG.style.display = '';
		if(leftImg!=null) { leftImg_.style.visibility = ''; } else { leftImg_.style.visibility = 'hidden'; }
		if(rightImg!=null) { rightImg_.style.visibility = ''; } else { rightImg_.style.visibility = 'hidden'; }
		//closeImg = true;
	}
	
	function hideTPic(){
		tPicSrc.src = "i/_.gif";
		tPicDiv.style.display = 'none';
		tPicBG.style.display = 'none';
	}
	
	
	function getScrollPosition () {
		var ScrollTop = document.body.scrollTop;
		if (ScrollTop == 0) {
			if (window.pageYOffset)
				ScrollTop = window.pageYOffset;
			else
				ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
		}
		return ScrollTop;
	}
