//******************************************************************************************************************************
var GalleryTop = 180;
ClickToClose = TRANS['GEN_IMG_POPUP_CLOSE'];

var Gallery_ElementObjectsCache=new Object();
function Gallery_GetE(objID){
  if (!Gallery_ElementObjectsCache[objID]) Gallery_ElementObjectsCache[objID]=document.getElementById(objID);    
  return Gallery_ElementObjectsCache[objID];
}

//******************************************************************************************************************************
function Gallery_Show(Obj,ImgId){
  Gallery_showpic(Obj[ImgId].src,Obj[ImgId].text,ImgId+1,Obj.length);
}


//******************************************************************************************************************************
function Gallery_hidepic(){
  Gallery_GetE('Gallery_BigImage').innerHTML='';
  Gallery_opacity('Gallery_BodyHider', 50, 0, 500,"Gallery_GetE('Gallery_BodyHider').style.visibility='hidden';");
}
  
//******************************************************************************************************************************
function Gallery_ShowSimple(Src,Text){
  ImgId=0;
  var Obj=new Array()
  Obj[0]=new Object();
  Obj[0].src=Src;
  Obj[0].text=Text;
  Gallery_Show(Obj,0);
}

//******************************************************************************************************************************
function Gallery_Show(ObjName,ImgId,NoAnimation){
  var Obj=new Object()
  Obj=eval(ObjName);
  
  if (!Gallery_GetE('Gallery_BigImage')){
    var Gallery_BodyHider = document.createElement("div");    
    window.document.body.appendChild(Gallery_BodyHider);    
    Gallery_BodyHider.id='Gallery_BodyHider';
    Gallery_GetE('Gallery_BodyHider').style.position="absolute";
    Gallery_GetE('Gallery_BodyHider').style.className='bodyHidder';
  
    var Gallery_BigImage = document.createElement("div");
    Gallery_BigImage.id='Gallery_BigImage';
    window.document.body.appendChild(Gallery_BigImage);
    Gallery_GetE('Gallery_BigImage').style.position="absolute";
    Gallery_GetE('Gallery_BigImage').style.zIndex=10000;
  }
  /*Gallery_GetE('Gallery_BodyHider').style.width=document.body.clientWidth+"px";
  Gallery_GetE('Gallery_BodyHider').style.height=document.body.clientHeight+'px';*/
  AvailablePageSizes=Gallery_getPageSize();
  Gallery_GetE('Gallery_BodyHider').style.width=AvailablePageSizes[0]+"px";
  Gallery_GetE('Gallery_BodyHider').style.height=AvailablePageSizes[1]+'px';
  
  Gallery_GetE('Gallery_BodyHider').style.visibility='visible';  
  Gallery_GetE('Gallery_BodyHider').className='bodyHidder';
  if (NoAnimation!='1') Gallery_opacity('Gallery_BodyHider', 0, 50, 1000);

  sXY=Gallery_getScrollXY();
  Gallery_GetE('Gallery_BigImage').style.top=(sXY[1]+GalleryTop)+'px';
  Gallery_GetE('Gallery_BigImage').style.left="0";
  Gallery_GetE('Gallery_BigImage').style.width="100%";
  var Content;
  Content='';
  Content+="<table id='Gallery_BigImageTable' border='0' cellpadding='0' cellspacing='0' align='center' class='Gallery_BigImageTable' style='z-index:11000'>";
  Content+="<tr><td></td><td></td><td class='Gallery_MarginTop'><img src='/images/gallery/close.jpg' border='no' title='"+ClickToClose+"' onClick=\"javascript:Gallery_hidepic();return false;\" style='cursor: pointer;'></td></tr>";
  Content+="<tr>";
    Content+="<td class='Gallery_MarginLeftRight'>";
    if (ImgId>0) {
      Execute="Gallery_opacity('GalleryBigImage',50,0,500,\"Gallery_Show('"+ObjName+"',"+(ImgId-1)+",'1');\");";
      //Execute="Gallery_Show('"+ObjName+"',"+(ImgId-1)+",'1');";
      Content+="<img src='/images/gallery/prev.jpg' border='no' onClick=javascript:"+Execute+"return false;\" style='cursor: pointer;'>";
      var TmpImgLeft=new Image();
      TmpImgLeft.src=Obj[ImgId-1].src;
    }
    Content+="</td>";
    Content+="<td class='Gallery_BigImageContent'><img id='GalleryBigImage' src='"+Obj[ImgId].src+"' onClick=\"javascript:Gallery_hidepic();return false;\" title='"+ClickToClose+"' class='Gallery_BigImage'></td>";
    Content+="<td class='Gallery_MarginLeftRight'>";
    if (ImgId<(Obj.length-1)) {
      Execute="Gallery_opacity('GalleryBigImage',50,0,500,\"Gallery_Show('"+ObjName+"',"+(ImgId+1)+",'1');\");";
      //Execute="Gallery_Show('"+ObjName+"',"+(ImgId+1)+",'1');";
      Content+="<img src='/images/gallery/next.jpg' border='no' onClick=javascript:"+Execute+"return false; style='cursor: pointer;'>";
      var TmpImgRight=new Image();
      TmpImgRight.src=Obj[ImgId+1].src;
    }
    Content+="</td>";
  Content+="</tr>";
  Content+="<tr class='Gallery_MarginBottom'><td class='Gallery_MarginLeftRight'></td><td class='Gallery_BigImageText'>"+Obj[ImgId].text+"</td><td class='Gallery_MarginLeftRight'></td></tr>";
  Content+="</table>";
  Gallery_GetE('Gallery_BigImage').innerHTML=Content;
  //Gallery_AdministrateMaskIframe('Gallery_BigImageTable');
}

