
var mainDiv = null;
var galleryTbl = null;
var popUpImg = null;
var imageDiv = null;
var gallery_win = null;
var boolslideshow = null;

function pop(imgLink) {
	if (!mainDiv) {
		var divs = document.getElementsByTagName('DIV');
		for (i = 0; i < divs.length; i ++) {
			if (divs[i].className == 'parentDisable') {
				mainDiv = divs[i];
				i = divs.length;
			}
		}
	}
	if (!imageDiv) {
		var divs = document.getElementsByTagName('DIV');
		for (i = 0; i < divs.length; i ++) {
			if (divs[i].className == 'image_bordered_popup') {
				imageDiv = divs[i];
				i = divs.length;
			}
		}
	}

	//set the pop Image
	var imgs = imageDiv.getElementsByTagName('IMG');
	popUpImg = imgs[0];
	popUpImg.src = imgLink;

	if (window.innerHeight) {
		//do stuff
	}
	else {
		var bodytag = document.getElementsByTagName('body')[0];
		var h = Number(bodytag.clientHeight)+50;
		var w = Number(bodytag.clientWidth);
		if (h < Number(document.documentElement.clientHeight)) h = Number(document.documentElement.clientHeight);
		if (w < Number(document.documentElement.clientWidth)) w = Number(document.documentElement.clientWidth);
		//alert(document.documentElement.clientHeight + '\n' + bodytag.clientHeight);
		mainDiv.style.height = String(h) + 'px';
		mainDiv.style.width = String(w) + 'px';
	}
	mainDiv.style.display='block';
	imageDiv.style.display='block';
	getGalleryTblLocation();
	return false;

}
function getGalleryTblLocation(){
	if (!galleryTbl) {
		var tbls = document.getElementsByTagName('TABLE');
		for (i = 0; i < tbls.length; i ++) {
			if (tbls[i].className == 'gallery_table' || tbls[i].className == 'slideshow_table') {
				galleryTbl = tbls[i];
				i = tbls.length;
			}
		}
		if (!galleryTbl) {
			var tbls = document.getElementsByTagName('DIV');
			for (i = 0; i < tbls.length; i ++) {
				if (tbls[i].className == 'gallery_table' || tbls[i].className == 'slideshow_table') {
					galleryTbl = tbls[i];
					i = tbls.length;
					boolslideshow = true;
				}
			}
		}
	}
	if (boolslideshow) {
		imageDiv.style.top = String(findPos(galleryTbl, 1)+3)+'px';
		imageDiv.style.left = String(findPos(galleryTbl, 0)+3)+'px';
	}
	else {
		imageDiv.style.top = String(findPos(galleryTbl, 1)+3)+'px';
		if (window.innerHeight) {
			left_pos = (findPos(galleryTbl, 0) + ((galleryTbl.offsetWidth - imageDiv.offsetWidth) / 2));
		}
		else {
			left_pos = (findPos(galleryTbl, 0) + ((galleryTbl.clientWidth - imageDiv.clientWidth) / 2))
		}
		imageDiv.style.left = String(left_pos)+'px';
	}

}
function findPos(obj, x_y) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	if (x_y == 0)
		return curleft;
	else
		return curtop;

}


function setResize(){
	if (mainDiv.style.display=='block'){
		if (window.innerHeight) {
			//do stuff
		}
		else {
			var bodytag = document.getElementsByTagName('body')[0];

			var h = Number(bodytag.clientHeight)+50;
			var w = Number(bodytag.clientWidth);

			if (h < Number(document.documentElement.clientHeight)) h = Number(document.documentElement.clientHeight);
			if (w < Number(document.documentElement.clientWidth)) w = Number(document.documentElement.clientWidth);

			mainDiv.style.height = String(h) + 'px';
			mainDiv.style.width = String(w) + 'px';
		}
		getGalleryTblLocation();
	}
}

function hide() {
	mainDiv.style.display='none';
	imageDiv.style.display='none';
	return false;
}

function mgal_pop(urlLink, w, h) {
	if (gallery_win) gallery_win.close();
	gallery_win = window.open(urlLink, 'galleryPop', 'menubar=no,width='+w+',height='+h+',toolbar=no,location=no');
	gallery_win.focus();
	return false;
}
