startList = function() 
{
	if (document.all&&document.getElementById) 
	{
		var a = [];
		var re = new RegExp('( |^)hover( |$)');
		var els = document.body.getElementsByTagName("*");

		for(var i=0; i < els.length; i++)
		{
			node = els[i];

			if(re.test(node.className))
			{
				node.onmouseover=function() 
				{
					this.className+=" over";
				}

				node.onmouseout=function() 
				{
					this.className=this.className.replace
						(" over", "");
				}
			}
		}

	}
};

addLoadEvent(startList); 

/* new gallery on the block */
function Galeria(elements)
{
	this.elements = elements;

	this.init = function()
	{
		this.loaded = 0;
		this.position = 0;
		this.move = 0;
		this.size = 0;
		this.max = 10;
		this.acc = 1.1;
		this.imgs = Array();

		this.container = DIV({'class':'container'});

		this.loadNext();
	}

	this.loadNext = function()
	{
		if (this.loaded != 0)
		{
			var wd = this.imgs[this.loaded - 1].width;

			if (wd == 0)
			{
				appendChildNodes(document.body, PRE({'class':'debug', 'style':'Background-color: green; color: black;'}, dumpObj(this.imgs[this.loaded - 1])));
				return;
			}

			this.size +=  wd + 12;
			this.container.style.width = this.size + "px";
		}

		if (this.loaded == this.elements.length)
		{
			return;
		}

		if (this.loaded == 0)
		{
			this.loadElements();
		}

		var loading = this.elements[this.loaded];
		this.imgs[this.loaded] =
			IMG({'class':'capa', 'src': loading[0]});

		var prev_func = "javascript:preview(" + 
				repr(loading[1]) + ", " +
				repr(loading[2]) + ", " +
				repr(loading[3]) + ", " + 
				repr(loading[4]) + ", " + 
				repr(loading[5]) + ", " + 
				repr(loading[6]) + ", " + 
				repr(loading[7]) + ", " + 
				repr(loading[8]) + ", " + 
				repr(loading[9]) + ")";

		appendChildNodes(this.container,
			A({'href': prev_func}, 
				this.imgs[this.loaded]
				));
		if (this.loaded == 0)
			eval(prev_func);

		/// Operações de tamanho

		this.loaded ++;

		if (this.imgs[this.loaded - 1].complete)
		{
			this.loadNext();
		} else
		{
			this.imgs[this.loaded - 1].onload = this.loadNext;
		}
	}

	this.loadElements = function()
	{
		var goleft = A({
			'onmouseover': this.goLeft, 
			'onmouseout' : this.stop,
			'onmousedown' : this.speedUp,
			'onmouseup'  : this.speedDown,
			'id'         : 'goLeft',
			'class'      : 'left'}, "<<");

		var goright = A({
			'onmouseover': this.goRight, 
			'onmouseout' : this.stop,
			'onmousedown' : this.speedUp,
			'onmouseup'  : this.speedDown,
			'id'         : 'goLeft',
			'class'      : 'right'}, ">>");

		swapDOM($('gal_loading'), DIV({'id':'galeria'},
			DIV({'id':'gal', 
				'style':"visibility: visible;"},
				goleft, 
				goright,
				SPAN({}, 
					"Clique na imagem para vê‐la ampliada"),
				this.container)));

/*
		if (sz > max)
		{
			sz = max;
		}


		$('gal').style.width = sz + "px"; */
		var max = computedStyle('gal', 'width',
			'width').replace(/px/, "");

		this.endMargin = max/2;
		this.container.style.left = 0 + "px";
	}

	/// Funções para cuidar do movimento. 
	this.scrollIt = function() 
	{ 
		this.position += this.move;

		if (this.position < 0)
		{
			this.position = 0;
		}

		if (this.position > this.size - this.endMargin)
		{
			this.position = this.size - this.endMargin;
		}

		this.container.style.left = (-this.position) + "px";

		if (Math.abs(this.move) < this.max)
		{
			this.move *= this.acc;
		} else 
		{
			this.move = (Math.abs(this.move)/this.move) * this.max;
		}

		if (this.move != 0)
		{
			callLater(0.05, this.scrollIt);
		}
	}

	this.goLeft = function()
	{
		this.move = -3;
		callLater(0.1, this.scrollIt);
	}

	this.goRight = function()
	{
		this.move = 3;
		callLater(0.1, this.scrollIt);
	}

	this.stop = function()
	{
		this.move = 0;
	}

	this.speedUp = function()
	{
		this.max = 30;
	}

	this.speedDown = function()
	{
		this.max = 10;
	}

	bindMethods(this);
	addLoadEvent(this.init);
}

