var gvPhotoGalPos=[];
var gvPhotoGalAuto=[];
var gvPhotoGalAutoReg=[];
var gvarePhotoGalTemp=[];
  if(typeof NS=="undefined") NS=false;
//---------------------------------------------------------------------------
function sidHexAr(c)
{
var a=c.replace("#","").match(/.{2}/g);
  return (hexTodec(a[0])<128 && hexTodec(a[1])<128 && hexTodec(a[2])<128)? 100:0;
}
function hexTodec(hex){return parseInt(hex,16);}
function rgb2hex(r,g,b)
{
  return Number(r).toString(16).toUpperCase().replace(/^(.)$/,'0$1') + 
         Number(g).toString(16).toUpperCase().replace(/^(.)$/,'0$1') +
         Number(b).toString(16).toUpperCase().replace(/^(.)$/,'0$1');
}
function sidDifColor(c,d)
{
var a=c.replace("#","").match(/.{2}/g);
var R = hexTodec(a[0])+d;
var G = hexTodec(a[1])+d;
var B = hexTodec(a[2])+d;
  if(R<0) R=0;
  if(G<0) G=0;
  if(B<0) B=0;
  if(R>255) R=255;
  if(G>255) G=255;
  if(B>255) B=255;
  return rgb2hex(R,G,B);  
}
function sidPhotoGalStart(s,s1,rand,path)
{
if(typeof parent.gveDialogPhotoGal=="object" && parent.gveDialogPhotoGal.style.display=="block") parent.getE("fraDialogPhotoGal").contentWindow.sidInitDescription(s,s1);
var ifr=document.getElementById("PhotoGalIfr"+rand);
var panel=document.getElementById("PhotoGalTbl"+rand);
var thumb=document.getElementById("PhotoGalThumb"+rand);
var img=document.getElementById("PhotoGalImage"+rand);
  if(!NS)
    {
var bgcolor=thumb.style.backgroundColor;
  if(!bgcolor || bgcolor=="") bgcolor=document.getElementById("PhotoGalTd"+rand).style.backgroundColor;
var d=sidHexAr(bgcolor);
var bgDark=sidDifColor(bgcolor,d+-20);
     thumb.style.scrollbarFaceColor=bgDark;
     thumb.style.scrollbarTrackColor=sidDifColor(bgcolor,d+20);
     thumb.style.scrollbarHighlightColor=bgDark;
     thumb.style.scrollbarShadowColor=bgDark;
     thumb.style.scrollbar3dlightColor=bgDark;
     thumb.style.scrollbarArrowColor=sidDifColor(bgcolor,d+-80);
     thumb.style.scrollbarDarkshadowColor=bgDark;
    }
 if(!ifr || !img || !thumb) return; 
var ar=s.split("|");
var arAlt=s1.split("|");
var thumbStyle=panel.getAttribute("thumb");
 thumbStyle=thumbStyle.replace(/((?:width|height):[^;]*;?)/ig,"");
var h=parseInt(panel.getAttribute("thumbh"));
 if((typeof ar!="object") || ar.length<2) return;
 gvarePhotoGalTemp[rand]=document.createElement("DIV");
 gvarePhotoGalTemp[rand].style.cssText=panel.getAttribute("image");
 thumb.innerHTML="";
 
var s="<table id=PhotoGalHolder"+rand+" cellpadding=0 cellspacing=0 border=0><tr>";
 for(var i=0; i<ar.length; i++)
    {
     if(ar[i]=="") continue;
     s+="<td><image src='/System/Constructor/Images/GetImage.aspx?file="+path+"/"+ar[i]+"&height="+h+"'"+
        " id=PhotoGalThumb_"+i+"_"+rand+" name=imgPhotoGal"+
        " alt=\""+arAlt[i]+" \""+
        " onclick=sidPhotoGalClick("+i+","+rand+")"+
        " style='"+thumbStyle+"'></td>";
    }
  s+="</tr><tr>";
  for(var i=0; i<ar.length-1; i++) s+="<td height=7 align=center></td>";
  s+="</tr></table>";
  thumb.innerHTML=s;
  gvPhotoGalPos[rand]=0;
  sidPhotoGalView(0,rand);
  if(!NS) thumb.style.height=h+40;
}
//-----------------
function sidPhotoGalClick(n,rand)
{
 sidPhotoGalAuto(rand,1);
 sidPhotoGalView(n,rand);
}
//-----------------
function sidPhotoGalView(n,rand)
{ 
var panel=document.getElementById("PhotoGalTbl"+rand);
var imgPanel=document.getElementById("PhotoGalImageHolder"+rand);
var w=parseInt(gvarePhotoGalTemp[rand].style.width);
var h=parseInt(gvarePhotoGalTemp[rand].style.height);
var thumb=document.getElementById("PhotoGalThumb_"+n+"_"+rand);
var st;
 s=document.getElementById("PhotoGalThumb_"+n+"_"+rand).src.split("&height=")[0]+"&height="+h+"&width="+w;
 imgPanel.innerHTML="<image src='"+s+"' name=imgPhotoGal>";
   
var tbl=document.getElementById("PhotoGalHolder"+rand);  
var row=tbl.rows[0];
 if(gvPhotoGalPos[rand]!=-1)
   {
    tbl.rows[1].cells[gvPhotoGalPos[rand]].innerHTML="";
    st=document.getElementById("PhotoGalThumb_"+gvPhotoGalPos[rand]+"_"+rand).style;
    st.filter="";
    st.MozOpacity="";
    st.opacity="";
   }
 gvPhotoGalPos[rand]=n;
 st=document.getElementById("PhotoGalThumb_"+gvPhotoGalPos[rand]+"_"+rand).style;
 st.filter='alpha(Opacity="50",FinishOpacity="50",Style="2")';
 st.MozOpacity="0.5";
 st.opacity="0.5";
 if(document.getElementById("PhotoGalDescription"+rand) && document.getElementById("PhotoGalThumb_"+gvPhotoGalPos[rand]+"_"+rand).alt)
    document.getElementById("PhotoGalDescription"+rand).innerHTML=document.getElementById("PhotoGalThumb_"+gvPhotoGalPos[rand]+"_"+rand).alt;
 tbl.rows[1].cells[gvPhotoGalPos[rand]].innerHTML="<img src='/System/.DesignEditor/Icons/PointerUp.gif' width=14 height=7 border=0>";
 if(gvPhotoGalAutoReg[rand]==1) imgPanel.firstChild.attachEvent("onload",new Function("sidPhotoGalAutoGo('"+rand+"');"));
var el=document.getElementById("PhotoGalThumb"+rand);     
 if(gvPhotoGalPos[rand]==0)
   {
    try {el.scrollLeft=0;}
    catch(e) {};   
   }
 else  
   {
  var w=parseInt((el.offsetWidth-row.cells[gvPhotoGalPos[rand]].offsetWidth)/2);
  var s=parseInt(el.scrollLeft);
  var p=row.cells[gvPhotoGalPos[rand]].offsetLeft;
    try
      {
       while(p-s>w)
            {
             s++;
             el.scrollLeft=s;
            } 
      }
      catch(e) {};    
   } 
} 
//-----------------
function sidPhotoGalNextView(rand)
{
var row=document.getElementById("PhotoGalHolder"+rand).rows[0];
var n=0;
 if(gvPhotoGalPos[rand]<row.cells.length-1) n=gvPhotoGalPos[rand]+1;
 sidPhotoGalView(n,rand);
}
//-----------------
function sidPhotoGalAutoGo(rand)
{
 clearInterval(gvPhotoGalAuto[rand]);
 gvPhotoGalAuto[rand]=setTimeout("sidPhotoGalNextView("+rand+")",4000);
}
function sidPhotoGalAuto(rand,reg)
{
var el=document.getElementById("PhotoGalAuto"+rand);
  if(el.src.indexOf("Play")>-1)
    {
     if(reg) return;
     el.src=el.src.replace("Play","Stop");
     gvPhotoGalAutoReg[rand]=1;
     gvPhotoGalAuto[rand]=setTimeout("sidPhotoGalNextView("+rand+")",1000);
    }
  else
    {
     clearInterval(gvPhotoGalAuto[rand]);
     el.src=el.src.replace("Stop","Play");
     gvPhotoGalAutoReg[rand]=0;
    }
}
