/* ======================================================================================
                              ===== DOM Panels III =====
        script by Gerard Ferrandez - ge1doot - April 22, 2007
        Evolved from Phil Richard's Panels II: http://www.mgifos.demon.co.uk/panels2.htm
        http://www.dhteumeuleu.com
   ====================================================================================== */

var panel = {
	speed : .02,
	t : 0,
	O : [],
	over : false,

	run : function() {
		panel.t += panel.speed;
		for (var i = 0, o; o = panel.O[i]; i++)
			o.anim(i + panel.t);
	},

	init : function() {
		for (var i = 0, o; o = document.images[i]; i++) {
			if (o.className.indexOf('panel') >= 0) {
				var div = document.createElement('div');
				div.className = 'panel';
				var img = document.createElement('img');
				img.src = o.src;
				img.className = 'imgPanel';
				o.parentNode.replaceChild(div,o);
				div.appendChild(img);
				div.ims = img.style;
				div.src = img.src;
				div.iw = 230;
				div.ih = 160;
				div.cx = -115;
				div.cy = -80;
				div.anim = function(t) {
					nw = this.offsetWidth;
					nh = this.offsetHeight;
					
					var mx = (this.iw - nw) * .5;
					var my = (this.ih - nh) * .5;
					var x = -mx * (1 + Math.cos(t * 1.2));
					var y = -my * (1 + Math.sin(t));

					this.cx += (x - this.cx) * .1;
					this.cy += (y - this.cy) * .1;
					this.ims.left = Math.round(this.cx) + 'px';
					this.ims.top  = Math.round(this.cy) + 'px';
				}
				
				this.O.push(div);
			}
		}
		setInterval(panel.run, 128);
	}
}