
utl = {}
utl.std = ( document.compatMode=="CSS1Compat")? document.documentElement : document.body;
utl.dom = (document.getElementById && document.createTextNode && document.getElementsByTagName)? true : false;
utl.ieOld = (typeof document.body.style.maxHeight == "undefined") ? true : false;
utl.swh = function(o)
{
var ob=document.getElementById(o);
if(!ob){return;}
ob.style.display=ob.style.display=='none'?'block':'none';
}
utl.tei = function(e)
{
return (utl.dom && document.getElementById(e))?true:false;
}
utl.gei = function(e)
{
if(utl.tei(e))
return document.getElementById(e);
}
utl.get = function(t)
{
if(utl.dom)
return document.getElementsByTagName(t);
}
utl.gec = function (c,t,n)
{
var ce = new Array();
if(!n) n = document.body;
var e = n.getElementsByTagName(t);
var el = e.length;
var p = new RegExp("\\b"+c+"\\b");
for (i = 0, j = 0; i < el; i++)
{
if ( p.test(e[i].className) )
{
ce[j] = e[i];
j++;
}
}
return ce;
}
utl.css = function (a,o,c1,c2)
{
switch (a)
{
case 's':
o.className=!utl.css('c',o,c1)?o.className.replace(c2,c1):o.className.replace(c1,c2);
break;
case 'a':
if(!utl.css('c',o,c1))
{
o.className+=o.className?' '+c1:c1;
}
break;
case 'r':
var r=o.className.match(' '+c1)?' '+c1:c1;
o.className=o.className.replace(r,'');
break;
case 'c':
return new RegExp("(^|\\s)" + c1 + "(\\s|$)").test(o.className)
break;
}
}
utl.ade = function(o,t,f,c)
{
if (o.addEventListener)
{
o.addEventListener(t, f, c);
return true;
}
else if (o.attachEvent)
{
var r = o.attachEvent('on' + t, f);
return r;
}
else
{
o['on' + t] = f;
}
}
utl.ajx = function(u,t,c)
{
document.getElementById(t).innerHTML = "<p><strong>Carregando...</strong></p>";
if (window.XMLHttpRequest)
{
r = new XMLHttpRequest();
r.onreadystatechange = function() {utl.ajd(t,c);};
r.open("GET", u, true);
r.send(null);
}
else if (window.ActiveXObject)
{
r = new ActiveXObject("Microsoft.XMLHTTP");
if (r)
{
r.onreadystatechange = function() {utl.ajd(t,c);};
r.open("GET", u, true);
r.send();
}
}
}
utl.ajd = function(t,c) {
if (r.readyState == 4)
{
if (r.status == 200)
{
re = r.responseText;
document.getElementById(t).innerHTML = re;
if (c)
c();
}
else
{
document.getElementById(t).innerHTML="Erro ajax:\n" +
r.statusText;
}
}
}
utl.plk = function(id, l, f)
{
if (!utl.gei(id))
{
return;
}
var li = utl.gei(id);
var ls = li.getElementsByTagName("a");
for (var i=0; i<ls.length; i++)
{
ls[i].onclick = function()
{
var u = this.getAttribute("href");
var ur = '/layout/set/' + l + u;
return !f(ur);
}
}
}
var win = null;
utl.nwd = function(p,n,w,h,s)
{
var l = (screen.width) ? (screen.width-w)/2 : 0;
var t = (screen.height) ? (screen.height-h)/2 : 0;
var st = 'height='+h+',width='+w+',top='+t+',left='+l+',scrollbars='+s+',resizable'
win = window.open(p,n,st)
}
utl.cen = function(o)
{
var ie = document.all && !window.opera;
var dom = document.getElementById;
var st = (ie) ? utl.std.scrollTop : window.pageYOffset; // st = scroll top
var sl = (ie) ? utl.std.scrollLeft : window.pageXOffset; // sl = scroll left
var dw = (ie) ? utl.std.clientWidth : window.innerWidth - 16; // dw = doc width
var dh = (ie) ? utl.std.clientHeight: window.innerHeight; // dh = doc height
var ow = o.offsetWidth; // ow = obj width - width of div element
var oh = o.offsetHeight; // oh = obj height -  height of div element
var tp = (dh > oh)? st + dh / 2 - oh / 2 + "px" : st + 10 + "px" //tp = top position - Vertical position of div element: Either centered, or if element height larger than viewpoint height, 10px from top of viewpoint
o.style.left = dw / 2 - ow / 2 + "px" //Center div element horizontally
o.style.top = Math.floor(parseInt(tp)) + "px";
}
utl.opa = function(o,v,b)
{
ob = document.getElementById(o);
ob.style.opacity = v/10;
ob.style.filter = 'alpha(opacity=' + v*10 + ')';
if (b) ob.style.backgroundColor = b;
ob.style.MozOpacity=v/10
ob.style.KhtmlOpacity=v/10
}
utl.ibc = function(f,b) // ibc = init busca
{
var m = "Por favor digite as palavras que deseja buscar";
var n = "Sua consulta deve conter no mínimo 3 caracteres";
var f = document[f];
var c = f["SearchText"];
var b = utl.gei(b);
b.onclick = function()
{
if (c.value == "")
{
alert(m);
f.reset();
c.focus();
return false ;
}
else if (c.value.length < 3)
{
alert(n);
c.focus();
return false;
}
f.submit();
return true ;
}
f.onsubmit = b.onclick;
}
if(window.searchPage != undefined)
utl.ibc("buscaf","procurar")
hig = {}
hig.tcol = '#000';
hig.lcol = new Array('#ffff66','#a0ffff','#99ff99','#ff9999','#ff66ff');
hig.init = function()
{
var p = /busca/i;
if (p.exec(document.referrer) != null)
{
var up = String(document.location).split('?');
if (up[1])
{
var ua = up[1].split('&');
for(var i=0; i<ua.length; i++)
{
var k = ua[i].split('=');
if (k[0] == 'h')
{
hig.go(hig.dec(k[1]));
return;
}
}
}
}
}
hig.dec = function(url)
{
return unescape(url.replace(/\+/g,' '));
}
hig.go = function (t){
t = t.replace(/\"/g,"");
var ts = t.split(' ');
var c = 0;
for(var i=0; i<ts.length; i++)
{
hig.hig(ts[i], utl.gei('content'),hig.lcol[c]);
c = (c == hig.lcol.length-1)?0:c+1;
}
}
hig.hig = function(t, cn, c)
{
var tl = t.toLowerCase();
for(var i=0; i<cn.childNodes.length; i++)
{
var n = cn.childNodes[i];
if (n.nodeType == 3){
var d = n.data;
var dl = d.toLowerCase();
if (dl.indexOf(tl) != -1)
{
var nn = document.createElement('SPAN');
n.parentNode.replaceChild(nn,n);
var r;
while((r = dl.indexOf(tl)) != -1)
{
nn.appendChild(document.createTextNode(d.substr(0,r)));
nn.appendChild(hig.cn(document.createTextNode(d.substr(r,t.length)),c));
d = d.substr(r + t.length);
dl = dl.substr(r + t.length);
}
nn.appendChild(document.createTextNode(d));
}
}
else
{
hig.hig(t, n, c);
}
}
}
hig.cn = function(ch, c)
{
var n = document.createElement('SPAN');
n.style.backgroundColor = c;
n.style.color = hig.tcol;
n.appendChild(ch);
return n;
}
hig.init()
glos = {}
glos.init = function()
{
utl.plk('glo','glossario', glos.go)
}
glos.go = function(ur)
{
utl.ajx(ur, 'glod');
return true;
}
if(window.glossario != undefined)
glos.init();
var sld = {};
sld.img=[];
sld.ar=[];
if (window.slides != undefined)
sld.ar = slides;
sld.cur = 1;
sld.pse = 0;
sld.num = 0;
sld.tmo ='';
sld.bld = function(n)
{
var speed=20, timer=0;
for(i=10;i>0;i--) setTimeout('utl.opa(\'sldi\','+i+')',timer++ * speed);
setTimeout('sld.chp('+n+')', timer * speed);
for(i=0;i<=10;i++) setTimeout('utl.opa(\'sldi\','+i+')',timer++ * speed);
}
sld.init = function()
{
var cn = utl.gei('sld');
if (!utl.dom || cn == null) return;
var btc = document.createElement('ul'), num=1;
var img = utl.gei('sldi');
btc.id="sldb";
sld.ar.unshift(
img.src,
img.alt,
utl.gei('sldl').href
);
var btn ='<li onclick="sld.prv()" onkeypress="sld.prv()" title="Anterior">-</li>';
for(var i=0;i<sld.ar.length;i+=3,num++)
{
btn+='<li onclick="sld.chc(\''+num+'\')" onkeypress="sld.chc(\''+num+'\')" title="'+sld.ar[(i+1)]+'">'+(num)+'</li>';
sld.img[num] = new Image()
sld.img[num].src = sld.ar[i];
}
btn +='<li onclick="sld.nxt()" onkeypress="sld.nxt()" title="Próximo">+</li>';
btc.innerHTML = btn;
cn.appendChild(btc);
sld.num = num-1;
utl.gei('sldb').getElementsByTagName('li')[sld.cur].className="act";
sld.tmo = setTimeout(sld.rti,5000)
utl.ade(img , "mouseover", function(){ sld.pse = 1; });
utl.ade(img , "mouseout", function(){ sld.pse = 0; });
}
sld.chp = function(n)
{
utl.gei('sldi').src = sld.img[n].src;
}
sld.chc = function(n)
{
if (sld.pse == 1)
{
sld.rti();
return;
}
clearTimeout(sld.tmo);
n = parseInt(n);
sld.cur = n;
if (utl.dom)
{
var img = utl.gei('sldi'), ar=(n-1)*3;
sld.bld(n);
img.alt = sld.ar[(ar+1)];
var fdl = utl.gei('sldl');
fdl.href=sld.ar[(ar+2)]
fdl.title=sld.ar[(ar+1)]
var btn = utl.gei('sldb').getElementsByTagName('li');
for(i=0;i<btn.length;i++)
{
btn[i].className="";
}
btn[(n)].className="act";
sld.rti();
}
}
sld.prv = function()
{
var prv = (sld.cur==1)?sld.num:sld.cur-1;
sld.chc(prv);
}
sld.nxt = function()
{
var nxt = (sld.cur==sld.num)?1:parseInt(sld.cur+1);
sld.chc(nxt);
}
sld.rti = function()
{
var nxt = (sld.cur==sld.num)?1:parseInt(sld.cur+1);
sld.tmo = setTimeout(function(){sld.chc(nxt)}, 5000)
}
var imv =
{
et : true, // et = enableTitle - Should "title" attribute of link be used as description?
ea : true, // ea = enableAnimation - Enable fading animation?
ft : '<div class="ft">Fechar X</div>', // ft = footer - Define HTML for footer interface
ld : 'Carregando Imagem...', // ld = loading  Define HTML for "loading" div
tb : null,
ti : null,
tld : null,
tit : false,
tl :[], // tl = targetlinks - Array to hold links with rel="thumbnail"
ctb : function() // tb = createthumbBox
{
var bd = utl.get('body')[0];
pc = document.createElement('div');
pc.id = 'imv';
pc.onclick = imv.closeit;
pc.innerHTML = '<div id="imvi"></div>' + imv.ft;
bd.appendChild( pc );
ld = document.createElement('div');
ld.id = 'imvl';
ld.innerHTML = imv.ld;
bd.appendChild( ld );
imv.tb = utl.gei("imv") // tb = thumbBox
imv.ti = utl.gei("imvi") //ti = thumbImage - Reference div that holds the shown image
imv.tld = utl.gei("imvl") // tld = thumbLoading - Reference "loading" div that will be shown while image is fetched
},
cd : function(o) // cd = centerDiv Centers a div element on the page
{
utl.cen(o);
o.style.visibility = "visible";
},
st : function() //st = show thumbbox Show ThumbBox div
{
imv.cd(imv.tb)
if (imv.ea) //If fading animation enabled
{
var s=20, t=0;
for(i=0;i<=10;i++) setTimeout('utl.opa(\'imvi\','+i+')',t++ * s);
}
},
li : function(link) //li = load image - Load image function that gets attached to each link on the page with rel="thumbnail"
{
if (imv.tb.style.visibility=="visible") //if thumbox is visible on the page already
imv.closeit() //Hide it first (not doing so causes triggers some positioning bug in Firefox
var ih = '<img src="'+link.getAttribute("href")+'" style="'+imv.opacitystring+'" />' // ih = imageHTML - Construct HTML for shown image
if (imv.et && link.getAttribute("title")) //Use title attr of the link as description?
{
imv.tit = true;
ih += '<p id="imvTitle">' + link.getAttribute("title") + '</p>';
}
imv.cd(imv.tld) //Center and display "loading" div while we set up the image to be shown
imv.ti.innerHTML = ih //Populate ti div with shown image's HTML (while still hidden)
imv.fi = imv.ti.getElementsByTagName("img")[0] //fi = featureImage - Reference shown image itself
imv.fi.onload = function() //When target image has completely loaded
{
imv.tld.style.visibility="hidden" //Hide "loading" div
imv.st() //Display "thumbbox" div to the world!
if ( imv.tit )
{
utl.gei('imvTitle').style.width = imv.fi.width + 'px';
}
}
if (document.all && !window.createPopup) //Target IE5.0 browsers only. Address IE image cache not firing onload 	bug: panoramio.com/blog/onload-event/
imv.fi.src = link.getAttribute( "href" );
imv.fi.onerror=function() //If an error has occurred while loading the image to show
{
imv.tld.style.visibility = "hidden" //Hide "loading" div, game over
}
},
closeit:function() //Close "thumbbox" div function
{
imv.tb.style.visibility="hidden"
imv.ti.innerHTML=""
imv.tb.style.left="-6000px"
imv.tb.style.top="-6000px"
},
cleanup:function() //Clean up routine on page unload
{
imv.tld=null
if (imv.fi) imv.fi.onload=null
imv.fi=null
imv.ti=null
for (var i=0; i<imv.tl.length; i++)
imv.tl[i].onclick=null
imv.tb=null
},
init : function() //Initialize thumbnail viewer script by scanning page and attaching appropriate function to links with rel="thumbnail"
{
var pl=document.getElementsByTagName("a")
for (var i=0; i<pl.length; i++) //BEGIN FOR LOOP
{
if (pl[i].getAttribute("rel") && pl[i].getAttribute("rel")=="thumbnail") //Begin if statement
{
pl[i].onclick=function()
{
imv.li(this) //Load image
return false
}
imv.tl[imv.tl.length]=pl[i] //store reference to target link
} //end if statement
} //END FOR LOOP
utl.ade(window, "resize", function(){if (imv.tb.style.visibility=="visible") imv.cd(imv.tb)})
} //END init() function
}
if(typeof( window[ 'showImage' ] ) != "undefined")
{
imv.ctb() //Output HTML for the image thumbnail viewer
utl.ade(window,"load",function(){imv.init()});
utl.ade(window,"unload",function(){imv.cleanup()});
}
function in_array(needle,haystack)
{
return new RegExp('(^|\,)' + needle + '(\,|$)','gi').test(haystack);
}