//******************************************************************************************************************************
function Gallery_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 Gallery_opacity(id, opacStart, opacEnd, millisec,ExecuteEndFunction) {
  //speed for each frame
  var speed = Math.round(millisec / 100);
  var timer = 0;
  //determine the direction for the blending, if start and end are the same nothing happens
  if(opacStart > opacEnd){
    for(i = opacStart; i >= opacEnd; i--) {
      setTimeout("Gallery_changeOpac(" + i + ",'" + id + "')",(timer * speed));
      timer++;
    }
  }else if(opacStart < opacEnd){
    for(i = opacStart; i <= opacEnd; i++){
      setTimeout("Gallery_changeOpac(" + i + ",'" + id + "')",(timer * speed));
      timer++;
    }
  }
  if (ExecuteEndFunction!='') setTimeout('eval("'+ExecuteEndFunction+'");',(timer * speed));
}

//*****************************************************************************************************************
//change the opacity for different browsers
function Gallery_changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 


//*****************************************************************************************************************

function Gallery_getPageSize(){

  var xScroll, yScroll;

  if (window.innerHeight && window.scrollMaxY) {
    xScroll = window.innerWidth + window.scrollMaxX;
    yScroll = window.innerHeight + window.scrollMaxY;
  } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
    xScroll = document.body.scrollWidth;
    yScroll = document.body.scrollHeight;
  } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
    xScroll = document.body.offsetWidth;
    yScroll = document.body.offsetHeight;
  }

  var windowWidth, windowHeight;

//  console.log(self.innerWidth);
//  console.log(document.documentElement.clientWidth);

  if (self.innerHeight) { // all except Explorer
    if(document.documentElement.clientWidth){
      windowWidth = document.documentElement.clientWidth;
    } else {
      windowWidth = self.innerWidth;
    }
    windowHeight = self.innerHeight;
  } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
    windowWidth = document.documentElement.clientWidth;
    windowHeight = document.documentElement.clientHeight;
  } else if (document.body) { // other Explorers
    windowWidth = document.body.clientWidth;
    windowHeight = document.body.clientHeight;
  }

  // for small pages with total height less then height of the viewport
  if(yScroll < windowHeight){
    pageHeight = windowHeight;
  } else {
    pageHeight = yScroll;
  }

//  console.log("xScroll " + xScroll)
//  console.log("windowWidth " + windowWidth)

  // for small pages with total width less then width of the viewport
  if(xScroll < windowWidth){
    pageWidth = xScroll;
  } else {
    pageWidth = windowWidth;
  }
//  console.log("pageWidth " + pageWidth)

  //alert(pageWidth+'+'+pageHeight+'+'+windowWidth+'+'+windowHeight);

  arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
  return arrayPageSize;
}

function Gallery_AdministrateMaskIframe(DivId,Action){
  var tmpDiv=document.getElementById(DivId);
  if (document.getElementById(DivId+'_iframe')){
    var tmpIframe=document.getElementById(DivId+'_iframe');
  }else{  
    var tmpIframe = document.createElement("iframe");
    document.body.appendChild(tmpIframe);
    tmpIframe.id=DivId+'_iframe';
  }
  if (Action=='Hide'){
    tmpIframe.style.display="none";
  }else{
    tmpIframe.style.width=tmpDiv.offsetWidth;
    tmpIframe.style.height=tmpDiv.offsetHeight;
    tmpIframe.style.top=tmpDiv.style.top;
    tmpIframe.style.left=tmpDiv.style.left;    
    tmpIframe.style.zIndex=tmpDiv.style.zIndex - 1;
    tmpIframe.style.display="block";
    tmpIframe.style.position='absolute';
 }
}