function preview(capa, texto, detalhes, tipo, chamada, detalhes2, tipo2, chamada2)
{
	var link = "";
	var link2 = "";

	closePreview2();

	if (detalhes != ".")
	{
		if (tipo == "PDF")
		{
			link = A({'href': detalhes, 'target': '_blank', 'style':'clear:both'}, chamada);
		} else
		{
			link = A({'href': 'javascript:preview2("' + detalhes + '")', 'style':'clear:both'}, chamada);
		}
	}

	if (detalhes2 != ".")
	{
		if (tipo2 == "PDF")
		{
			link2 = A({'href': detalhes2, 'target': '_blank'}, chamada2);
		} else
		{
			link2 = A({'href': 'javascript:preview2("' + detalhes2 + '")'}, chamada2);
		}
	}

	var newprev = DIV({'id':'preview'}, IMG({'src': capa}), mkPreviewSpan(texto), link, link2);
	swapDOM($('preview'), newprev);
}

var selo =  IMG({'src':'images/selo_FNLIJ.png', 'style':'float: left; border: 0; padding-left: 5px; padding-right: 5px;'});

function mkPreviewSpan(texto)
{
	ret = SPAN({}, texto[0]);

	for (i = 1; i < texto.length; i++)
	{
		var current = texto[i];
		if (current[0] == "#")
		{
			appendChildNodes(ret, BR(), selo, current.substring(1)); 
		} else if (current[0] == "<") {
			appendChildNodes(ret, BR(), SPAN({"style":"clear: both;"},current.substring(1)));
		} else if (current[0] == "@") {
			var match = current.match(/^@(.*){([^\|]+)\|([^}])}(\*?)/);
			if (match[4] == "*") {
				appendChildNodes(ret, BR());
			}
			appendChildNodes(ret, 
				match[1], 
				A({ "style":"display: inline;", "href": "javascript:preview2(\"" + match[2] + "\");"}, match[3]));
		} else {
			appendChildNodes(ret, BR(), current);
		}
	}

	return ret;
}

function preview2(url)
{
	var newprev = DIV({'id':'preview2'}, A({'href': 'javascript:closePreview2()'}, SPAN({}, "Voltar"), IMG({'src': url}), SPAN({}, "Voltar")));
	if ($('preview2'))
	{
		swapDOM($('preview2'), newprev);
	} else
	{
		appendChildNodes(currentDocument().body, newprev);
	}
}

function closePreview2()
{
	if ($('preview2'))
	{
		swapDOM($('preview2'), "");
	}
}

var MAX_DUMP_DEPTH = 2;
function dumpObj(obj, name, indent, depth) 
{

	if (depth > MAX_DUMP_DEPTH) {
		return indent + name + ": <Maximum Depth Reached>\n";
	}

	if (typeof obj == "object") 
	{
		var child = null;
		var output = indent + name + "\n";

		indent += "\t";

		for (var item in obj)
		{
			try {
				child = obj[item];
			} catch (e) {
				child = "<Unable to Evaluate>";
			}

			output += indent + item + ": " + child + "\n";
		}

		return output;
	} else 
	{
		return obj;
	}
}
/* :cal SetSyn("javascript") */