function getQueryVariable(variable, sURL) {
	  var query = sURL;
	  var CutOffPos = sURL.indexOf("?");
	  var QueryString = query.substring(CutOffPos+1, sURL.length)
	  var vars = QueryString.split("&");
	  for (var i=0;i<vars.length;i++) {
	    var pair = vars[i].split("=");
	    if (pair[0] == variable) {
	      return pair[1];
	    }
	  } 
	  alert('Query Variable ' + variable + ' not found');
	}
	
	function OpenWin(sURL,sWidth,sHeight) {
		if (getQueryVariable("popup", sURL) == "true"){
			window.open(sURL,'','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width='+ sWidth +',height='+ sHeight +'');
			}
		else{
			window.location = sURL
			}
		}

	function findPos(obj) {
		var curleft = curtop = 0;
		if (obj.offsetParent) {
			curleft = obj.offsetLeft
			curtop = obj.offsetTop
			while (obj = obj.offsetParent) {
				curleft += obj.offsetLeft
				curtop += obj.offsetTop
			}
		}
		return [curleft,curtop];
	}
	
	function positionControls(ctrls, img, width, ctrlHeight, isNew) {
		var pos = findPos(img);
		var iAdjust = 0
		var iHeight = 0

		if (isNew == 1) {
			ctrls.style.left = 0
			if (width == 379) ctrls.style.top = 260
			if (width == 520) ctrls.style.top = 450
		} else {
			if (width == 379) iAdjust = 0
			var iLeft = (parseFloat(pos[0]) + iAdjust)
			var iTop = pos[1] + (img.height - ctrlHeight)
			ctrls.style.left = iLeft + 'px';
			ctrls.style.top = iTop + 'px';
			
			// on some sites the controls slide somewhere for no reason
			// catch them and put them back!!!
			var ctrlpos = findPos(ctrls)
			
			if (ctrlpos[0] != iLeft) {
				var iAdjustLeft = ctrlpos[0] - iLeft
				ctrls.style.left = iLeft - iAdjustLeft - iAdjust + 'px';
			}
			
			if (ctrlpos[1] != iTop) {
				var iAdjustTop = ctrlpos[1] - iTop
				ctrls.style.top = iTop - iAdjustTop + 'px';
			}
		}
		
		ctrls.style.width = width + 'px';
	}
	
					