var _BOX_ = null;

function creabox(x, y)
{
	_BOX_ = document.createElement("div");
	_BOX_.style.border = "1px solid black";
	_BOX_.style.position = "absolute";
	_BOX_.style.top = y + "px";
	_BOX_.style.left = x + "px";
	_BOX_.style.backgroundColor = "white";
	_BOX_.style.color = "black";
	_BOX_.innerHTML = "Download";
	_BOX_.style.padding = "2px 2px 2px 2px";
	document.body.appendChild(_BOX_);
}

function onOverOut()
{
	var nome = new String(this.src);
	var tmp = nome.split("/");
	nome = new String(tmp[tmp.length - 1]);
	tmp = nome.split(".");
	nome = new String(tmp[0]);
	var curr = new String(document.getElementById("current_foto").value);

	if (nome.indexOf("_over", 0) > 0)
	{
		if (curr.valueOf() != nome.substr(0, nome.length - 5))
			this.src = "/images/" + nome.substr(0, nome.length - 4) + "alpha.jpg";
	}
	else
	{
		if (curr.valueOf() != nome.substr(0, nome.length - 6))
			this.src = "/images/" + nome.substr(0, nome.length - 5) + "over.jpg";
	}
}

function carica_foto(src)
{
	var imm = document.createElement("img");
	imm.src = '/images/' + src;

	var nome = new String(src);
	var tmp = nome.split(".");
	nome = new String(tmp[0]);

	var curr = new String(document.getElementById("current_foto").value);
	try { document.getElementById(curr.valueOf() + "_img").src = "/images/" + curr.valueOf() + "_over.jpg"; }
	catch (e) {}

	document.getElementById("current_foto").value = nome.valueOf();
	document.getElementById(nome.valueOf() + "_img").onmouseover = onOverOut;
	document.getElementById(nome.valueOf() + "_img").onmouseout = onOverOut;
	document.getElementById(nome.valueOf() + "_img").src = "/images/" + nome.valueOf() + "_alpha.jpg";

	imm.onmouseover = function(e)
	{
		if (!e) var e = window.event;
		var xmouse = parseInt(e.clientX);
		var ymouse = parseInt(e.clientY);
		creabox(xmouse + 10, ymouse + 10);
	}

	imm.onmousemove = function(e)
	{
		if (!e) var e = window.event;
		var xmouse = parseInt(e.clientX);
		var ymouse = parseInt(e.clientY);
		_BOX_.style.top = (ymouse + 10) + "px";
		_BOX_.style.left = (xmouse + 10) + "px";
	}

	imm.onmouseout = function()
	{
		document.body.removeChild(_BOX_);
	}

	imm.onclick = function()
	{
		var foto = new String(this.src);
		var tmp = foto.split("/");
		tmp = new String(tmp[tmp.length - 1]);
		var tmp2 = tmp.split(".");
		window.location.replace("/images/" + tmp2[0] + "_high.zip");
	}

	document.getElementById("secdiv").innerHTML = "";
	document.getElementById("secdiv").appendChild(imm);
}

function precache(photoName)
{
	var newphoto = new Image();
	newphoto.src = photoName;
	return newphoto;
}