// =====================================================
// script by Gerard Ferrandez - ge1doot - June 1999
// DOM crossbrowser version - April 15th, 2006
// http://www.dhteumeuleu.com
// =====================================================

////////
var Nxi = 6;
var Nyi = 4;
////////
var img;
var spa = [];
var spi = [];
var nx  = 0;
var ny  = 0;
var Li  = 0;
var Hi  = 0;
var nbi = 0;
var yB  = 0;
var fx1 = 0;
var n1  = 0;
var ni1 = 0;
var fx2 = 0;


function ci() {
	for(i=0; i=9; i++){
		y = Math.floor(Math.random()*(Nxi*Nyi));
		if (y != yB) break;
	}
	yB = y;
	return y;
}

function anim() {
	if (fx2 == 1 && y == (Nxi*Nyi)-1) fx2 = 0;

	if (fx1 == 1) {
		n1++;
		y = n1;
		x = ni1;
		if (n1==(Nxi*Nyi)-1) fx1 = 0;
	}

	else {
		x = Math.floor(Math.random() * nbi);
		y = ci();
	}

	if (y==0 && Math.random() > .33) {
		fx1 = 1;
		n1  = 0;
		ni1 = x;
		if (Math.random() > .33) fx2 = 1;
	}
	with (spi[y].style) {
		if (fx2==1) {
			width  = Math.round(nx)+'px';
			height = Math.round(ny)+'px';
			top    = Math.round(-(y % Nyi)*Hi)+'px';
			left   = Math.round(((y % Nyi)*(Li/(Nxi-2)))-((y/Nyi)*Li))+'px';
		}
		else {
			width  = Math.round(Li)+'px';
			height = Math.round(Hi)+'px';
			top    = '0px';
			left   = '0px';
		}
	}

	spi[y].src = img[x].src;

	setTimeout("anim()", 32);
}

function resize() {
	nx = document.getElementById("G1D").offsetWidth;
	ny = document.getElementById("G1D").offsetHeight;
	Li  = Math.floor(nx / Nxi);
	Hi  = Math.floor(ny / Nyi);
	x   = 0;
	y   = 0;
	k   = 0;
	for(var i=0; i<Nxi; i++) {
		for(var j=0; j<Nyi; j++) {
			with (spa[k].style) {
				top    = Math.round(y)+'px';
				left   = Math.round(x)+'px';
				width  = Math.round(Li + 1)+'px';
				height = Math.round(Hi + 1)+'px';
			}
			with (spi[k].style) {
				width  = Math.round(Li)+'px';
				height = Math.round(Hi)+'px';
			}
			k++;
			y += Hi;
		}
		x += Li;
		y = 0;
	}
}

function zyva() {
	img = document.getElementById("img").getElementsByTagName("img");
	nbi = img.length;
	for(var i=0; i<Nxi*Nyi; i++) {
		spa[i] = s = document.createElement("span");
		spi[i] = m = document.createElement("img");
		m.src = img[(i+1)%(nbi-1)].src;
		s.appendChild(m);
		document.getElementById("G1D").appendChild(s);
	}
	resize();
	anim();
}

