
var htRequest = false;
var htURL = "artworkData/getnext.php";
var newID = 0;
function slide(id){
  htRequest = false;
  
  document.getElementById("awImg").src = "img/loader.gif";
  
  if(window.XMLHttpRequest){ // FF & Co.
    htRequest = new XMLHttpRequest();
  }
  else if(window.ActiveXObject){ // IE
    try{
      htRequest = new ActiveXObject("Msxml2.XMLHTTP");
    }catch(e){
      try{
        htRequest = new ActiveXObject("Microsoft.XMLHTTP");
      }catch(e){}
    }
  }
  if(!htRequest){
    return false; // Fehler beim Client
  }
  
  newID = id;
  
  htRequest.onreadystatechange = function(){
	if(htRequest.readyState == 4){
      if(htRequest.status == 200)
        return show(htRequest.responseText);
      else
        return false; // Fehler beim Server
	}
  }
  
  parameter = 'id='+id;
  
  htRequest.open("POST", htURL, true);
  htRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  htRequest.setRequestHeader("Content-length", parameter.length);
  htRequest.setRequestHeader("Connection", "close");
  htRequest.send(parameter);
  
  return true;
}

var repeats = 0;
var contentAry = new Array();

function show(content){
  contentAry = content.split("\r\n");
  
  contentAry['img'] = new Image();
  contentAry['img'].src = "artworkData/imgs/"+contentAry[3];
  
  contentAry[8] = parseInt(contentAry[8]);
  contentAry['h'] = parseInt(document.getElementById("leinwand").style.height)-15;
  
  resizeMap(contentAry, 0);
}

function resizeMap(contentAry, repeats){
  repeats++;
  actHeightDiff = -Math.round(Math.cos(repeats/(50/Math.PI))*(contentAry[8]-contentAry['h'])/2-(contentAry[8]-contentAry['h'])/2);
  document.getElementById("leinwand").style.height = (contentAry['h']+actHeightDiff+15)+"px";
  if(contentAry[8]==actHeightDiff || repeats>=50)
    showContent(contentAry);
  else
    window.setTimeout(function(){ resizeMap(contentAry, repeats); }, 25);
}

function showContent(contentAry){
  // contentAry[#0-9]
  document.getElementById("leinwand").style.height = (parseInt(contentAry[8])+15)+"px";
  document.getElementById("awImg").src = contentAry['img'].src;
  document.getElementById("awTitle").firstChild.data = contentAry[0];
  document.getElementById("awDescr").innerHTML = contentAry[1];
  document.getElementById("awLabels").innerHTML = contentAry[9];
  document.getElementById("awDate").firstChild.data = contentAry[2];
  document.title = contentAry[0]+" ·· Artwork ·· floern.com";
  document.getElementById("awImg").alt = contentAry[0];
  
  naviA = document.getElementById("awNaviA");
  naviAlinks = naviA.getElementsByTagName("a");
  if(contentAry[4]!='0'){
    naviAlinks[0].href = "artwork/"+contentAry[4];
    naviAlinks[0].setAttribute("onclick", "return !slide('"+contentAry[4]+"')");
    naviAlinks[0].title = contentAry[5];
    naviA.getElementsByTagName("img")[0].style.backgroundPosition = "0 top";
  }
  else{
    naviAlinks[0].href = "artwork";
    naviAlinks[0].setAttribute("onclick", "return false");
    naviAlinks[0].title = "";
    naviA.getElementsByTagName("img")[0].style.backgroundPosition = "-50px top";
  }
  if(contentAry[6]!='0'){
    naviAlinks[1].href = "artwork/"+contentAry[6];
    naviAlinks[1].setAttribute("onclick", "return !slide('"+contentAry[6]+"')");
    naviAlinks[1].title = contentAry[7];
    naviA.getElementsByTagName("img")[2].style.backgroundPosition = "-25px top";
  }
  else{
    naviAlinks[1].href = "artwork";
    naviAlinks[1].setAttribute("onclick", "return false");
    naviAlinks[1].title = "";
    naviA.getElementsByTagName("img")[2].style.backgroundPosition = "-75px top";
  }
  
  naviB = document.getElementById("awNaviB");
  naviBlinks = naviB.getElementsByTagName("a");
  if(contentAry[4]!='0'){
    naviBlinks[0].href = "artwork/"+contentAry[4];
    naviBlinks[0].setAttribute("onclick", "return !slide('"+contentAry[4]+"')");
    naviBlinks[0].title = contentAry[5];
    naviB.getElementsByTagName("img")[0].style.backgroundPosition = "0 top";
  }
  else{
    naviBlinks[0].href = "artwork";
    naviBlinks[0].setAttribute("onclick", "return false");
    naviBlinks[0].title = "";
    naviB.getElementsByTagName("img")[0].style.backgroundPosition = "-50px top";
  }
  if(contentAry[6]!='0'){
    naviBlinks[1].href = "artwork/"+contentAry[6];
    naviBlinks[1].setAttribute("onclick", "return !slide('"+contentAry[6]+"')");
    naviBlinks[1].title = contentAry[7];
    naviB.getElementsByTagName("img")[2].style.backgroundPosition = "-25px top";
  }
  else{
    naviBlinks[1].href = "artwork";
    naviBlinks[1].setAttribute("onclick", "return false");
    naviBlinks[1].title = "";
    naviB.getElementsByTagName("img")[2].style.backgroundPosition = "-75px top";
  }
  
  url = window.location.href.split("#")[0];
  window.location.href = url+"#"+newID;
  
}

