var scrollerwidth="160px";
//var scrollerheight="650px";
var scrollerspeed=1;
var pauseit=1;

scrollerspeed=(document.all)? scrollerspeed : Math.max(1, scrollerspeed-1);
var copyspeed=scrollerspeed;
var iedom=document.all||document.getElementById;
var actualheight='';
var cross_scroller, ns_scroller;
var pausespeed=(pauseit==0)? copyspeed: 0;

function popfull(url) 
{
 params  = 'width='+screen.width;
 params += ', height='+screen.height;
 params += ', top=0, left=0'
 params += ', fullscreen=yes';
 newwin=window.open(url,'print', params);
 if (window.focus) {newwin.focus()}
 return false;
}

function populate(scrollercontent, scrollerheight)
 {
  if (iedom)
   {
    cross_scroller=document.getElementById? document.getElementById("iescroller") : document.all.iescroller;
    cross_scroller.style.top=parseInt(scrollerheight)+8+"px";
    cross_scroller.innerHTML=scrollercontent; 
    actualheight=cross_scroller.offsetHeight;
   }
  else if (document.layers)
   {
    ns_scroller=document.ns_scroller.document.ns_scroller2;
    ns_scroller.top=parseInt(scrollerheight)+8;
    ns_scroller.document.write(scrollercontent);
    ns_scroller.document.close();
    actualheight=ns_scroller.document.height;
   }
  lefttime=setInterval("scrollscroller("+scrollerheight+")",20);
 }

function scrollscroller(scrollerheight)
 {
  if (iedom)
   {
    if (parseInt(cross_scroller.style.top)>(actualheight*(-1)+8))
     cross_scroller.style.top=parseInt(cross_scroller.style.top)-copyspeed+"px";
    else
     cross_scroller.style.top=parseInt(scrollerheight)+8+"px";
   }
  else if (document.layers)
   {
    if (ns_scroller.top>(actualheight*(-1)+8))
     ns_scroller.top-=copyspeed;
    else
     ns_scroller.top=parseInt(scrollerheight)+8;
   }
 }

function echoscroll(scrollerheight)
 {
  if (iedom||document.layers)
   {
    with (document)
     {
      if (iedom)
       {
        write('<div style="position:relative;width:'+scrollerwidth+';height:'+scrollerheight+';overflow:hidden" onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=scrollerspeed">');
        write('<div id="iescroller" style="position:absolute;left:0px;top:0px;width:100%;">');
        write('</div></div>');
       }
      else if (document.layers)
       {
        write('<ilayer width='+scrollerwidth+' height='+scrollerheight+' name="ns_scroller">');
        write('<layer name="ns_scroller2" width='+scrollerwidth+' height='+scrollerheight+' left=0 top=0 onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=scrollerspeed"></layer>');
        write('</ilayer>');
       }
     }
   }
 }

var imagecount=new Array();

function getAjaxImages(imgclass, galType, modsubmit, delsubmit)
{
 if (imgclass=="") { imgclass="mwai"; }
 imgtype="mw";
 imagecount[imgclass]=0;
 var ai = document.getElementsByTagName("a");
 for(var i=0,j=ai.length; i<j; i++) 
  if(ai[i].className==imgclass) 
   { 
    imagecount[imgclass]++;
    ai[i].id=imgclass + "_" + imagecount[imgclass];
    if (!ai[i].onclick) ai[i].onclick = function() { showImage(this.id, imgclass, imgtype, galType, modsubmit, delsubmit); return false; }
   }
}

