// Moves object in vertical direction
function changePosiAnim(obj_id, move_to, move_from, dir, speed, no_anim) {
  this.move = move
  function move() {
    if (Math.abs(move_from-move_to) > 5 ) {
      move_from += 5*dir;
    } else {
      move_from = move_to
      clearInterval(anim)
    }
    document.getElementById(obj_id).style.top = move_from + 'px'
  }
  
  //Do not animate if already inside site
  if (document.referrer.search('jack.fi') == -1 || document.referrer.search('jack.fi/index.html') > 0) {
    document.getElementById(obj_id).style.top = move_from
    document.getElementById(obj_id).style.display = 'block'
    var anim = setInterval(this.move, speed)	
  } else {
    document.getElementById(obj_id).style.top = move_to
    document.getElementById(obj_id).style.display = 'block'
  }
}
// Moves object in horizontal direction
function changePosiHAnim(obj_id, move_to, move_from, dir, speed) {
  this.move = move
  if (document.getElementById(obj_id).style.left != (move_to + 'px')) {
    document.getElementById(obj_id).style.left = move_from
    if (speed == 0) {
       move_from = move_to
    }
    var anim = setInterval(this.move, speed)
  }
  function move() {
    if (Math.abs(move_from-move_to) > 5 ) {
      move_from += 5*dir;
    } else {
      move_from = move_to
      clearInterval(anim)
    }
    document.getElementById(obj_id).style.left = move_from + 'px'
  }
}
// Changes height on element according to parameters
function changeHeightAnim(obj_id, from_height, to_height, dir, speed) {
  this.move = move

    if (document.getElementById(obj_id).style.height != (to_height + 'px')) {
      document.getElementById(obj_id).style.height = from_height
      var anim = setInterval(this.move, speed)
    }

  function move() {
    if (Math.abs(from_height-to_height) > 10 ) {
	    from_height += 10*dir;
    } else {
	    from_height = to_height
	    clearInterval(anim)
	  }
	  document.getElementById(obj_id).style.height = from_height + 'px'
  }
}
function zControl(obj_id,z) {
  document.getElementById(obj_id).style.zIndex = z
}
function centerContents(div_id, target_ids) {
  var l = 0
  var elem = document.getElementById(div_id)
  var list = elem.getElementsByTagName("DIV");
  for (i=0;i<list.length;i++) {
    if (list[i].className.search(target_ids)!=-1) {
	  l = l + list[i].offsetWidth
	}
  }
  if (l != 0) {
    elem.style.width = l +'px'
  }
}
