﻿var etailPicturePluseBrowser='msie';
var W=navigator.userAgent.toLowerCase();
if(W.indexOf("opera")!=-1)
{
  etailPicturePluseBrowser='opera';
}
else if(W.indexOf("msie")!=-1)
{
   etailPicturePluseBrowser='msie';
}
else if(W.indexOf("safari")!=-1)
{
   etailPicturePluseBrowser='safari';
}
else if(W.indexOf("mozilla")!=-1)
{
  etailPicturePluseBrowser='gecko';
}
var etailPictureZooming=new Array();
function _el(id)
{
 return document.getElementById(id);
};
function etailPicturePluseStyle(el,styleProp)
{
  if(el.currentStyle)
  {
    var y=el.currentStyle[styleProp];
    y=parseInt(y)?y:'0px';
  }
  else if(window.getComputedStyle)
  {
    var css=document.defaultView.getComputedStyle(el,null);
    var y=css?css[styleProp]:null;
   }
    return y;
}
 
  function etailPicturePluseBind(e)
  {
    if(e.getBoundingClientRect)
    {
        var r=e.getBoundingClientRect();
        var wx=0;
        var wy=0;
        if(document.body&&(document.body.scrollLeft||document.body.scrollTop))
        {
            wy=document.body.scrollTop;
            wx=document.body.scrollLeft
        }
        else if(document.documentElement&&(document.documentElement.scrollLeft||document.documentElement.scrollTop))      
        {
            wy=document.documentElement.scrollTop;
            wx=document.documentElement.scrollLeft;
        }
        return{'left':r.left+wx,'top':r.top+wy,'right':r.right+wx,'bottom':r.bottom+wy};
     }
   }
   function etailPicturePluseBindEvent(e)
    {
         var x=0;var y=0;
         if(etailPicturePluseBrowser == 'msie')
         {
            y=e.clientY;x=e.clientX;
            if(document.body&&(document.body.scrollLeft||document.body.scrollTop))
            {
              y=e.clientY+document.body.scrollTop;
              x=e.clientX+document.body.scrollLeft
            }
            else if(document.documentElement&&(document.documentElement.scrollLeft||document.documentElement.scrollTop))
            {
             y=e.clientY+document.documentElement.scrollTop;
             x=e.clientX+document.documentElement.scrollLeft}
            }
            else
            {
                y=e.clientY;x=e.clientX;y+=window.pageYOffset;x+=window.pageXOffset
            }
        return{'x':x,'y':y};
    }
    function etailPictureSee()
    {
        return false;
    }
    
    
    var etailPictureElementExtend=function()
    {
        var args=arguments;
        if(!args[1])args=[this,args[0]];
        for(var property in args[1])
            args[0][property]=args[1][property];
       
       return args[0];
     };
     
      function etailPicturePluseEventAddListener(obj,event,listener)
     {
        if(etailPicturePluseBrowser=='gecko'||etailPicturePluseBrowser=='opera'||etailPicturePluseBrowser=='safari')
        {
            try
            {
               obj.addEventListener(event,listener,false);
            }
            catch(e)
            {
               alert("We Find Error In : "+e+", event="+event);
            }
        }
        else if(etailPicturePluseBrowser =='msie')
        {
           obj.attachEvent("on"+event,listener);
        }
      };
      
      function etailPicturePluseEventListenerRemove(obj,event,listener)
      {
        if(etailPicturePluseBrowser=='gecko'||etailPicturePluseBrowser=='opera'||etailPicturePluseBrowser=='safari')
        {
            obj.removeEventListener(event,listener,false);
        }
        else if(etailPicturePluseBrowser=='msie')
        {
           obj.detachEvent("on"+event,listener);
        }
      };
      function etailPicturePluseImageConcat()
      {
        var result=[];
        for(var i=0;i<arguments.length;i++)
            for(var j=0;j<arguments[i].length;j++)
                result.push(arguments[i][j]);
                
            return result;
      };
      
      function etailPicturePluseWithoutImage(sequence,skip)
      {
        result=[];
        for(var i=skip;i<sequence.length;i++)
            result.push(sequence[i]);
            
        return result;
      };
      
      function etailPicturePluseMethodReference(object,methodName)
      {
        var args=etailPicturePluseWithoutImage(arguments,2);
        return function()
        {
            object[methodName].apply(object,etailPicturePluseImageConcat(arguments,args));
        }
      };
      function etailPicturePluseEventPropagationClose(e)
      {
        if(etailPicturePluseBrowser=='gecko'||etailPicturePluseBrowser=='safari'||etailPicturePluseBrowser=='opera')
        {
          e.cancelBubble=true;e.preventDefault();e.stopPropagation();
        }
        else if(etailPicturePluseBrowser=='msie')
        {
            window.event.cancelBubble=true
        }
      };
    function etailPicturePluse(smallImageContId,smallImageId,bigImageContId,bigImageId,settings)
    {
        this.recalculating=false;
        this.smallImageCont=_el(smallImageContId);
        this.smallImage=_el(smallImageId);
        this.bigImageCont=_el(bigImageContId);
        this.bigImage=_el(bigImageId);
        this.pup=0;
        this.settings=settings;
        if(!this.settings["header"]){this.settings["header"]=""}
        this.bigImageSizeX=0;this.bigImageSizeY=0;this.smallImageSizeX=0;this.smallImageSizeY=0;this.popupSizeX=20;
        this.popupSizey=20;this.positionX=0;this.positionY=0;this.bigImageContStyleTop='';this.loadingCont=null;
        if(this.settings["loadingImg"]!=''){this.loadingCont=document.createElement('DIV');
        this.loadingCont.style.position='absolute';
        this.loadingCont.style.visibility='hidden';
        this.loadingCont.className='etailPicturePluseLoading';
        this.loadingCont.style.display='block';
        this.loadingCont.style.textAlign='center';
        this.loadingCont.innerHTML=this.settings["loadingText"]+'<br/><img border="0" alt="'+
        this.settings["loadingText"]+'" src="'+this.settings["loadingImg"]+'"/>';
        this.smallImageCont.appendChild(this.loadingCont)}this.baseuri='';
        this.safariOnLoadStarted=false;etailPictureZooming.push(this);
        this.checkcoords_ref=etailPicturePluseMethodReference(this,"checkcoords");
    }; 
    
    etailPicturePluse.prototype.stopZoom=function()
    {
        etailPicturePluseEventListenerRemove(window.document,"mousemove",this.checkcoords_ref);
        if(this.settings["position"]=="custom")
        {
            _el(this.smallImageCont.id+"-big").removeChild(this.bigImageCont)
        }
    };    
    etailPicturePluse.prototype.checkcoords=function(e)
    {
        var r=etailPicturePluseBindEvent(e);var x=r['x'];var y=r['y'];var smallY=0;var smallX=0;
        var tag=this.smallImage;
        while(tag&&tag.tagName!="BODY"&&tag.tagName!="HTML")
        {
            smallY+=tag.offsetTop;
            smallX+=tag.offsetLeft;
            tag=tag.offsetParent;
        }
        if(etailPicturePluseBrowser=='msie')
        {
            var r=etailPicturePluseBind(this.smallImage);
            smallX=r['left'];
            smallY=r['top']
        }
        smallX+=parseInt(etailPicturePluseStyle(this.smallImage,'borderLeftWidth'));
        smallY+=parseInt(etailPicturePluseStyle(this.smallImage,'borderTopWidth'));
        if(etailPicturePluseBrowser!='msie'||!(document.compatMode&&'backcompat'==document.compatMode.toLowerCase()))
        {
            smallX+=parseInt(etailPicturePluseStyle(this.smallImage,'paddingLeft'));
            smallY+=parseInt(etailPicturePluseStyle(this.smallImage,'paddingTop'))
        }
        if(x>parseInt(smallX+this.smallImageSizeX))
        {
            this.hiderect();
            return false;
        }
        if(x<parseInt(smallX))
        {
            this.hiderect();
            return false
        }
        if(y>parseInt(smallY+this.smallImageSizeY))
        {
            this.hiderect();
            return false;
        }
        if(y<parseInt(smallY))
        {   
            this.hiderect();return false; 
        }
        if(etailPicturePluseBrowser=='msie')
        {
            this.smallImageCont.style.zIndex=1;
        }
        return true;
    };     
    etailPicturePluse.prototype.mousedown=function(e)
    {
        etailPicturePluseEventPropagationClose(e);
        this.smallImageCont.style.cursor='move';
    };
    etailPicturePluse.prototype.mouseup=function(e)
    {
        etailPicturePluseEventPropagationClose(e);
        this.smallImageCont.style.cursor='default';
    };
    etailPicturePluse.prototype.mousemove=function(e)
    {
        etailPicturePluseEventPropagationClose(e);
        for(i=0;i<etailPictureZooming.length;i++)
        {
            if(etailPictureZooming[i]!=this)
            {
                etailPictureZooming[i].checkcoords(e);
            }
         }
    if(this.settings&&this.settings["drag_mode"]==true)
    {
        if(this.smallImageCont.style.cursor!='move')
        {
            return;
        }
    }
    if(this.recalculating)
    {
        return;
    }
    if(!this.checkcoords(e))
    {
        return;
    }
    this.recalculating=true;
    var smallImg=this.smallImage;
    var smallX=0;
    var smallY=0;
    if(etailPicturePluseBrowser=='gecko'||etailPicturePluseBrowser=='opera'||etailPicturePluseBrowser=='safari')
    {
        var tag=smallImg;
        while(tag.tagName!="BODY"&&tag.tagName!="HTML")
        {
            smallY+=tag.offsetTop;
            smallX+=tag.offsetLeft;
            tag=tag.offsetParent;
         }
    }
    else
    {
        var r=etailPicturePluseBind(this.smallImage);
        smallX=r['left'];
        smallY=r['top'];
    }
    smallX+=parseInt(etailPicturePluseStyle(this.smallImage,'borderLeftWidth'));
    smallY+=parseInt(etailPicturePluseStyle(this.smallImage,'borderTopWidth'));
    if(etailPicturePluseBrowser!='msie'||!(document.compatMode&&'backcompat'==document.compatMode.toLowerCase()))
    {
        smallX+=parseInt(etailPicturePluseStyle(this.smallImage,'paddingLeft'));
        smallY+=parseInt(etailPicturePluseStyle(this.smallImage,'paddingTop'));
    }
    var r=etailPicturePluseBindEvent(e);
    var x=r['x'];
    var y=r['y'];
    this.positionX=x-smallX;
    this.positionY=y-smallY;
    if((this.positionX+this.popupSizeX/2)>=this.smallImageSizeX)
    {
        this.positionX=this.smallImageSizeX-this.popupSizeX/2;
    }
    if((this.positionY+this.popupSizeY/2)>=this.smallImageSizeY)
    {
        this.positionY=this.smallImageSizeY-this.popupSizeY/2;
    }
    if((this.positionX-this.popupSizeX/2)<=0)
    {
        this.positionX=this.popupSizeX/2;
    }
    if((this.positionY-this.popupSizeY/2)<=0)
    {
        this.positionY=this.popupSizeY/2;
    }
    setTimeout(etailPicturePluseMethodReference(this,"showrect"),10);
  }; 
  etailPicturePluse.prototype.showrect=function()
  {
        var pleft=this.positionX-this.popupSizeX/2;
        var ptop=this.positionY-this.popupSizeY/2;
        var perX=pleft*(this.bigImageSizeX/this.smallImageSizeX);
        var perY=ptop*(this.bigImageSizeY/this.smallImageSizeY);
        if(document.documentElement.dir=='rtl')
        {
            perX=(this.positionX+this.popupSizeX/2-this.smallImageSizeX)*(this.bigImageSizeX/this.smallImageSizeX);
        }
        pleft+=parseInt(etailPicturePluseStyle(this.smallImage,'borderLeftWidth'));
        ptop+=parseInt(etailPicturePluseStyle(this.smallImage,'borderTopWidth'));
        if(etailPicturePluseBrowser!='msie'||!(document.compatMode&&'backcompat'==document.compatMode.toLowerCase()))
        {
            pleft+=parseInt(etailPicturePluseStyle(this.smallImage,'paddingLeft'));
            ptop+=parseInt(etailPicturePluseStyle(this.smallImage,'paddingTop'));
        }
        this.pup.style.left=pleft+'px';
        this.pup.style.top=ptop+'px';
        this.pup.style.visibility="visible";
        if((this.bigImageSizeX-perX)<parseInt(this.bigImageCont.style.width))
        {
            perX=this.bigImageSizeX-parseInt(this.bigImageCont.style.width);
        }
        if((this.bigImageSizeY-perY)<parseInt(this.bigImageCont.style.height))
        {
            perY=this.bigImageSizeY-parseInt(this.bigImageCont.style.height);
        }
        this.bigImage.style.left=(-perX)+'px';
        this.bigImage.style.top=(-perY)+'px';
        this.bigImageCont.style.top=this.bigImageContStyleTop;
        this.bigImageCont.style.display='block';
        this.bigImageCont.style.visibility='visible';
        this.bigImage.style.display='block';
        this.bigImage.style.visibility='visible';
        this.recalculating=false
   };    
   etailPicturePluse.prototype.hiderect=function()
    {
        if(this.settings&&this.settings["bigImage_always_visible"]==true)
             return;
        if(this.pup)
        {
            this.pup.style.visibility="hidden";
        }
        this.bigImageCont.style.top='-10000px';
        if(etailPicturePluseBrowser=='msie')
        {
            this.smallImageCont.style.zIndex=0;
        }
    };  