function deb(str)
{
  var e = document.getElementById('debug');
  e.style.display = 'block';
  var o = document.createElement('div');
  e.appendChild(o);
  
  var n = document.createTextNode(str);
  o.appendChild(n);
  
  e.scrollTop = e.scrollHeight;
}

var moviemover = {
  movieBox: null,
  max: 0,
  min: 0,
  goal: 0,
  inited: false,
  init: function() {
    if(!this.inited)
    {
      this.inited = true;
      this.movieBox = document.getElementById('bottommovies');
      this.max = -1 * parseInt(this.movieBox.style.width) + 670;
    }
  },
  isMoving: false,
  move: function() {
    var curr = parseInt(this.movieBox.style.left);
    var diff = (curr - this.goal)/20;
    var delta = curr - (this.goal <= curr ? Math.ceil(diff) : Math.floor(diff) );
    
    //deb('curr: ' + curr + ', goal: ' + this.goal + ', diff: ' + Math.round(diff) + ', delta: ' + delta);
    
    this.movieBox.style.left = delta + 'px';
    
    var prev = document.getElementById('prevvid');
    var next = document.getElementById('nextvid');
    
    if(this.goal == this.min){
      prev.style.visibility = 'hidden';
      next.style.visibility = '';
    } else if (this.goal == this.max){
      prev.style.visibility = '';
      next.style.visibility = 'hidden';
    } else {
      prev.style.visibility = '';
      next.style.visibility = '';
    }
    
    if(curr != this.goal){
      setTimeout('moviemover.move()', 40);
    }else{
      this.isMoving = false;
    }
  },
  next: function() {
    this.init();
    this.goal = Math.max(this.goal - 670, this.max);
    if(this.isMoving) return;
    this.isMoving = true;
    this.move();
  },
  
  prev: function() {
    this.init();
    this.goal = Math.min(this.goal + 670, this.min);
    if(this.isMoving) return;
    this.isMoving = true;
    this.move();
  }
};

function showVid(s){
  // TODO: skal nok laves bedre
  var obj = document.getElementById('videobox');
  obj.innerHTML = '';
  obj.innerHTML = '<object width="480" height="300" id="yt"><param name="movie" id="yt1" value="http://www.youtube.com/v/' + s + '"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed id="yt2" src="http://www.youtube.com/v/' + s + '?color1=0x234900&color2=0x4e9e00&autoplay=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="300"></embed></object>';
}

$(function(){
  $('.boxpageimg').fancybox();
});
