var aPopupImages=[],iPopupImageIndex=-1
function iniPopup(name,oJqueryObject,aImages){aPopupImages[name]=aImages;if(!jQuery('#popup').length)jQuery('<div id="popup"></div>').appendTo('body');if(!jQuery('#backgroundPopup').length)jQuery('<div id="backgroundPopup"></div>').prependTo('body');oJqueryObject.click(function(){clickToPopup(this,name)});jQuery("#popup").click(disablePopup);jQuery(document).keypress(function(e){if(e.keyCode==27&&jQuery('#popup').length&&jQuery('#popup').css('display')!='none')disablePopup()})};var sPopupName,iWinWidth=$(window).width(),iWinHeight=$(window).height(),iDivWidth=iWinWidth-80,iDivHeight=iWinHeight-80
function clickToPopup(ob,name){sPopupName=name;iPopupImageIndex=-1;if(jQuery('#popup').length&&jQuery('#popup').css('display')=='none'){id=jQuery(ob).attr('id');id_parts=jQuery(ob).attr('id').split('_');iPopupImageIndex=!id_parts.length||parseInt(id_parts[1])!=id_parts[1]?0:id_parts[1];jQuery('#popup img').remove();var iDivWidth=iWinWidth-40;jQuery('#popup').append('<img src="'+aPopupImages[name][iPopupImageIndex][0]+'" width=10" height="10" border="0" alt="" />');scale(aPopupImages[sPopupName][iPopupImageIndex][1],aPopupImages[sPopupName][iPopupImageIndex][2])};loadPopup()}
function scale(width,height){var iOrigWidth=width,iOrigHeight=height;fRatioWidth=1;fRatioHeight=1;iMaxWidth=iDivWidth-20;iMaxHeight=iDivHeight-20;if(iOrigWidth>iMaxWidth)fRatioWidth=(iMaxWidth/iOrigWidth);if(iOrigHeight>iMaxHeight)fRatioHeight=(iMaxHeight/iOrigHeight);if(fRatioWidth>fRatioHeight){fRatio=fRatioHeight}else fRatio=fRatioWidth;iWidth=iOrigWidth*fRatio;iHeight=iOrigHeight*fRatio;jQuery("#popup div").css({width:iDivWidth,height:iDivHeight});jQuery("#popup img").css({width:iWidth,height:iHeight})}
function loadPopup(){if(jQuery('#popup').length&&jQuery('#popup').css('display')!='none')return;centerPopup();jQuery("#backgroundPopup").css({opacity:"0.7"});jQuery("#backgroundPopup").fadeIn("fast");jQuery("#popup").fadeIn("fast");if(iPopupImageIndex!=-1)jQuery('body').append('<img src="/site/std/img/iconClose.png" id="icon_close" width="60" height="60" border="0" alt="" style="behavior:url(/site/std/css/iepngfix.htc); z-index: 200; cursor: pointer" onclick="disablePopup()" />').fadeIn("slow",centerClose)}
function centerPopup(){var windowWidth=$(window).width(),windowHeight=$(window).height(),popupWidth=jQuery("#popup").width(),popupHeight=jQuery("#popup").height();jQuery("#popup").css({position:"absolute",top:$(window).scrollTop(),left:windowWidth/2-popupWidth/2});jQuery("#backgroundPopup").css({height:windowHeight})}
function disablePopup(){if(!jQuery('#popup').length||jQuery('#popup').css('display')=='none')return;jQuery("#backgroundPopup").fadeOut("slow");jQuery("#popup").fadeOut("slow");jQuery("#icon_close, #icon_prev, #icon_next").remove()}
function centerClose(){var windowWidth=$(window).width(),iconWidth=jQuery("#icon_close").width(),iImgWidth=jQuery("#popup").width();jQuery("#icon_close").css({position:"absolute",top:$(window).scrollTop(),left:windowWidth/2-iconWidth+(iImgWidth/2)+5})}
function centerPrev(){var windowWidth=document.documentElement.clientWidth,windowHeight=document.documentElement.clientHeight,iconHeight=jQuery("#icon_prev").height(),iconPrevWidth=jQuery("#icon_prev").width(),popupWidth=jQuery("#popup").width(),popupHeight=jQuery("#popup").height();jQuery("#icon_prev").css({position:"absolute",top:windowHeight/2-iconHeight/2+$(window).scrollTop()+(popupHeight/2),left:(windowWidth/2-popupWidth/2)})}
function centerNext(){var windowHeight=document.documentElement.clientHeight,popupHeight=jQuery("#icon_next").height();jQuery("#icon_next").css({position:"absolute",top:windowHeight/2-popupHeight/2+$(window).scrollTop(),right:10})}
function prevImage(){if(iPopupImageIndex<=0)return;iPopupImageIndex--;jQuery('#popup img').fadeOut("slow",function(){jQuery(this).remove();jQuery('#popup').append('<img src="'+aPopupImages[sPopupName][iPopupImageIndex][0]+'" width="10" height="10" border="0" alt="" />');scale(aPopupImages[sPopupName][iPopupImageIndex][1],aPopupImages[sPopupName][iPopupImageIndex][2]);if(iPopupImageIndex==0)jQuery('#icon_prev').remove();if(iPopupImageIndex==aPopupImages[sPopupName].length-2)jQuery('body').append('<img src="/site/std/img/iconRight.png" id="icon_next" width="60" height="60" border="0" alt="" style="behavior:url(/site/std/css/iepngfix.htc); z-index: 100; cursor: pointer" onclick="nextImage()" />').fadeIn("slow",centerNext);centerPopup()})}
function nextImage(){if(iPopupImageIndex>=aPopupImages[sPopupName].length-1)return;iPopupImageIndex++;jQuery('#popup img').fadeOut("slow",function(){jQuery(this).remove();jQuery('#popup').append('<img src="'+aPopupImages[sPopupName][iPopupImageIndex][0]+'" width="10" height="10" border="0" alt="" />');scale(aPopupImages[sPopupName][iPopupImageIndex][1],aPopupImages[sPopupName][iPopupImageIndex][2]);if(iPopupImageIndex==1)jQuery('body').append('<img src="/site/std/img/iconLeft.png" id="icon_prev" width="60" height="60" border="0" alt="" style="behavior:url(/site/std/css/iepngfix.htc); z-index: 100; cursor: pointer" onclick="prevImage()" />').fadeIn("slow",centerPrev);if(iPopupImageIndex==aPopupImages[sPopupName].length-1)jQuery('#icon_next').remove();centerPopup()})}
