var browser=navigator.appName;
var b_version=navigator.appVersion;
var version=parseFloat(b_version);

document.write("<table border='0' cellpadding='0' cellspacing='0' width='780'>");
document.write("	<tr>");
document.write("		<td valign='top' width='780' height='20' align='center' bgcolor='#000000'>");
document.write("        <form name=test_form> <font color='#808080' size='2'>");
document.write("        <input type=checkbox name=ShowCommentary checked onclick='RecheckCheckBoxesSet()'>Zobrazovat název fotky / Show the picture name<br>");
document.write("        <input type=checkbox name=OpenPicNoPopUp checked onclick='RecheckCheckBoxes()'>Otevírat obrázky v horní vrstvě aktuálního okna / Open the pics in an upper layer of the same window<br>");
document.write("</font></form>");
document.write("</td></tr></table>");

var lasto=-1;
var lastObjectID;
var scrWidth; 
var clientW;
var scrHeight 
var clientH;
var GalerySample;
var PicName;
var CurOpac;
var newWindow4pic;
var LeftPicPos = 0;
var TopPicPos = 0;
var LastPicPosTop = 0, LastPicPosLeft = 0;
var long_comment;

window.onscroll = function Scroll()
                    {
                    RepositionPic(1);
                    }     
 
function RecheckCheckBoxes()
{
  box = eval("document.test_form.OpenPicNoPopUp"); 
   if (box.checked == false) document.test_form.ShowCommentary.checked = false; // cannot show commentary if not in upper layer so far

}
function RecheckCheckBoxesSet()
{
  box = eval("document.test_form.ShowCommentary"); 
   if (box.checked == true ) document.test_form.OpenPicNoPopUp.checked = true; // cannot show commentary if not in upper layer so far

}

function Unload(URL)
  {
   document.getElementById('RTLogger').innerHTML ='<p align="left"><img src="http://www.kalop.eu/logger.php?link=unload></p>';
   document.getElementById(URL).style.visibility = "hidden";  
  return(true);
  }
  
  
function Judge(URL,mark)
  {
   
   document.getElementById('RTLogger').innerHTML ='<p align="left"><img src="http://www.kalop.eu/logger.php?link=judge_' + URL +',mark:' +mark+ '"></p>';
   //if(mark < 3 ) alert("Díky za hodnocení / Thanks for judging"); 
   //   else alert("Známka byla zaznamenána / The mark was recordered");
   document.getElementById(URL).style.visibility = "hidden";  
  return(true);
  }
  
function TJudge(TOPURL,URL,mark)
  {
   document.getElementById('RTLogger').innerHTML ='<p align="left"><img src="http://www.kalop.eu/logger.php?link=judge_vote_' +TOPURL+ ':'+ URL +',mark:' +mark+ '"></p>';
   //if(mark < 3 ) alert("Díky za hodnocení / Thanks for judging"); 
   //   else alert("Známka byla zaznamenána / The mark was recordered");
   
   document.getElementById(TOPURL).style.visibility = "hidden";
   if(URL=="baton_solo")
    {
    alert("Thanks. That's my pick too. :) (Please note, that only the last vote per computer and day will be counted.)");
    }
     else alert("Thanks. :)  (Please note, that only the last vote per computer and day will be counted.)");  
  return(true);
  }
  
  
function findParentDivName(parName, obj) {
    var testObj = obj.parentNode;
    var count = 1;
    while(testObj.getAttribute('name') != parName ) {
        testObj = testObj.parentNode;
        count++;
    }
    // now we have the object we were looking for
    name = testObj.getAttribute('id')
return(name);    
} 
  
  

