/* Shalmaneser Web Interface
 *
 * Javascript library
 */

var images = new Array();
var xml_link = "";
var index = 0;
 
function init() {
  $('updating').style.display="none";
  $('render').style.display="none";
  Ajax.Responders.register({
    onCreate: function() {
      $('updating').style.display='';
    },
    onComplete: function() {
      $('updating').style.display='none';
    }
  });
}                                

function request() {
  fparser = ($('collins').checked ? "collins" : "minipar");
  fcorpus = ($('framenet').checked ? "framenet" : "wordnet");
  flearner = ($('maxent').checked ? "maxent" : "timbl");
  
  $('updating').style.display="";
  $('render').style.display="none";
  
  new Ajax.Request("rpc/request.php",
    { 
      method:"post",
      parameters:$H({ input: $('input').value, parser: fparser, corpus: fcorpus, learner: flearner }),
      onComplete: function(xml) {
	alert(xml);
      },
      onFailure: function(xml) {
	alert("Failure");
      },
      onSuccess: function(xml) {
        update(xml.responseText);
      }
    });
}

function update(xml) {
  var data = xml.evalJSON();
  $('updating').style.display='none';
  $('render').style.display="";
  xml_link = data.shift();
  images = data;
  index = 0;
  $('previous').style.display = "none";
  $('next').style.display = "none";
  if(images.length > 1)
    $('next').style.display="";
  $('parse').src = data[index];
  $('xml').href=xml_link;
}

function previous_image() {
  if(index > 0) {
    $('next').style.display="";
    index--;
    $('parse').src = images[index];

    if(index <= 0)
      $('previous').style.display="none";
  }
}

function next_image() {
  if(index < images.length-1) {
    $('previous').style.display="";
    index++;
    $('parse').src = images[index];
    
    if(index >= images.length-1)
      $('next').style.display="none";
  }
}
