var tbody;
var tPicBG;
var tPicDiv;
var tPicSrc;
var tPicTitle;
var tPicAnnotac;

var arrRight;
var arrLeft;

window.onload = function(){
	tbody = document.getElementsByTagName("body")[0];
	tbody.innerHTML += 
		"<div id='tPicBG' style='display:none; z-index: 9998; 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='text-align:center; z-index: 9999; position:absolute; display:none; border:2px solid #888; padding:5px; cursor:pointer;  background-color:#FFF; '>"+
			"<a id='arrRight' style='width:100px; text-align:right; display: block; position: absolute; right: 5px; vertical-align:middle; height:600px; z-index: 996; ' href='javascript:hideTPic()'><img border='0' src='/i/right.png' /></a>"+
			"<a id='arrLeft' style='width:100px; text-align:left; display: block; position: absolute; left: 5px; z-index: 997; ' href='javascript:hideTPic()'><img border='0' src='/i/left.png' /></a>"+
			"<a style='display: block; position: absolute; right: 5px; bottom: 5px; z-index: 998;' href='javascript:hideTPic()'><img border='0' src='/i/close.jpg' style='opacity: 0.5;' /></a>"+
			"<div id='tPicTitle' style='background:transparent url(/i/bg1.gif) repeat-x scroll 0 0; color:#EDF4FA; font-size:14px; font-weight:bold; padding:5px 0 5px 8px; '></div>"+
			"<div id='tPicAnnotac' style='border-bottom:1px solid #999'></div>"+
			"<img onClick='hideTPic();' align=center id='tPicSrc' />"+
		"</div>";

		
	 tPicBG = document.getElementById("tPicBG");
	 tPicDiv = document.getElementById("tPicDiv");
	 tPicSrc = document.getElementById("tPicSrc");
	 tPicTitle = document.getElementById("tPicTitle");
	 tPicAnnotac = document.getElementById("tPicAnnotac");

	 arrRight = document.getElementById("arrRight");
	 arrLeft = document.getElementById("arrLeft");


	tPicDiv.style.top = '200px';
	tPicDiv.style.left = '300px';
}

function getNumByImg(img){
	var num = 0;
	for(i=0; i<globalGallery.length; i++){
		if(globalGallery[i].img == img) {
			num = i;
		}
	}
	return num;
}

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';
}


function showTPic(img,xx,yy, title, annotac){
	if(img != undefined) {
		tPicSrc.src = img;
		arrRight.style.height = yy+'px';
		arrLeft.style.height = yy+'px';
		arrRight.childNodes[0].style.paddingTop = (yy/2)-52+'px';
		arrLeft.childNodes[0].style.paddingTop = (yy/2)-52+'px';
		var num = getNumByImg(img);

		if(globalGallery[num-1] != undefined) {
			arrLeft.style.display = '';
			arrLeft.href = 
				'javascript:showTPic("'+
					globalGallery[num-1].img+'",'+
					globalGallery[num-1].xx+','+
					globalGallery[num-1].yy+',"'+
					globalGallery[num-1].title+'","'+
					globalGallery[num-1].annotac+'");';
		} else {
			arrLeft.style.display = '';
			arrRight.href='javascript:nope();';
		}
		
		if(globalGallery[num+1] != undefined) {
			arrRight.style.display = '';
			arrRight.href = 
				'javascript:showTPic("'+
					globalGallery[num+1].img+'",'+
					globalGallery[num+1].xx+','+
					globalGallery[num+1].yy+',"'+
					globalGallery[num+1].title+'","'+
					globalGallery[num+1].annotac+'");';
		} else {
			arrRight.style.display = '';
			arrRight.href='javascript:nope();';
		}
	}
	tPicTitle.innerHTML = title;
	tPicAnnotac.innerHTML = "<div style='padding:3px 10px;'>"+annotac+"</div>";
	winSizes(xx,yy);
	tPicDiv.style.display = '';
	tPicBG.style.display = '';
}

function nope(){
	
}

function hideTPic(){
	tPicSrc.src = "i/_.gif";
	tPicDiv.style.display = 'none';
	tPicBG.style.display = 'none';
}


function getScrollPosition () {
	var ScrollTop = document.documentElement.scrollTop ? document.documentElement.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;
}