function WinOpen(URL, id, wnd_width, wnd_height, wnd_comment)
   {                                  
   var xpos, ypos, len, full_len, alt_comment;
   var better2close;

   
   box = eval("document.test_form.OpenPicNoPopUp"); 
   if (box.checked == false) newWindow4pic = true; 
      else newWindow4pic = false;
     
   
   full_len = wnd_comment.length
   len      = wnd_comment.indexOf("~");
   long_comment = "";
   if( len < 1 ) 
     {
     len = full_len;
     long_comment = wnd_comment.replace(/_/g," ").substring(0,len); 
     }else
       {
       long_comment = wnd_comment.replace(/_/g," ").substring(len+1,full_len)
       }
   alt_comment =  wnd_comment.replace(/_/g," ").substring(0,len);
  
  
    box = eval("document.test_form.ShowCommentary"); 
   if (box.checked == false) long_comment = ""; // Don't show commentary  

   wnd_width  = wnd_width  + 30;
   wnd_height = wnd_height + 30; 
   if ( wnd_width < 0 ) wnd_width = 0;
   if ( wnd_height < 0 ) wnd_height = 0;
   if(wnd_comment != null ) 
     {
     PicName = URL.substring(URL.indexOf("name=")+5,URL.toUpperCase().indexOf(".JPG")+4);
     URL = URL + "&comment=" + wnd_comment;
     } 
   GetScreenWH();
   GetClientWH();
   // xpos = scrWidth/2-  wnd_width/2;
   // ypos = scrHeight/2 - wnd_height/2;
    xpos = clientW/2-  wnd_width/2;
    ypos = clientH/2 - wnd_height/2;

   if( xpos < 0 ) xpos = 0;
   if( ypos < 0 ) ypos = 0;
   // Dont upper layer if is biger than screen.
   // if(wnd_width-30>scrWidth || wnd_height-30> scrHeight) newWindow4pic = true;
   if(wnd_width-30>clientW || wnd_height-30> clientH) newWindow4pic = true;
   better2close = false;
   
   //GetClientWH();
   LeftPicPos = clientW/2 - wnd_width/2 + 15; 
   TopPicPos  = clientH/2 - wnd_height/2 + 15; 
   
   if( newWindow4pic == true )
     {
     if(GalerySample ) { GalerySample.close(); 
                     }else better2close =true; // resizing in galleryPic.htm is not that fast
     }   
   
   if(wnd_width < scrWidth )
    {
      if( newWindow4pic == true )
       {
       GalerySample = window.open(URL, id , 'directories=0,toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,titlebar=0,width='+wnd_width+',height='+wnd_height+',left = ' + xpos + ',top = ' + ypos);
       }else{       
             
             document.getElementById('RTLogger').innerHTML ='<p align="left"><img src="http://www.kalop.eu/logger.php?link=gallPicTOP_' + PicName + '"></p>';             
             
             document.getElementById('BelowTopPic').style.visibility = "visible";

             setOpacity(document.getElementById('BelowTopPic'), 70);
             
             document.getElementById('TopPic').innerHTML ='<img name="TopPic" "border="0" onclick="RemoveTopPIC()" src="Images/' + PicName + '" alt="' + alt_comment + '">';
                        
             setOpacity(document.getElementById('TopPic'), 0);
                      
             document.getElementById('TopPic').style.visibilility = "visible";
           
           if(  long_comment != null ) 
            {  
             document.getElementById('Commentary').innerHTML ='<p align=\'right\'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[x]&nbsp;&nbsp;' +long_comment + '&nbsp;</p>';
             document.getElementById('Commentary').style.visibilility = "visible";          
             }
             
             RepositionPic(0);
             CurOpac = 0;
             FadeInTopPIC();
            } 
       
         if(better2close == true )
             {
             }
    }else if(wnd_width >= scrWidth )
                { 
                 if( newWindow4pic == true )
                  { 
                  GalerySample = window.open(URL, id , 'directories=0,toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,titlebar=0,width='+wnd_width+',height='+wnd_height+',left = ' + xpos + ',top = ' + ypos);
                  }
                 if(better2close == true )
                     {
                     }
                }
 if( newWindow4pic == true )
     {
       if( GalerySample != null )
         {
         GalerySample.focus();
         }
         return(GalerySample);
      }else return(true);
      
}


