/* COOKIE */
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function showEnquete() {
  /* SHOW LAYER */
  if (readCookie("x-eupanel") == "done") return;
  var n = document.getElementById("eupanel");
  n.style.left = (document.body.clientWidth/2 - 80) + "px";
  var me = new MovingElement(n);
  var targetLeft = document.body.clientWidth/2 - 80; // Layer width/2.
  me.route = function(i) {
    return [
      [targetLeft, targetLeft, 100, (this.targetTop - this.top) * 0.2 + 5, function() {
																																 }],
      [targetLeft, 0.5, 100, 0.5]
    ][i];
  };
  setTimeout(function() {
	me.start();
  }, 500);
  /* CLOSE LAYER */
  document.getElementById("enquete-yes-nl").onclick = function() {
    n.style.display = "none";
    //createCookie("x-eupanel", "done", 265);
    window.open(document.getElementById("enquete-yes-nl").href, "_blank");
    return false;
  };
  document.getElementById("enquete-no").onclick = function() {
    n.style.display = "none";
    //createCookie("x-eupanel", "done", 265);
    return false;
  };
}
function MovingElement(n) {
  var that = this;
  this.route = function() {
    return null;
  };
  this.element = n;
  this.hop = 0;
  this.left = n.offsetLeft;
  this.top = n.offsetTop;
  n.style.marginLeft = 0;
  this.targetLeft = 0;
  this.targetTop = 0;
  this.speedLeft = 0;
  this.speedTop = 0;
  this.step = function() {
    var next = false;
    if (this.left != this.targetLeft || this.top != this.targetTop) {
      if (this.left != this.targetLeft) {
        this.speedLeft = Math.max(1, this.route(this.hop)[1]);
        if (this.left < this.targetLeft) // going right
          this.left = Math.min(this.targetLeft, this.left + this.speedLeft);
        else
          this.left = Math.max(this.targetLeft, this.left - this.speedLeft);
        this.element.style.left = this.left + "px";
      }
      if (this.top != this.targetTop) {
        this.speedTop = Math.max(1, this.route(this.hop)[3]);
        if (this.top < this.targetTop) // going down
          this.top = Math.min(this.targetTop, this.top + this.speedTop);
        else
          this.top = Math.max(this.targetTop, this.top - this.speedTop);
        this.element.style.top = this.top + "px";
      }
      setTimeout(function() {
        that.step();
      }, 50);
    }
    else {
      if (this.route(this.hop)[4])
        this.route(this.hop)[4]();
      if (this.route(++this.hop)) {
        this.targetLeft = this.route(this.hop)[0];
        this.targetTop = this.route(this.hop)[2];
        setTimeout(function() {
          that.step();
        }, 50);
      }
    }
  };
  this.start = function() {
    if (this.route(0)) {
      this.targetLeft = this.route(0)[0];
      this.targetTop = this.route(0)[2];
      this.step();
    }
  };
}
var oldWindowLoad = window.onload;
window.onload = function() {
  if (oldWindowLoad != null) oldWindowLoad();
  showEnquete();
};
