d = document;
w = window;

//Detect Viewport Dimensions

	function detectSize(which){
		w = 0;
		h = 0;

		if (typeof(w.innerWidth) == 'number'){ //Non-IE
			w = w.innerWidth;
			h = w.innerHeight;
		} else if (d.documentElement && (d.documentElement.clientWidth || d.documentElement.clientHeight)){ //IE6+ in 'standards compliant mode'
			w = d.documentElement.clientWidth;
			h = d.documentElement.clientHeight;
		} else if (d.body && (d.body.clientWidth || d.body.clientHeight)){ //IE4
			w = d.body.clientWidth;
			h = d.body.clientHeight;
		}

		if (which == 'w') return w;
		else if (which == 'h') return h;
	}

//Detect Scroll Distance

	function detectScroll(which){
		h = 0;
		v = 0;

		if (typeof(w.pageYOffset) == 'number'){ //Netscape
			h = w.pageXOffset;
			v = w.pageYOffset;
		} else if (d.body && (d.body.scrollLeft || d.body.scrollTop)){ //DOM compliant
			h = d.body.scrollLeft;
			v = d.body.scrollTop;
		} else if (d.documentElement && (d.documentElement.scrollLeft || d.documentElement.scrollTop)){ //IE6+ in 'standards compliant mode'
			h = d.documentElement.scrollLeft;
			v = d.documentElement.scrollTop;
		}

		if (which == 'h') return h;
		else if (which == 'v') return v;
	}

//In-Page Pop

	function makePop(w, h, nm, scr, src){
		if ((w + 24) > detectSize('w')) w = (detectSize('w') - 24);
		if ((h + 24 + 27) > detectSize('h')) h = (detectSize('h') - 24 - 27);

		clearPop();
		p = d.getElementById('pop');

		buildHTML = '<div style="float:left;width:12px;height:12px;background-image:url(\'/admin/images/popshadow_toplt.png\');background-repeat:no-repeat;"></div>';
		buildHTML += '<div style="float:left;width:' + w + 'px;height:12px;background-image:url(\'/admin/images/popshadow_top.png\');background-repeat:repeat-x;"></div>';
		buildHTML += '<div style="float:left;width:12px;height:12px;background-image:url(\'/admin/images/popshadow_toprt.png\');background-repeat:no-repeat;"></div>';
		buildHTML += '<div style="clear:both;"></div>';
		buildHTML += '<div style="float:left;width:12px;height:' + (h + 27) + 'px;background-image:url(\'/admin/images/popshadow_lt.png\');background-repeat:repeat-y;"></div>';
		buildHTML += '<div style="float:left;background-color:#ffffff;width:' + w + 'px;height:' + (h + 27) + 'px;"><div style="height:22px;margin-top:5px;margin-right:5px;text-align:right;"><a href="#" onclick="popPosition=window.clearInterval(popPosition);d.getElementById(\'pop\').style.display=\'none\';d.getElementById(\'lightbox\').style.display=\'none\';return false;" style="#ff0000;"/>Close</a></div><iframe frameborder="0" height="' + h + '" hspace="0" marginheight="0" marginwidth="0" name="' + nm + '" scrolling="' + scr + '" src="' + src + '" vspace="0" width="' + w + '"></iframe></div>';
		buildHTML += '<div style="float:left;width:12px;height:' + (h + 27) + 'px;background-image:url(\'/admin/images/popshadow_rt.png\');background-repeat:repeat-y;"></div>';
		buildHTML += '<div style="clear:both;"></div>';
		buildHTML += '<div style="float:left;width:12px;height:12px;background-image:url(\'/admin/images/popshadow_botlt.png\');background-repeat:no-repeat;"></div>';
		buildHTML += '<div style="float:left;width:' + w + 'px;height:12px;background-image:url(\'/admin/images/popshadow_bot.png\');background-repeat:repeat-x;"></div>';
		buildHTML += '<div style="float:left;width:12px;height:12px;background-image:url(\'/admin/images/popshadow_botrt.png\');background-repeat:no-repeat;"></div>';
		buildHTML += '<div style="clear:both;"></div>';
		p.innerHTML = buildHTML;

		p.style.width = (w + 24) + 'px';
		p.style.height = (h + 24 + 27) + 'px'; //24 for outer shadow, 27 for close btn
		popPosition = self.setInterval('positionPop(' + w + ', ' + h + ')', 1);

		p.style.display = 'block';
		d.getElementById('lightbox').style.display = 'block';
	}

	function clearPop(){
		p = d.getElementById('pop');
		p.innerHTML = '';
	}

	function positionPop(w, h){
		p = d.getElementById('pop');

		topVar = Math.round((detectSize('h') / 2) - (h / 2) + detectScroll('v') - ((24 + 27) / 2));
		if (topVar < 0) topVar = 0;
		p.style.top = topVar + 'px';

		leftVar = Math.round((detectSize('w') / 2) - (w / 2) + detectScroll('h') - (24 / 2));
		if (leftVar < 0) leftVar = 0;
		p.style.left = leftVar + 'px';

		d.getElementById('lightbox').style.top = detectScroll('v') + 'px';
	}