function showImage(sentid, imgclass, type, galType, modsubmit, delsubmit)
 {
   var imghref = document.getElementById(sentid).href;
   var imgsrc = imghref.split("/");
   var imgcnt = sentid.split("_"); var imgid = imgcnt[imgcnt.length-1];
   var imgdescr = document.getElementById(sentid).title;
   document.getElementById("kep").src = "/images/loading.gif";
   document.getElementById("kepgr").style.display = "block";
   document.getElementById("kepedit").style.display = "block";
   document.getElementById("kepbtn1").style.display = "block";
   document.getElementById("kepbtn2").style.display = "inline";

   var keph = parseInt(document.getElementById("kepgr").offsetHeight)-60;
   if (keph<300) keph=300;

   type="mw";
    document.getElementById("kep").src = "/image/h/" + keph + "/" + imgsrc[imgsrc.length-1];
   var imgnr1 = imgsrc[imgsrc.length-1];
   var imgnr2 = imgnr1.split(".");
   if (document.getElementById("kepnext") && document.getElementById("kepprev"))
    {
     if (imgid<2) 
      {
       document.getElementById("kepprev").style.display = "none";
      }
     else
      {
       var gopr = parseInt(imgid)-1;
       document.getElementById("kepprev").style.display = "inline";
       document.getElementById("kepprev").onclick = function() { showImage(imgclass + "_" + gopr, imgclass, type, galType, modsubmit, delsubmit); }
      }
     if (imgid==imagecount[imgclass])
      {
       document.getElementById("kepnext").style.display = "none";
      }
     else
      {
       var gone = parseInt(imgid)+1;
       document.getElementById("kepnext").style.display = "inline";
       document.getElementById("kepnext").onclick = function() { showImage(imgclass + "_" + gone, imgclass, type, galType, modsubmit, delsubmit); }
      }
     document.getElementById("kepcounter").innerHTML = imgid + '/' + imagecount[imgclass];
      document.getElementById("kepzoom").onclick = function() { window.open('/image/h/1600/' + imgsrc[imgsrc.length-1], 'pic', 'toolbar=no,left=0,top=0,status=0,toolbar=0,scrollbars=yes,menubar=0,location=0,directories=0,resizable=yes,width=1024, height=768'); }
     if (parseInt(imagecount[imgclass])>1)
      {
       document.getElementById("startslide").onclick = function() { slideImage(imgid, imgclass, type); }
       document.getElementById("startslide").style.display = "inline";
      }
     else
      {
       document.getElementById("startslide").style.display = "none";
       document.getElementById("kepcounter").style.display = "none";
      }
    document.getElementById("stopslide").style.display="none";
   }
  if (galType=="editor")
   {
        document.getElementById("kepforms").innerHTML = '<form name="ft" style="margin: 0; display: inline;" method="post" action="' + modsubmit + '"> \
        <input type="text" id="keptext" name="keptext" value="" style="border: 1px solid #eee; color: #eee; background: transparent; width: 380px; font-weight: normal; font-size: 10pt; text-align: center"> \
        <input type="hidden" id="id" name="id" value="' + imgnr2[0] + '"> \
        <input type="submit" id="kepbtnedit" value="Módosít" style="background: #eee; color: #333; border: 1px dotted #888; font: bold 10pt Arial;"></form> \
        <form name="fd" style="margin: 0; display: inline;" method="post" action="' + delsubmit + '"> \
        <input type="hidden" name="id" value="' + imgnr2[0] + '"> \
        <input type="button" id="kepbtndel" value="Töröl" onclick=\'if(confirm("Biztos benne? A törlés nem visszavonható!")) submit(this.form)\' style="background: #eee; color: #333; border: 1px dotted #888; font: bold 10pt Arial;"></form>';
   }
  else
   {
        document.getElementById("kepforms").innerHTML = '<form name="ft" style="margin: 0; display: inline;"> \
        <input type="text" id="keptext" name="keptext" value="" style="border: 0; color: #eee; background: transparent; width: 500px; font-weight: normal; font-size: 10pt; text-align: center" readonly></div> \
        <input type="hidden" id="kepid" value=""><input type="hidden" id="kepcount" value=""></form>';
   }
  document.getElementById("keptext").value = imgdescr;
 }


