var BigImage = new Image;
var caption = "";
isIE=document.all;
isNN=!document.all&&document.getElementById;
isN4=document.layers;
//alert("isIE: "+ isIE +" isNN: "+ isNN +" isN4: "+ isN4);
DoIt=false;
function ddInit(e){
	TWD=isIE ? "BODY" : "HTML";
	TWD1=isIE ? document.all.BigImageLayer : document.getElementById("BigImageLayer");
	TWD2=isIE ? event.srcElement : e.target;
	while (TWD2.id!="titleBar"&&TWD2.tagName!=TWD){
		TWD2=isIE ? TWD2.parentElement : TWD2.parentNode;
	}
	if (TWD2.id=="titleBar"){
		offsetx=isIE ? event.clientX : e.clientX;
		offsety=isIE ? event.clientY : e.clientY;
		nowX=parseInt(TWD1.style.left);
		nowY=parseInt(TWD1.style.top);
		ddEnabled=true;
		document.onmousemove=dd;
	}
}

function dd(e){
	if (!ddEnabled) return;
	TWD1.style.left=isIE ? nowX+event.clientX-offsetx : nowX+e.clientX-offsetx;
	TWD1.style.top=isIE ? nowY+event.clientY-offsety : nowY+e.clientY-offsety;
	return false;
}

function ddN4(TWD3){
	if (!isN4) return;
	N4=eval(TWD3);
	N4.captureEvents(Event.MOUSEDOWN|Event.MOUSEUP);
	N4.onmousedown=function(e){
		N4.captureEvents(Event.MOUSEMOVE);
		N4x=e.x;
		N4y=e.y;
	}
	N4.onmousemove=function(e){
		if (DoIt){
			N4.moveBy(e.x-N4x,e.y-N4y);
			return false;
		}
	}
	N4.onmouseup=function(){
		N4.releaseEvents(Event.MOUSEMOVE);
	}
}

function hideMe(){
	if (isIE||isNN) TWD1.style.visibility="hidden";
	else if (isN4) document.BigImageLayer.visibility="hide";
}

function showMe(){
	if (isIE||isNN) TWD1.style.visibility="visible";
	else if (isN4) document.BigImageLayer.visibility="show";
}

document.onmousedown=ddInit;
document.onmouseup=Function("ddEnabled=false");

function PopUp(img,capt){
	BigImage = img;
	caption = capt;
	BuildLayer();
	PositionLayer();
	showMe();
}

function leafName(path){
	var l = path.length;
	for(var i=l; i>0; i--){
		if(path.charAt(i) == "/"){break;}
	}
	return path.substring(i+1);
}

function BuildLayer(){
	var BigImageName = leafName(BigImage);
	var txt = "";
	txt += '<table bgcolor="#D2B486" border="0" cellpadding="5" cellspacing="0">';
	txt += '<tbody>';
	txt += '<tr>';
	txt += '<td width="100%">';
	txt += '<table id="titleBar" style="cursor: move;" border="0" cellpadding="0" cellspacing="0" height="36" width="100%">';
	txt += '<tbody>';
	txt += '<tr>';
	txt += '<td width="100%"><font color="#6C6C6C" face="Arial"><b>Courtesy Pest Control: ' + caption + '</b></font>';
	txt += '</td>';
	//txt += '<td style="" valign="top"> <a href="#" ';
	//txt += 'onclick="hideMe();return false"><font style="text-decoration: none;"';
	//txt += 'color="#ffffff" face="arial" size="2">close</font></a> </td>';
	txt += '<td style="" valign="top"> <a href="#" ';
	txt += 'onclick="hideMe();return false">'
	txt += '<img src="images/close.gif" style="border: 0px solid ; width: 13px; height: 13px;"></a> </td>';
	txt += '</tr>';
	txt += '<tr>';
	txt += '<td style="padding: 4px; text-align: center; vertical-align: middle;" colspan="2" bgcolor="#ffffff"';
	txt += 'width="100%">';
	txt += '<img src="' + BigImage + '">';
	txt += '<br>';
	txt += '</td>';
	txt += '</tr>';
	txt += '</tbody>';
	txt += '</table>';
	txt += '</td>';
	txt += '</tr>';
	txt += '</tbody>';
	txt += '</table>';
	document.getElementById("BigImageLayer").innerHTML = txt;
}

function StayPut(){
	window.scrollBy(0,0);
}
