﻿function isIE() {
  return (navigator.appName == "Microsoft Internet Explorer");
}

var animatedObjects = [];


function setElementOpacity(e, op) {
  e.style.opacity = op;
  e.style.filter = 'alpha(opacity = ' + (op * 100) + ')';
}


function setCookie(c_name, value, expiredays) {
  var exdate = new Date();
  exdate.setDate(exdate.getDate() + expiredays);
  document.cookie = c_name + "=" + escape(value) +
((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());
}

function getCookie(c_name) {
  if (document.cookie.length > 0) {
    c_start = document.cookie.indexOf(c_name + "=");
    if (c_start != -1) {
      c_start = c_start + c_name.length + 1;
      c_end = document.cookie.indexOf(";", c_start);
      if (c_end == -1) c_end = document.cookie.length;
      return unescape(document.cookie.substring(c_start, c_end));
    }
  }
  return null;
}

var animation = false;


function removeObjectFromAnimation(obj) {
}

function addObjectToAnimate(obj) {

  var i = animatedObjects.length;
  while (i--) {
    if (animatedObjects[i] === obj)
      return;
  }

  animatedObjects.push(obj);
  if (!animation) {
    animation = true;
    lastTick = new Date().getTime();

    animationCore();
  }

}

var lastTick = null;

function log(msg) {
  document.getElementById("log").innerHTML += " " + msg;
}

function animationCore() {
  var tick = new Date().getTime();
  var delta = tick - lastTick;
  lastTick = tick;

  var i = 0;

  while (i < animatedObjects.length) {

    if (!animatedObjects[i].Update(delta)) {
      animatedObjects.splice(i, 1);
    } else {
      i++;
    }
  }

  if (animatedObjects.length == 0) {
    animation = false;
  } else {
    setTimeout("animationCore()", 20);
  }
}


