/*************************************************************************
  dw_lib.js - used with dw_glide.js, dw_glider.js, ...
  document.getElementById and document.all compatible (not ns4)
  version date September 2003
  
  This code is from Dynamic Web Coding 
  at http://www.dyn-web.com/
  Copyright 2003 by Sharon Paine 
  See Terms of Use at http://www.dyn-web.com/bus/terms.html
  Permission granted to use this code 
  as long as this entire notice is included.
*************************************************************************/

dynObj.holder = {}; 
// constructor
function dynObj(id,x,y,w,h) {
  this.el = dynObj.getElemRef(id);
  if (!this.el) return;  this.id = id; 
  dynObj.holder[this.id] = this; this.animString = "dynObj.holder." + this.id;
  var px = window.opera? 0: "px";
	this.x = x || 0;	if (x) this.el.style.left = this.x + px;
	this.y = y || 0;	if (y) this.el.style.top = this.y + px;
	this.w = w || this.el.offsetWidth || 0;	this.h = h || this.el.offsetHeight || 0;
	// if w/h passed, set style width/height
	if (w) this.el.style.width = w + px; if (h) this.el.style.height = h + px;
  // methods (ref's)
  this.shiftTo = dw_shiftTo;  this.shiftBy = dw_shiftBy;
  this.show = dw_show;  this.hide = dw_hide;  
}

// ref can be discarded (with other prop's retained) and re-obtained using getInstance
dynObj.getElemRef = function(id) { 
  var el = document.getElementById? document.getElementById(id): document.all? document.all[id]: null;
  return el;
} 

dynObj.getInstance = function(id) {
  var obj = dynObj.holder[id];
  if (!obj) obj = new dynObj(id);
  else if (!obj.el) obj.el = dynObj.getElemRef(id);
  return obj;
}

function dw_shiftTo(x,y) {
  if (x != null) this.el.style.left = (this.x = x) + "px";
  if (y != null) this.el.style.top = (this.y = y) + "px";
}

function dw_shiftBy(x,y) { this.shiftTo(this.x+x, this.y+y); }
function dw_show() { this.el.style.visibility = "visible"; }
function dw_hide() { this.el.style.visibility = "hidden"; }  


// for time-based animations
// resources: www.13thparallel.org and www.youngpup.net (accelimation)
var dw_Bezier = {
  B1: function (t) { return t*t*t },
  B2: function (t) { return 3*t*t*(1-t) },
  B3: function (t) { return 3*t*(1-t)*(1-t) },
  B4: function (t) { return (1-t)*(1-t)*(1-t) },
  // returns current value based on percentage of time passed
  getValue: function (percent,startVal,endVal,c1,c2) {
    return endVal * this.B1(percent) + c2 * this.B2(percent) + c1 * this.B3(percent) + startVal * this.B4(percent);
  }
}

// adapted from accelimation.js by Aaron Boodman of www.youngpup.net
dw_Animation = {
  instances: [],
  add: function(fp) {
    this.instances[this.instances.length] = fp;
  	if (this.instances.length == 1) this.timerID = window.setInterval("dw_Animation.control()", 20);
  },
  
  remove: function(fp) {
    for (var i = 0; i < this.instances.length; i++) {
  		if (fp == this.instances[i]) {
  			this.instances = this.instances.slice(0,i).concat( this.instances.slice(i+1) );
  			break;
  		}
  	}
  	if (this.instances.length == 0) {
  		window.clearInterval(this.timerID);	this.timerID = null;
  	}
  },
  
  control: function() {
    for (var i = 0; i < this.instances.length; i++) {
  		if (typeof this.instances[i] == "function" ) this.instances[i]();
      else eval(this.instances[i]);
    }
  }
}

/*************************************************************************
  dw_glide.js - requires dw_lib.js
  version date September 2003
  
  This code is from Dynamic Web Coding 
  at http://www.dyn-web.com/
  Copyright 2003 by Sharon Paine 
  See Terms of Use at http://www.dyn-web.com/bus/terms.html
  Permission granted to use this code 
  as long as this entire notice is included.
*************************************************************************/

