control = {

  headline: null,
  summary: null,
  details: null,
  timetable: null,
  image: null,
  rendered: null,

  showDetail: function(href) {
    this.resetAll();
    YAHOO.util.Get.script('http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%22http%3A%2F%2Fwww.schauburg.de%2F' + href + '%22%20and%20xpath%3D%22%2Fhtml%2Fbody%2F%2Fh4%22&format=json&callback=control.getMovieHeadline'); 
    YAHOO.util.Get.script('http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%22http%3A%2F%2Fwww.schauburg.de%2F' + href + '%22%20and%20xpath%3D%22%2Fhtml%2Fbody%2F%2Fp%5B%40class%3D\'Text\'%5D%22&format=json&callback=control.getMovieSummary'); 
    YAHOO.util.Get.script('http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%22http%3A%2F%2Fwww.schauburg.de%2F' + href + '%22%20and%20xpath%3D%22%2Fhtml%2Fbody%2F%2Fp%5B%40class%3D\'Daten\'%5D%22&format=json&callback=control.getMovieDetails'); 
    YAHOO.util.Get.script('http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%22http%3A%2F%2Fwww.schauburg.de%2F' + href + '%22%20and%20xpath%3D%22%2Fhtml%2Fbody%2F%2Ftable%5B%40class%3D\'Spielzeiten\'%5D%2F%2Ftd%22&format=json&callback=control.getMovieTimetable'); 
    YAHOO.util.Get.script('http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%22http%3A%2F%2Fwww.schauburg.de%2F' + href + '%22%20and%20xpath%3D%22%2Fhtml%2Fbody%2F%2Fcenter%2Fimg%22&format=json&callback=control.getMovieImage'); 
  },
  
  resetAll: function() {
    document.getElementById('frame').innerHTML = '';
    this.rendered = false;
    this.headline = null;
    this.summary = null;
    this.details = null;
    this.timetable = null;
    this.image = null;
    this.rendered = null;
  },
  
  getMovieHeadline: function(o) {
    this.headline = o.query.results.h4;
    if (!this.headline) this.headline = 'no headline';
    this.finished();
  },
  
  getMovieSummary: function(o) {
    this.summary = o.query.results.p.font.content;
    if (!this.summary) this.summary = 'no content';
    this.finished();
  },
  
  getMovieDetails: function(o) {
    this.details = o.query.results;
    if (!this.details) this.details = 'no details';
    this.finished();
  },
  
  getMovieTimetable: function(o) {
    this.timetable = o.query.results.td;
    if (!this.timetable) this.timetable = 'no timetable';
    this.finished();
  },
  
  getMovieImage: function(o) {
    this.image = o.query.results.img;
    this.finished();
  },
  
  finished: function() {
  /*
    console.log(this.rendered);
    console.log(this.headline);
    console.log(this.summary);
    console.log(this.details);
    console.log(this.timetable);
    console.log(this.image);*/
    if (!this.rendered && this.headline && this.summary && this.details && this.timetable && this.image) {
      this.rendered = true;
      var h2 = document.createElement('h2');
      h2.appendChild(document.createTextNode(this.headline));
      document.getElementById('frame').appendChild(h2);
      var p = document.createElement('p');
      p.setAttribute('class', 'summary');
      p.appendChild(document.createTextNode(this.summary));
      document.getElementById('frame').appendChild(p);
      var div = document.createElement('p');
      div.setAttribute('class', 'cover');
      var img = document.createElement('img');
      img.setAttribute('src', 'http://www.schauburg.de/' + this.image.src);
      img.setAttribute('alt', this.image.alt);
      div.appendChild(img);
      document.getElementById('frame').appendChild(div);
      var h3 = document.createElement('h3');
      h3.appendChild(document.createTextNode('Spielzeiten'));
      var dl = document.createElement('dl');
      dl.setAttribute('class', 'timetable');
      for (var i = 0; i < this.timetable.length; i = i + 2) {
        if (this.timetable[i] && this.timetable[i].em) {
          var dt = document.createElement('dt');
          dt.appendChild(document.createTextNode(this.timetable[i].em));
          dl.appendChild(dt);
        }
        if (this.timetable[i + 1] && this.timetable[i + 1].p) {
          var dd = document.createElement('dd');
          dd.appendChild(document.createTextNode(this.timetable[i + 1].p));
          dl.appendChild(dd);
        }
      }
      document.getElementById('frame').appendChild(h3);
      document.getElementById('frame').appendChild(dl);
      console.log(this.summary);
      console.log(this.details);
      console.log(this.timetable);
      console.log(this.image);
    }
  }
  
};