var banner = ["images/2319326794_b5909f2a1e_o.jpg"];

function init() {
	HTMLElement.prototype.fade = fade;
	document.styleSheets[0].deleteRule(8);

	for each (var par in document.getElementsByTagName("ul")) {
		if (par.className == "hdr")
			var ch = par.firstElementChild;
			while (ch) {
				ch.firstElementChild.style.color = "#ff0000";
				ch.style.opacity = 0.625;
				ch.onmouseover = function(evt) {
						var tgt = evt ? evt.target : window.event.target;
						tgt.fade(1.0, 200, null);
					};
				ch.onmouseout = function(evt) {
						var rel = evt ? evt.relatedTarget : window.event.relatedTarget;
						while (rel) {
							if (rel == this)
								break;
							rel = rel.parentNode;
						}
						if (rel != this)
							this.fade(0.625, 200, null);
					};
				ch = ch.nextElementSibling;
			}
	}

	loop();
}

function fade(a, dur, callback) {
	var e = this;
	clearInterval(e.interval);
	e.interval = setInterval(function() {
			if (Math.abs(parseFloat(e.style.opacity) - a) < 0.05) {
				clearInterval(e.interval);
				e.style.opacity = a;
				if (!!callback)
					callback();
			} else
				e.style.opacity = parseFloat(e.style.opacity) + (a - parseFloat(e.style.opacity))*50/dur + "";
		}, 50);
}

function loop() {
	var title = document.getElementById("title");
	var bg = document.getElementById("bg");
	bg.tm = 0;
	bg.style.opacity = 0;
	bg.fade(1.0, 200, function() {
			bg.dx = ((-bg.clientWidth + title.clientWidth)*Math.random() - bg.offsetLeft)/600;
			bg.dy = ((-bg.clientHeight + title.clientHeight)*Math.random() - bg.offsetTop)/600;
			bg.interval = setInterval(function() {
					bg.tm++;
					if (bg.tm >= 600) {
						bg.fade(0.0, 200, function() {
								bg.style.left = (-bg.clientWidth + title.clientWidth)*Math.random() + "px";
								bg.style.top = (-bg.clientHeight + title.clientHeight)*Math.random() + "px";
								loop();
							});
					} else {
						bg.style.left = bg.offsetLeft + bg.dx + "px";
						bg.style.top = bg.offsetTop + bg.dy + "px";
					}
				}, 50);
		});
}

function preview(evt) {
	var tgt = evt ? evt.target : window.event.target;

	var par = document.createElement("div");
	par.id = "filter";
	par.style.background	= "#000000";
	par.style.filter	= "alpha(opacity=0)";
	par.style.opacity	= 0;
	par.style.height	= "100%";
	par.style.left		= 0;
	par.style.position	= "fixed";
	par.style.top		= 0;
	par.style.width		= "100%";
	par.style.zIndex	= 1;
	document.body.insertBefore(par, document.getElementById("docgrid"));
	par.fade(0.5, 200, function() {
			var par = document.getElementById("filter");
			var ch = document.createElement("img");
			ch.id	= "prev";
			ch.src	= tgt.src;
			ch.style.border		= "thin solid #808080";
			ch.style.left		= ((window.innerWidth ? window.innerWidth : document.documentElement.clientWidth) - ch.width)/2;
			ch.style.position	= "fixed";
			ch.style.top		= ((window.innerHeight ? window.innerHeight : document.documentElement.clientHeight) - ch.height)/2;
			ch.style.zIndex		= 2;
			document.body.insertBefore(ch, document.getElementById("docgrid"));
			par.onclick = function(evt) {
				var tgt = evt ? evt.target : window.event.target;
				document.body.removeChild(tgt.nextElementSibling);
				tgt.fade(0.0, 200, function() { document.body.removeChild(tgt); });
			};
			ch.onclick = function(evt) {
				var tgt = evt ? evt.target : window.event.target;
				var par = tgt.previousElementSibling;
				document.body.removeChild(tgt);
				par.fade(0.0, 200, function() { document.body.removeChild(par); });
			}
		});
}