// acc is number between -1 and 1 ( -1 full decelerated, 1 full accelerated, 0 linear, i.e. no acceleration)
dynObj.prototype.slideTo = function (destX,destY,slideDur,acc,endFn) {
  this.slideDur = slideDur || .0001; var acc = -acc || 0;
  if (endFn) this.onSlideEnd = endFn;
  // hold destination values (check for movement on 1 axis only)
 	if (destX == null) this.destX = this.x;	else this.destX = destX;
  if (destY == null) this.destY = this.y; else this.destY = destY;
  this.startX = this.x; this.startY = this.y;
	this.st = new Date().getTime();
	// control points for bezier-controlled slide (see www.youngpup.net accelimation)
  this.xc1 = this.x + ( (1+acc) * (this.destX-this.x)/3 );
	this.xc2 = this.x + ( (2+acc) * (this.destX-this.x)/3 );
  this.yc1 = this.y + ( (1+acc) * (this.destY-this.y)/3 );
	this.yc2 = this.y + ( (2+acc) * (this.destY-this.y)/3 );
	this.sliding = true;
  this.onSlideStart();
  dw_Animation.add(this.animString + ".doSlide()");
}

dynObj.prototype.doSlide = function() {
	if (!this.sliding) return;	
	var elapsed = new Date().getTime() - this.st;
	if (elapsed < this.slideDur) {
    var x = dw_Bezier.getValue(elapsed/this.slideDur, this.startX, this.destX, this.xc1, this.xc2);
    var y = dw_Bezier.getValue(elapsed/this.slideDur, this.startY, this.destY, this.yc1, this.yc2);
		this.shiftTo(Math.round(x), Math.round(y));
		this.onSlide();
	} else {	// if time's up
    dw_Animation.remove(this.animString + ".doSlide()");
		this.shiftTo(this.destX,this.destY);
		this.onSlide();
		this.sliding = false;
		this.onSlideEnd();
	}
}

dynObj.prototype.slideBy = function(dx,dy,slideDur,acc,endFn) {
	var destX=this.x+dx; var destY=this.y+dy;
	this.slideTo(destX,destY,slideDur,acc,endFn);
}

dynObj.prototype.onSlideStart = function () {}
dynObj.prototype.onSlide = function () {}
dynObj.prototype.onSlideEnd = function () {}

function initSlidePopup(url, image) {
	var ac_pub = getCookie('ac_pub');
	if (getMyPseudo() == "visiteur") {
		ac_pub = '';
	}	
	if ((ac_pub == '') || (ac_pub == null)) {
		setCookie('ac_pub','on');
		document.write("<div id='slideCode' align='right' style='position:absolute;visibility:hidden;width:120px;height:610px;z-index:200;border:0px;background:black'>");
		document.write("<span style='text-align:right;background:black;position:relative;top:0px;right:3px;padding:0px;font:bold 10px Verdana,Arial,Geneva,sans-serif'><a style='text-decoration:none;color:white' href=\"javascript:void(0)\" onclick=\"slideEmOff(\'slideCode\')\">Fermer X</a></span>");
		document.write("<a href='" + url + "'  target='_blank'><img src='" + image + "' border='0' width='120' height='600'/></a>");
		document.write('</div>');
		slidePop = new dynObj('slideCode', -3800, 28);
		slidePop.show();
		slidePop.el = null;
		slideEm('slideCode');
		setTimeout('slideEmOff()', 30000);
	}
}

function slideEm(id) {
	newLyr = dynObj.getInstance(id);
	newLyr.slideTo(0, null, 2000, -1);
}

function slideEmOff() {
	newLyr = dynObj.getInstance('slideCode');
	newLyr.slideTo(-800, null, 2000, -1);
}

initSlidePopup("http://downloads.casinoqueenvegas.com/affiliates/aiddownload.asp?casinoID=443&gAID=35531&subGid=0&bannerID=8808","http://i42.servimg.com/u/f42/09/02/50/20/120x6013.gif");