function RepositionPic(attr)
{
var x, y, posT, posL, imgW, imgH;
var moveit;
GetClientWH();
posT = posTop(); 
posL = posLeft()
moveit = false;




if( attr == 1 )
   {
    imgW = 0;
    imgH = 0;
    y = LastPicPosTop;
    x = LastPicPosLeft;
    if( firstChildImage(document.getElementById('TopPic')) != null )
       {  
        imgW = document.images["TopPic"].width;
        imgH = document.images["TopPic"].height;
        // alert(LastPicPosTop+" < "+posT+ ", "+LastPicPosTop+imgH+">="+posT+clientH );
        // recalculate if possible, clientW can be change by user during session 
        LeftPicPos = clientW/2 - imgW/2; 
        TopPicPos  = clientH/2 - imgH/2; 
       }               


    // X scroll    --------------
    if( LastPicPosLeft <= posL && (LastPicPosLeft+imgW) >= (posL+clientW))
       {
       // is in bounds let it move with page .. top and bottom is beyond window boarder 
       }else{                    
             if( LastPicPosLeft > posL)
               { // left boarder
                if( imgW > clientW )
                   { x = posL;
                    }else x = posL+LeftPicPos;   
               }else x = (posL+clientW-imgW);
             
             moveit = true;                            
            } 
    
    // Y scroll    --------------
    if( LastPicPosTop <= posT && (LastPicPosTop+imgH) >= (posT+clientH))
       {
       // is in bounds let it move with page
       }else{             
             if( LastPicPosTop > posT)
               { // top boarder
                if( imgH > clientH )
                   { y = (posT);
                    }else y = posT+TopPicPos;   
               }else y = (posT+clientH-imgH);
                 
             moveit= true;                                      
            } 
          
   }else{ // Initial set pos
         x = (posL+LeftPicPos);
         y = (posT+TopPicPos);
         moveit = true;  
     
        }
    
if( moveit == true )
  {    
   moveObjTo('TopPic',x+'px',y+'px');
   moveObjTo('Commentary',x-20+'px',y+5+'px');
   
   LastPicPosLeft = x;
   LastPicPosTop = y;
  }      
  
x = (posL+clientW/2-65) + 'px';
y = (posT+clientH/2-60) + 'px';
moveObjTo('BelowTopPic',x,y)
 
}

   
function GetScreenWH()
{
scrHeight = 480; scrWidth = 640;
if (parseInt(navigator.appVersion)>3) 
  {
  scrWidth = screen.width;
  scrHeight = screen.height;
  }
  else if (navigator.appName == "Netscape"  && parseInt(navigator.appVersion)==3 && navigator.javaEnabled() ) 
			{
			 var jToolkit = java.awt.Toolkit.getDefaultToolkit();
			 var jScreenSize = jToolkit.getScreenSize();
			 scrWidth = jScreenSize.width;
			 scrHeight = jScreenSize.height;
			}
 } 


function GetClientWH()
{
var myWidth = 0, myHeight = 0; 
  var str = "";
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  
clientW = myWidth;
clientH = myHeight;   
}


function OnClickErase(obj)
{
//obj.style.visibility='hidden';
     document.getElementById('TopPic').innerHTML ='';
     document.getElementById('Commentary').style.visibility = "hidden";  
}

function setOpacity(objectID, opac) 
{ 
var objn;

if (opac == lasto && objectID == lastObjectID ) return(0);

    objn = objectID;
    objn.style.opacity = (opac/100 );
    objn.style.MozOpacity = (opac / 100);
    objn.style.KhtmlOpacity = (opac / 100);
    objn.style.filter = 'alpha(opacity=' + opac + ')';
    if(opac == 100 ) objn.style.filter = 'alpha(enabled=false)'; 
    lasto = opac;
    lastObjectID = objectID;
return(opac);    
}


function FadeInTopPIC()
{
var objID;
var picID;

if( CurOpac < 0 ) CurOpac  = 0;
if( CurOpac > 100 ) CurOpac  = 100;

objID = document.getElementById('TopPic');
picID = firstChildImage(objID);

  
setOpacity(objID, CurOpac);
setOpacity(picID, CurOpac);

if( CurOpac > 0 || isImageOk(picID) == true )
 {
    if( CurOpac == 0 ) 
       { document.getElementById('BelowTopPic').style.visibility = "hidden";
       }
    if( CurOpac < 100 ) 
        { CurOpac = CurOpac + 4;
          setTimeout('FadeInTopPIC()',1);
        }
   if( CurOpac > 80 &&  long_comment != "" ) 
     { document.getElementById('Commentary').style.visibility = "visible";
       objID = document.getElementById('Commentary');
       setOpacity(objID, 50);
     }  
  }else setTimeout('FadeInTopPIC()',10); // Just waiting      
}

function RemoveTopPIC()
{
document.getElementById('BelowTopPic').style.visibility = "hidden";
FadeOutTopPIC();

}

function FadeOutTopPIC()
{
var objID = document.getElementById('TopPic');

if( CurOpac < 0 ) CurOpac  = 0;
if( CurOpac > 100 ) CurOpac  = 100;

setOpacity(objID, CurOpac);

if( CurOpac > 0 ) 
  { CurOpac = CurOpac - 20;
    setTimeout('FadeOutTopPIC()',1);  
    if( CurOpac < 41 ) document.getElementById('Commentary').style.visibility = "hidden";  
  }else OnClickErase(document.getElementById('TopPic'));
}

function firstChildImage(fchi) 
{
    
  fchi = fchi.firstChild;
  while(fchi && fchi.tagName != 'IMG') 
        {
        fchi = fchi.nextSibling;
        }  
  
    return fchi;
}
//------------------------------