function createGallery(imgclass, galType, modsubmit, delsubmit)
{
 if (!document.getElementById("kepgr"))
  {
   document.write('<div id="kepgr" style="text-align: center; display: none; z-index: 100; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: black; filter:alpha(opacity=75); opacity: 0.75; -moz-opacity: 0.75;"></div> \
      <div id="kepbtn1" style="text-align: right; width: 100%; height: 20px; margin: 0; padding: 2px; display: none; z-index: 104; position: fixed; top: 0; right: 0;"><img src="/images/close.gif" style="border: 1px dotted #888" title="Bezár" alt="Bezár" onclick="HideImg();" /></div> \
    <div id="kepedit" style="z-index: 102; display: none; text-align: center; position: fixed; top: 0; left: 0; width: 100%;"> \
    <center><table align="center" valign="middle" style="margin: 10px; padding: 0px;"><tr> \
     <td align="center" valign="middle" style="background: white; margin: 0px; padding: 2px;" align="center"><img src="/images/loading.gif" id="kep" name="kep" title="" alt="" style="margin-bottom: 20px;" onclick="HideImg();" /><br /> \
         <div id="kepbtn2" style="float: left; width: 100px;"><img src="/images/array_prev.gif" style="border: 1px dotted #888; cursor: hand;" id="kepprev" title="Előző" alt="Előző" /> \
        <img src="/images/array_next.gif" style="border: 1px dotted #888; cursor: hand;" id="kepnext" title="Következő" alt="Következő" /> \
        <img src="/images/zoom.gif" style="border: 1px dotted #888; cursor: hand;" id="kepzoom" title="Nagyít" alt="Nagyít" /> \
        <img src="/images/slideshow.gif" style="border: 1px dotted #888; cursor: hand;" id="startslide" title="Diavetítés" alt="Diavetítés" /> \
        <img src="/images/slideshow.gif" style="border: 1px dotted red; cursor: hand; display: none;" id="stopslide" title="Leállítás" alt="Leállítás" onclick="HideImg();" /> \
        </div><div id="kepforms" style="float: left; width: 500px;"> </div> \
	 <div style="border: 0; background: #eee; text-align: center; border: 1px dotted #888; color: #333; padding: 0 3px 0 3px; height: 15px; float: right; width: 20px;" id="kepcounter"></div><div style="clear: both"></div> \
</td></tr></table></center></div>');
  }
 getAjaxImages(imgclass, galType, modsubmit, delsubmit);
}


function slideImage(imgid, imgclass, type)
 {
   if (document.getElementById("kepbtnedit")) document.getElementById("kepbtnedit").style.display = "none";
   if (document.getElementById("kepbtndel")) document.getElementById("kepbtndel").style.display = "none";
   document.getElementById("kepzoom").style.display = "none";
   document.getElementById("startslide").style.display = "none";
   document.getElementById("stopslide").style.display = "inline";
   var keph = parseInt(document.getElementById("kepgr").offsetHeight)-60;
   if (keph<300) keph=300;
   var imghref = document.getElementById(imgclass+"_"+imgid).href;
   var imgsrc = imghref.split("/");
   nextid=parseInt(imgid)+1;
   if (nextid > imagecount[imgclass]) nextid = 1;
   var imgdescr = document.getElementById(imgclass+"_"+imgid).title;
   if (type=="garageblog")
    document.getElementById("kep").src = "/image/h/" + keph + "/g/" + imgsrc[imgsrc.length-1];
   else
    document.getElementById("kep").src = "/image/h/" + keph + "/" + imgsrc[imgsrc.length-1];
   document.getElementById("keptext").value = imgdescr;
       document.getElementById("kepprev").style.display = "none";
       document.getElementById("kepfirst").style.display = "none";
       document.getElementById("kepnext").style.display = "none";
       document.getElementById("keplast").style.display = "none";
   document.getElementById("kepcounter").innerHTML = imgid + '/' + imagecount[imgclass];
   t = setTimeout("slideImage('"+nextid+"', '"+imgclass+"', '"+type+"');",5000);
 }

function HideImg()
 {
   if (typeof t!="undefined") window.clearTimeout(t);
   document.getElementById("kepgr").style.display = "none";
   document.getElementById("kepedit").style.display = "none";
   document.getElementById("kepbtn1").style.display = "none";
   document.getElementById("kepbtn2").style.display = "none";
   document.getElementById("kep").src = "/images/loading.gif";
 }

