var minwidth = 300;
var myWidth = 0, myHeight = 0;
getWinSize();


function getWinSize(){
  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;
  }

  var date = new Date();
  date.setTime(date.getTime()+(1*24*60*60*1000));
  var expires = "; expires="+date.toGMTString();

  document.cookie = 'winWidth='+myWidth+expires+'; path=/'
  document.cookie = 'winHeight='+myHeight+expires+'; path=/'

}
var comment = document.getElementById('comment');
var picture = document.getElementById('picture');

function keyPress(e){
      	var keycode;
        if (!e) e = window.event;
	keycode = e.keyCode ? e.keyCode : e.which;

	switch(keycode){
          //case 33: //pgup
          case 37: //levo
            imgPrev();
            break;
	  //case 34: //pgdown
          case 39: //pravo
            imgNext();
            break;
          case 38: //nahoru
            document.location.href='./';
          case 13: //enter
            break;
 	  default:
	    //alert(keycode);
 	}
}

function imgPrev(){
  var foto = document.getElementById('foto');
  var prev = document.getElementById('prev');
  if(prev) document.location.href=prev.name;
}

function imgNext(){
  var foto = document.getElementById('foto');
  var next = document.getElementById('next')
  if(next) document.location.href=next.name;
}



function scaleImage(){
  getWinSize();
  var foto = document.getElementById('foto');
  var sipka1 = document.getElementById('sipka1');
  var sipka2 = document.getElementById('sipka2');
  var dokumain = document.getElementById('dokumain');

  if(myWidth < 1000){
      sipka1.style.visibility='hidden';
      sipka1.style.position='absolute';
      sipka2.style.visibility='hidden';
      sipka2.style.position='absolute';
      document.body.style.margin='0.5em';

  }else{
      sipka1.style.visibility='visible';
      sipka1.style.position='relative';
      sipka2.style.visibility='visible';
      sipka2.style.position='relative';
      document.body.style.margin='1em';
  }


  var wwidth = myWidth-170; var wheight=myHeight-100;
  var newWidth = origWidth; var newHeight = origHeight;
  if(wwidth<newWidth){
    newWidth = (wwidth<minwidth) ? minwidth : wwidth;
    newHeight = origHeight*(newWidth/origWidth);
  }


  if(wheight<newHeight && newHeight>minwidth){
    newHeight = wheight;
    newWidth = origWidth*(newHeight/origHeight);
  }

  if(newWidth<minwidth){
    newWidth=minwidth;
    newHeight=origHeight*(newWidth/origWidth);
  }

  if(newWidth!=foto.width){
    foto.style.width='auto';
    foto.style.height = newHeight+'px';

    if(foto.width > newWidth){
      foto.style.height='auto';
      foto.style.width=newWidth+'px';
    }

    document.getElementById('picture').style.width=(foto.width)+'px';
    document.getElementById('picture').style.height=(foto.height)+'px';
    document.getElementById('fotoinfo').style.width=(foto.width)+'px';
    document.getElementById('fotonext').style.width=(foto.width)+'px';
  }

}

function keyDown(e){
  if (!e) var e = window.event;
  if(e.keyCode == 13){
    //addComment();
  }
}


function keyUp(e){ 
  if (!e) var e = window.event;
  if(e.keyCode==13){
  }
}



if (window.Event) window.captureEvents(Event.RESIZE ); 	
window.onresize = scaleImage;
window.onload = scaleImage;
//if (document.Event) document.captureEvents(Event.KEYPRESS ); 	
//document.onkeypress = keyPress;

//document.onkeydown  = keyDown;
//document.onkeyup    = keyUp;

var foto = document.getElementById('foto');