// Cross Browser DOM
// copyright Stephen Chapman, 4th Jan 2005
// you may copy this code but please keep the copyright notice as well
var aDOM = 0, ieDOM = 0, nsDOM = 0; var stdDOM = document.getElementById;
if (stdDOM) aDOM = 1; else {ieDOM = document.all; if (ieDOM) aDOM = 1; else {
var nsDOM = ((navigator.appName.indexOf('Netscape') != -1)
&& (parseInt(navigator.appVersion) ==4)); if (nsDOM) aDOM = 1;}}
function xDOM(objectId, wS) {
if (stdDOM) return wS ? document.getElementById(objectId).style:
document.getElementById(objectId);
if (ieDOM) return wS ? document.all[objectId].style: document.all[objectId];
if (nsDOM) return document.layers[objectId];
}
function objWidth(objectID) {var obj = xDOM(objectID,0); if(obj.offsetWidth) return obj.offsetWidth; if (obj.clip) return obj.clip.width; return 0;}
function objHeight(objectID) {var obj = xDOM(objectID,0); if(obj.offsetHeight) return obj.offsetHeight; if (obj.clip) return obj.clip.height; return 0;}
function objLeft(objectID) {var obj = xDOM(objectID,0);var objs = xDOM(objectID,1);  if(objs.left) return objs.left; if (objs.pixelLeft) return objs.pixelLeft; if (obj.offsetLeft) return obj.offsetLeft; return 0;}
function objTop(objectID) {var obj = xDOM(objectID,0);var objs = xDOM(objectID,1);  if(objs.top) return objs.top; if (objs.pixelTop) return objs.pixelTop; if (obj.offsetTop) return obj.offsetTop; return 0;}
function objRight(objectID) {return objLeft(objectID)+objWidth(objectID);}
function objBottom(objectID) {return objTop(objectID)+objHeight(objectID);}
function objLayer(objectID) {var objs = xDOM(objectID,1); if(objs.zIndex) return objs.zIndex; return 0;}
function objVisible(objectID) {var objs = xDOM(objectID,1); if(objs.visibility == 'hide' || objs.visibility == 'hidden') return 'hidden'; return 'visible';}

// More Object Functions
// copyright Stephen Chapman, 18th Jan 2005
// you may copy these functions but please keep the copyright notice as well
function setObjVis(objectID,vis) {var objs = xDOM(objectID,1); objs.visibility = vis;}
function toggleObjVis(objectID) {var objs = xDOM(objectID,1); var vis = objs.visibility; objs.visibility = (vis == "visible" || vis == "show") ? 'hidden' : 'visible';}
function moveObjTo(objectID,x,y) {var objs = xDOM(objectID,1); objs.left = x; objs.top = y;}
function moveObjBy(objectID,x,y) {var obj = xDOM(objectID,0);var objs = xDOM(objectID,1); if (obj.offsetLeft != null) {var l = obj.offsetLeft; var t = obj.offsetTop; objs.left = l+x; objs.top = t+y;} else if (objs.pixelLeft != null) {objs.pixelLeft += x; objs.pixelTop += y;} else obj.moveBy(x,y);}
function moveObjLayer(objectID,z) {var objs = xDOM(objectID,1); objs.zIndex = z;}

// Browser Window Size and Position
// copyright Stephen Chapman, 3rd Jan 2005
// you may copy these functions but please keep the copyright notice as well
function pageWidth() {return window.innerWidth != null? window.innerWidth: document.body != null? document.body.clientWidth:null;}
function pageHeight() {return window.innerHeight != null? window.innerHeight: document.body != null? document.body.clientHeight:null;}
function posLeft() {return typeof window.pageXOffset != 'undefined' ? window.pageXOffset:document.documentElement.scrollLeft? document.documentElement.scrollLeft:document.body.scrollLeft? document.body.scrollLeft:0;}
function posTop() {return typeof window.pageYOffset != 'undefined' ? window.pageYOffset:document.documentElement.scrollTop? document.documentElement.scrollTop: document.body.scrollTop?document.body.scrollTop:0;}
function posRight() {return posLeft()+pageWidth();}
function posBottom() {return posTop()+pageHeight();}


// thank you Keith from DZone Snippets 
function isImageOk(img) {
    if (img == null ) 
      { 
      // alert ("Img obj is null - shouldn't be.");
      return false;
      }
    // During the onload event, IE correctly identifies any images
    // that weren't downloaded as not complete. Others should too.
    // Gecko-based browsers act like NS4 in that they report this
    // incorrectly: they always return true.  
    if (!img.complete) {
    
    
    return false;
    }

    // However, they do have two very useful properties: naturalWidth
    // and naturalHeight. These give the true size of the image. If
    // it failed to load, either of these should be zero.
    if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) {
        // alert("Not completed");    
        return false;
    }

    // No other way of checking: assume it's ok.
    return true;
}


