var FIXED_WIDTH=800;
var FIXED_HEIGHT=600;
var pzBrowserWidth=0;
var pzBrowserHeight=0;
var pzDragging=false;
var pzStartX=0;
var pzStartY=0;
var pzStartScrollX=0;
var pzStartScrollY=0;
var pzMskVar=document.getElementById('pzMsk');
var pzPnlVar=document.getElementById('pzPnl');
var pzPnlBdVar=document.getElementById('pzPnlBd');
var pzImgVar=document.getElementById('pzImg');
var pzImgBVar=document.getElementById('pzImgB');
var pzRecVar=document.getElementById('pzRec');
var pzZoomIn=document.getElementById('pzZoomIn');
var pzZoomOut=document.getElementById('pzZoomOut');
function centerModal(obj){
	var currW=obj.clientWidth;
	var currH=obj.clientHeight;
	obj.style.top="50%";
	obj.style.marginTop=-((currH/2) - 10)+'px';
	obj.style.left="50%";
	obj.style.marginLeft=-(currW/2)+'px';
}

function openPZModalFull(cacheDomain,newImg) {
	var imgSrc = cacheDomain+newImg;
	pzMskVar.style.display='block';
	pzPnlVar.style.display='block';
	(/MSIE/.test(navigator.userAgent))?pzImgVar.style.display='block':pzImgVar.style.display='inline-block';
	pzRecVar.style.display='block';
	pzZoomOut.style.display='block';
	pzZoomIn.style.display='none';
	setImgSrc(imgSrc);
	pzRecVar.style.background="url(\""+imgSrc+"\") no-repeat";
	checkpzImgBVarSize();
}

function openPZModal(cacheDomain,newImg){
	var imgSrc = cacheDomain+"/affiliate/ceg/collection/"+newImg;
	pzMskVar.style.display='block';
	pzPnlVar.style.display='block';
	(/MSIE/.test(navigator.userAgent))?pzImgVar.style.display='block':pzImgVar.style.display='inline-block';
	pzRecVar.style.display='block';
	pzZoomOut.style.display='block';
	pzZoomIn.style.display='none';
	setImgSrc(imgSrc);
	pzRecVar.style.background="url(\""+imgSrc+"\") no-repeat";
	checkpzImgBVarSize();	
}
function checkpzImgBVarSize(){
	(pzImgBVar.clientWidth==0||pzImgBVar.clientHeight==0)?setTimeout(finishOpening,500):finishOpening();
}

function SetSizes() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    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;
  } else {
	myWidth = FIXED_WIDTH;
	myHeight = FIXED_HEIGHT;
  }
  pzBrowserWidth = myWidth;
  pzBrowserHeight = myHeight;
}

function finishOpening(){
	var bodyHeight, bodyWidth, recHeight, recWidth, imgHeight, imgWidth;
	
	SetSizes();
	
	recWidth = pzBrowserWidth;
	recHeight = pzBrowserHeight;
	
	imgWidth = (pzBrowserWidth > FIXED_WIDTH ? FIXED_WIDTH : pzBrowserWidth);
	imgHeight = (pzBrowserHeight > FIXED_HEIGHT ? FIXED_HEIGHT : pzBrowserHeight);

	pzPnlVar.style.width=imgWidth+"px";
	pzPnlVar.style.height=imgHeight+"px";
	pzPnlBdVar.style.width=imgWidth+"px";
	pzPnlBdVar.style.height=(imgHeight-65)+"px";
	pzRecVar.style.width=recWidth+"px";
	pzRecVar.style.height="auto";	
	
	pzImgVar.style.height='auto';
	pzImgVar.style.width='auto';
	pzImgVar.style.maxHeight='525px';
	pzImgVar.style.maxWidth='725px';
	
	pzRecVar.style.display='none';
	centerModal(pzPnlVar);
}
function setImgSrc(newImg){
	pzImgVar.src=newImg;
	pzImgBVar.src=newImg;
}
function closePZModal(){
	pzZoomIn.style.display='none';
	pzZoomOut.style.display='block';
	pzMskVar.style.display='none';
	pzPnlVar.style.display='none';
	/*if (!/MSIE/.test(navigator.userAgent)){pzImgVar.src="";pzImgBVar.src="";}*/
}
function zoomOutPZModal(){
	pzZoomOut.style.display='block';
	pzZoomIn.style.display='none';
	(/MSIE/.test(navigator.userAgent))?pzImgVar.style.display='block':pzImgVar.style.display='inline-block';
	pzRecVar.style.display='none';
	pzRecVar.style.height='100%';
	pzRecVar.style.width="auto";
}
function zoomInPZModal(){
	pzImgVar.style.display='none';
	pzRecVar.style.display='inline-block';
	pzZoomOut.style.display='none';
	pzZoomIn.style.display='block';
	pzRecVar.style.cursor="pointer";
	if(navigator.userAgent.toLowerCase().indexOf('firefox')!=-1){pzRecVar.style.cursor="-moz-grab";}
	pzRecVar.style.width="auto";
	pzRecVar.style.height="auto";
}
function scrollPZRight(){
	pzPnlBdVar.scrollLeft=pzPnlBdVar.scrollLeft+20;
}
function scrollPZLeft(){
	pzPnlBdVar.scrollLeft=pzPnlBdVar.scrollLeft-20;
}
function scrollPZUp(){
	pzPnlBdVar.scrollTop=pzPnlBdVar.scrollTop-20;
}
function scrollPZDown(){
	pzPnlBdVar.scrollTop=pzPnlBdVar.scrollTop+20;
}
function startPZDrag(e){
	pzDragging=true;
	if(!e){e=window.event;}
	pzStartX=e.clientX;
	pzStartY=e.clientY;
	pzStartScrollX=pzPnlBdVar.scrollLeft;
	pzStartScrollY=pzPnlBdVar.scrollTop;
	pzRecVar.style.cursor="move";
	if(navigator.userAgent.toLowerCase().indexOf('firefox')!=-1){pzRecVar.style.cursor="-moz-grabbing";}
}
function pzDrag(e){
	if(!pzDragging){return;}
	if(!e){e=window.event;}
	var currX=e.clientX,currY=e.clientY;
	pzPnlBdVar.scrollLeft=pzStartScrollX-(currX-pzStartX);
	pzPnlBdVar.scrollTop=pzStartScrollY-(currY-pzStartY);
}
function stopPZDrag(){
	pzDragging=false;
	pzRecVar.style.cursor="pointer";
	if(navigator.userAgent.toLowerCase().indexOf('firefox')!=-1){pzRecVar.style.cursor="-moz-grab";}
}