var ajaxdestination="";

function getdata(what,where) { // get data from source (what)
 try {
   xmlhttp = window.XMLHttpRequest?new XMLHttpRequest():
  		new ActiveXObject("Microsoft.XMLHTTP");
 }
 catch (e) { /* do nothing */ }

 document.getElementById(where).innerHTML ="<center><br><br><img src='bgrounds/dark.gif' class=load></center>";
// we are defining the destination DIV id, must be stored in global variable (ajaxdestination)
 ajaxdestination=where;

 xmlhttp.onreadystatechange = triggered; // when request finished, call the function to put result to destination DIV
 xmlhttp.open("GET", what, true);
 xmlhttp.send(null);
  return false;
}

function triggered() { // put data returned by requested URL to selected DIV
  if (xmlhttp.readyState == 0){
	document.getElementById(ajaxdestination).innerHTML ="<center><br><br><img src='bgrounds/dark.gif' class=load></center>";
	}
  if (xmlhttp.readyState == 4) if (xmlhttp.status == 200) 
    document.getElementById(ajaxdestination).innerHTML =xmlhttp.responseText;
}

var save_scroll;
function beforeScroll(some_scroll){
save_scroll = some_scroll;
}

function afterScroll(){
window.scrollTo(0,save_scroll);
}


function setSize(obj){
var winW = 630, winH = 460;

  winW = window.innerWidth;
  winH = window.innerHeight;

if (parseInt(navigator.appVersion)>3) {
 if (navigator.appName=="Netscape") {
  winW = window.innerWidth;
  winH = window.innerHeight;
 }
 if (navigator.appName.indexOf("Microsoft")!=-1) {
  winW = document.body.offsetWidth;
  winH = document.body.offsetHeight;
 }
}

var posX = document.body.scrollLeft;
var posY = document.body.scrollTop;
beforeScroll(posY);
win = document.getElementById(obj);
win.style.width = winW + 'px';
win.style.height = winH + 'px';
win.style.top = posY + 'px';
win.style.opacity = 0.8;
win.style.filter = 'alpha(opacity=80)';
win.style.visibility = 'visible';
win.style.display = '';
document.body.style.overflow = 'hidden';
}

function showBig(){

win = document.getElementById('bigDiv');
win.style.visibility = 'visible';
//document.body.style.overflow = 'hidden';
}

function hideBig(div){

var win = document.getElementById(div);
var loaded = document.getElementById('loaded');
loaded.style.width = '0px';
loaded.style.height = '0px';
loaded.style.visibility = 'hidden';
win.style.width = '0px';
win.style.height = '0px';
win.style.visibility = 'hidden';
document.body.style.overflow = 'auto';

}

var xmlhttp;

function showComments(gal,page,perpage)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }

var url="comments.php";
url=url+"?gallery="+gal;
url=url+"&page="+page;
url=url+"&perpage="+perpage;
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function stateChanged()
{
if (xmlhttp.readyState==4)
{
document.getElementById('comments').innerHTML=xmlhttp.responseText;
}
}

var fhttp;
function showFComments(page,perpage)
{
fhttp=GetXmlHttpObject();
if (fhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }

var url="forum_comments.php";
url=url+"?page="+page;
url=url+"&perpage="+perpage;

fhttp.onreadystatechange=stateFChanged;
fhttp.open("GET",url,true);
fhttp.send(null);
}

function stateFChanged()
{
if (fhttp.readyState==4)
{
document.getElementById('comments').innerHTML=fhttp.responseText;
}
}

var curPage=1;
var ghttp;
function showLThumbs(page, last, up)
{
ghttp=GetXmlHttpObject();
if (ghttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
if(up == false){
curPage = Math.round(curPage) + Math.round(page);
}
else{curPage = curPage - page;}
if(curPage < 1){curPage = Math.abs(1);}

if(curPage > last){curPage = Math.abs(last);};

var url="gal_thumb.php";
url=url+"?lpage="+curPage;

ghttp.onreadystatechange=stateGChanged;
ghttp.open("GET",url,true);
ghttp.send(null);
}

function stateGChanged()
{
if (ghttp.readyState==4)
{
document.getElementById('glthm').innerHTML=ghttp.responseText;
}
}


function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}

var http;
function addComment(gallery, check){
http = GetXmlHttpObject();
var url = "addcom.php";
var params = ""; 

if(check == true){
params = "method=send&autor=";
var autor = document.getElementById('autor').value;
var body = document.getElementById('comment').value;
var email = document.getElementById('email').value;
params = params + autor + "&email=";
params = params + email + "&gallery=";
params = params + gallery + "&comment=";
params = params + body;
}

http.open("POST", url, true);

//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");
http.onreadystatechange=saveCom;

http.send(params);
}

function saveCom()
{
if (http.readyState==4)
{
var response = http.responseText;
document.getElementById('add_comment').innerHTML = ''+response+ '';
}
}

function reloadCom(gallery){
http = GetXmlHttpObject();
var url = "addcom.php?gallery="+gallery;
http.onreadystatechange=relCom;
http.open("GET",url,true);
http.send(null);
}

function relCom(){
if (http.readyState==4)
{
document.getElementById('add_comment').innerHTML = http.responseText;
showComments(gallery,1,7);
}
}

var dole;
function chodDole(max){
var funkcia = "showLThumbs(1, "+max+", false)";
dole = setInterval( funkcia , 300);
}

function stojDole(){
clearInterval(dole);
}

var hore;
function chodHore(max){
var funkcia = "showLThumbs(1, "+max+", true)";
hore = setInterval( funkcia , 300);
}

function stojHore(){
clearInterval(hore);
}

