// Code by Donald Tetto for http://photos.tetto.org/
// Feel free to modify, redistribute, et cetera, but leave this message intact
// Creative Commons Licensed: http://creativecommons.org/licenses/by-nc-sa/2.0/

slid = 0;
showingInput = 0; 

function show(thisTitle) {
  document.getElementById(thisTitle).style.visibility = 'visible';
  return;
}

function hide(thisTitle) {
  document.getElementById(thisTitle).style.visibility = 'hidden';
  return;
}

function slide(maxHeight) {
  if(slid==0) {
    show('info');
    document.getElementById('comments').style.display = 'block';
    document.getElementById('comments').style.overflow='hidden';
    document.getElementById('comments').style.height='0px';
    document.getElementById('slider').style.height='auto';
    moveUp(0,maxHeight);
    slid = 1;
    return;
  }
  document.getElementById('comments').style.overflow='hidden';
  moveDown(maxHeight);
  slid = 0;
  return;
}

function moveUp(curPixels,maxHeight) { 
  if(curPixels<390) {
    curPixels = curPixels + 30;
    if(curPixels>maxHeight) curPixels = maxHeight;
    document.getElementById('comments').style.height=curPixels + "px";
    return window.setTimeout("moveUp("+curPixels+","+maxHeight+")", 25);
  }
  document.getElementById('comments').style.overflow='auto';
  return;
}

function moveDown(curPixels) { 
  if(curPixels>0) {
    curPixels = curPixels - 30;
    if(curPixels<0) curPixels = 0;
    document.getElementById('comments').style.height=curPixels+ "px";
    return window.setTimeout("moveDown("+curPixels+")", 25);
  }
  document.getElementById('comments').style.display = 'none';
  document.getElementById('slider').style.height='30px';
  return;
}

function addTag() {
  document.getElementById('addtag').innerHTML = '<input id="tag" type="text" size="10" name="tag" maxlength="25" autocomplete="off" onkeyup="getTags();" onblur="setTimeout(\'hideTags();\',100);" /><div id="gettags" onmousedown="document.getElementById(\'gettags\').style.display=\'block\';"></div>';
  document.getElementById('tag').focus();
  return;
}

function hideTags() {
  document.getElementById('gettags').style.display='none';
  return;
}

function getHTTPObject() {
  var xmlhttp;
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}

var http = getHTTPObject();

function getTags() {
    if(document.getElementById('tag').value.length) {
        http.open("GET", "/gettags.php?q="+escape(document.getElementById('tag').value), true);
        http.onreadystatechange = doChange;
        http.send(null);
    } else {
        document.getElementById('gettags').style.display = "none";
    }
    return;
}

function doChange() {
  if (http.readyState == 4 && http.responseText.length) {
      document.getElementById('gettags').style.display = "block";
      document.getElementById('gettags').innerHTML = http.responseText;
  } else {
      document.getElementById('gettags').style.display = "none";
  }
  return;
}

function postTag(photo,tag) {
  window.location="/post/?photo="+photo+"&tag="+tag;
}  