
var floatingBg = false;
var closeBg = false;
var floatingBlock = false;
var floatingFrame = false;

var is_msie = (navigator.userAgent.indexOf('MSIE')>=0 && navigator.userAgent.indexOf('opera')==-1 && document.all)?true:false;

function showFloatingPix(e, file, fs) {
	stopSlideShow();
	setBackground();
	var wh = fs.split("|");
	var winSize = getWinSize();
	var bodyWidth = winSize[0];
	var bodyHeight = winSize[1];
	var mediaPath = "";
	if (!floatingBlock)
		floatingBlock = document.createElement('DIV');
	floatingBlock.id = 'floatingBlock';
	document.body.appendChild(floatingBlock);
	
	floatingBlock.style.width = null;
	floatingBlock.innerHTML = "<a href=\"#\" onclick=\"hideFloatingPix(); return false;\" title=\"click to close\" alt=\"click to close\"><img src=\""+file+"\"></a>";
	
	floatingBlock.style.position = 'absolute';
	if(is_msie){
		if (!floatingFrame)
			floatingFrame = document.createElement('IFRAME');
		floatingFrame.frameborder='0';
		floatingFrame.style.backgroundColor='#666666';
		floatingFrame.style.filter = "progid:DxImageTransform.Microsoft.Alpha(Opacity = 90)";
		floatingFrame.src = '#'; 	
		floatingFrame.style.zIndex = 1000;
		floatingFrame.style.position = 'absolute';
		document.body.appendChild(floatingFrame);
	}
		
	var sp = getScrollXY();
	var sl = sp[0];
	var st = sp[1];
	
	var blockWidth = wh[0];
	var blockHeight = wh[1];
	
	var lp = (bodyWidth - blockWidth)/2 + sl;
	var tp = (bodyHeight - blockHeight)/2 + st;
	
	floatingBlock.style.left = lp + 'px';
	floatingBlock.style.top = tp + 'px';
	floatingBlock.style.width = blockWidth + 'px';
	floatingBlock.style.height = blockHeight + 'px';
	if(is_msie){
		floatingFrame.style.left = floatingBlock.style.left;
		floatingFrame.style.top = floatingBlock.style.top;
		floatingFrame.style.width = floatingBlock.offsetWidth + 'px';
		floatingFrame.style.height = floatingBlock.offsetHeight + 'px';
	}
	
	floatingBlock.style.display='block';
	floatingBlock.style.zIndex = 1001;
	if(is_msie)
		floatingFrame.style.display='block';
}

function hideFloatingPix() {
	if (floatingBlock)
		document.body.removeChild(floatingBlock);
	if (floatingFrame)
		document.body.removeChild(floatingFrame);
	if (floatingBg)
		document.body.removeChild(floatingBg);
}

function setBackground() {
	if (!floatingBg)
		floatingBg = document.createElement('DIV');
	floatingBg.id = 'floatingBg';
	document.body.appendChild(floatingBg);
	floatingBg.style.position = 'absolute';
	
	var sp = getScrollXY();
	var sl = sp[0];
	var st = sp[1];
	
	floatingBg.style.left = sl + 'px';
	floatingBg.style.top = 0 + 'px';
	
	var winSize = getWinSize();
	var bodyWidth = winSize[0];
	var bodyHeight = winSize[1];
	
	var docHeight = bodyHeight + st;
	floatingBg.style.width = bodyWidth + 'px';
	floatingBg.style.height = docHeight + 'px';
	
	floatingBg.style.backgroundColor = "#666666";
	floatingBg.style.MozOpacity = 0.9;
	if (is_msie)
		floatingBg.style.filter = "progid:DxImageTransform.Microsoft.Alpha(Opacity = 90)";
	
	floatingBg.style.display='block';
	floatingBg.style.zIndex = 999;
	var btn_close = "/pandacms.v2/templates/artgallery/images/btn_close.gif"
	if (!closeBg)
		closeBg = document.createElement('div');
	closeBg.id = "closeBg";
	floatingBg.appendChild(closeBg);
	closeBg.style.position = "absolute";
	var btn_top = st + 5;
	closeBg.style.top = btn_top + "px";
	closeBg.style.right = 5 + "px";
	closeBg.style.width = 14 + "px";
	closeBg.style.height = 14 + "px";
	closeBg.innerHTML = "<a href=\"#\" onclick=\"hideFloatingPix(); return false;\"><img src=\""+btn_close+"\"></a>";
	closeBg.style.display = "block";
}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

function getWinSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth -20;
    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;
  }
  return [ myWidth, myHeight ];
}

