﻿// list.js
// gallery.js
// tooltip.js
// autogallery.js
// util.js
// mm.js

/// list.js
function Group(id, visible, fatherId)
{
	this.id = id;
	this.visible = visible;
	this.fatherId = fatherId;
}

function Reset()
{
	var id=0;
	var fatherId=-1;

	while(allGroups[id].fatherId==fatherId)
	{
		ForceShowHide(document.getElementById(allGroups[id].id), true);
		fatherId=id;
		id++;
	}
	listOpenId=id-1;
}

function ListShowHide(id)
{
	var c=id;
	var x;
	var found=false;
	var common=c;
	var child=-1;
	
	if(id != listOpenId)
	{
		
		while(c!=-1)
		{
			x=listOpenId;
			while((x != c) && (x != -1))
				x=allGroups[x].fatherId;
			if(x == c)
				break;		
			c=allGroups[c].fatherId;
		}
		common=c;
		x=listOpenId;
		while(x!=common)
		{
			ForceShowHide(document.getElementById(allGroups[x].id), false);
			x=allGroups[x].fatherId;
		}
		
		c=id;
		while(c!=common)
		{
			ForceShowHide(document.getElementById(allGroups[c].id), true);
			c=allGroups[c].fatherId;
		}
		
		listOpenId=id;
		
		child=FirstChild(id)
		while(child!=-1)
		{
			ForceShowHide(document.getElementById(allGroups[child].id), true);
			listOpenId=child;
			child=FirstChild(child);
		}
		
	}
}

function FirstChild(id)
{
	for(i=0; i<allGroups.length; i++)
	{
		if(id==allGroups[i].fatherId)
			return i;
	}
	return -1;
}



/// gallery.js

function getQueryValue(name) {
	var value = "";
	if ( (i=location.search.indexOf('?'+name))==-1 && (i=location.search.indexOf('&'+name,3))==-1 )
		return null;
	else
		i += name.length+2;
	
	if ( (j=location.search.indexOf("&",i))!=-1 )
		value = location.search.substring(i,j);
	else
		value = location.search.substring(i,location.search.length);
	
	for ( i=0; i<value.length; i++ )
		if ( value.charAt(i)=='+' )
  			value = value.substring(0,i)+' '+value.substring(i+1,value.length);
	return unescape(value);
}

N4  = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4 ));
IE4 = ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4 ));
BROWSER4 = (N4 || IE4);
		
function GetCookie(sName)
{
	// cookies are separated by semicolons
	var aCookie = document.cookie.split("; ");
	for (var i=0; i < aCookie.length; i++)
	{
		// a name/value pair (a crumb) is separated by an equal sign
		var aCrumb = aCookie[i].split("=");
		if (sName == aCrumb[0])
			return unescape(aCrumb[1]);
	}

	// a cookie with the requested name does not exist
	return null;
}


function guardar_posicao()
{
	//if (!N4)
	//	document.cookie = "Y=" + document.body.scrollTop; 
}

function posicao()
{
	//if (!N4)
	//	window.scrollTo(0, GetCookie("Y"));
}

function fg(url)
{
	guardar_posicao();
	window.location=url;
}

function zoom(page, w, h)
{
    var param, newwindow;
    w+=50;
    h+=62;
    wAvailable=screen.availWidth-40;
    hAvailable=screen.availHeight-70;
    if((wAvailable < w) || (hAvailable < h))
    {
    if(wAvailable < w) {w=wAvailable;}
    if(hAvailable < h) {h=hAvailable;}
    }
    param='resizable=yes,scrollbars=yes,width=' + w + ',height=' + h + ',toolbar=no';
    newwindow=window.open('','popWin',param); 
    newwindow.resizeTo(w,h);
    newwindow.location.href=page;
    newwindow.focus();
}


function resize(w, h)
{
    var param, newwindow;
    w+=50;
    h+=62;
    wAvailable=screen.availWidth-40;
    hAvailable=screen.availHeight-70;
    if((wAvailable < w) || (hAvailable < h))
    {
		if(wAvailable < w) {w=wAvailable;}
		if(hAvailable < h) {h=hAvailable;}
    }
    window.resizeTo(w,h);
}


/// tooltip.js
var timerID = null;
// avoid error of passing event object in older browsers
if (!document.layers && !document.all) event = "none";

function showToolTip(sTipText, sBGColor, sFontFace, sSize, e) {
    if (document.layers) { // Netscape 4.7x
        var ToolTip = document.layers.tooltip;
        var ToolTipDoc = ToolTip.document;
        ToolTipDoc.open();
        ToolTipDoc.write('<bo'+'dy><div id="tt" style="position:absolute;border:solid;border-width:1;border-color:#000000;layer-background-color:' + sBGColor + ';">');
        ToolTipDoc.write('<font face="' + sFontFace + '" size="' + sSize + '">' + sTipText);
        ToolTipDoc.write('</font></div></bo'+'dy>');
        ToolTipDoc.close();
        ToolTip.clip.width = ToolTipDoc.layers.tt.clip.width;
        ToolTip.clip.height = ToolTipDoc.layers.tt.clip.height;
        document.captureEvents(Event.MOUSEMOVE);
        document.onmousemove = delayToolTip;
        delayToolTip(e);
     }
     if (document.all) { // IE
        var ToolTip = document.all.tooltip;
        var sInnerHTML = '<div id="tt" style="position:absolute;border:solid;border-width:1;padding:2;border-color:#000000;background-color:'+ sBGColor + ';">'; sInnerHTML += '<font face="' + sFontFace + '" size="' + sSize + '">' + sTipText + '</font></div>';
        ToolTip.innerHTML = sInnerHTML;
        ToolTip.noWrap = true;
        document.onmousemove = delayToolTip;
        delayToolTip(e);
     }
} // showToolTip()

function delayToolTip(e) {
    if (timerID) clearTimeout(timerID);
    var nX = 0;
    var nY = 0;
    if (document.layers) { // Netscape 4.7x
        nX = e.pageX;
        nY = e.pageY;
    }
    if (document.all) { // IE
        nX = window.event.clientX + document.body.scrollLeft;
        nY = window.event.clientY + document.body.scrollTop;
    } timerID = setTimeout("displayToolTip(" + nX + ", " + nY + ")", 100);
} // delayToolTip()

function displayToolTip(nX, nY) {
    if (document.layers) { // Netscape 4.7x
        document.releaseEvents(Event.MOUSEMOVE);
        document.onmousemove = null;
        var ToolTip = document.layers.tooltip;
        var ToolTipClip = ToolTip.clip;
        var nRightMargin = window.innerWidth + window.pageXOffset;
        if ((nX + ToolTipClip.width) > (nRightMargin - 10)) { // if the tooltip runs off right
            nX = nRightMargin - ToolTipClip.width - 20;
        }
        if ((nY + ToolTipClip.height) > (window.innerHeight + window.pageYOffset - 38)) { // if tooltip runs off bottom
            nY -= ToolTipClip.height + 22;
        }
        ToolTip.left = nX;
        ToolTip.top = nY + 20;
        ToolTip.visibility = 'visible';
     }
     if (document.all) { // IE
        document.onmousemove = null;
        var ToolTip = document.all.tooltip;
        var ToolTipStyle = ToolTip.style;
        var InnerToolTip = ToolTip.all.tt;
        var nRightMargin = document.body.clientWidth + document.body.scrollLeft;
        if ((nX + InnerToolTip.clientWidth) > nRightMargin) { // if the tooltip runs off right
            nX = nRightMargin - InnerToolTip.clientWidth - 6;
        }
        if ((nY + InnerToolTip.clientHeight) > (document.body.clientHeight + document.body.scrollTop - 20)) { // if tooltip runs off bottom
            nY -= InnerToolTip.clientHeight + 30;
        }
        ToolTipStyle.pixelLeft = nX;
        ToolTipStyle.pixelTop = nY + 20;
        ToolTipStyle.visibility = 'visible';
     }
} // displayToolTip()

function hideToolTip() {
    if (timerID) clearTimeout(timerID);
    if (document.layers) { // Netscape 4.7x
        document.releaseEvents(Event.MOUSEMOVE);
        document.onmousemove = null;
        document.layers.tooltip.visibility = 'hidden';
    }
    if (document.all) { // IE
     document.onmousemove = null;
     var ToolTipStyle = document.all.tooltip.style;
     ToolTipStyle.visibility = 'hidden';
     ToolTipStyle.pixelLeft = 0; // move layer to top left corner, otherwise when you
     ToolTipStyle.pixelTop = 0;  // set innerHTML again, it may cause a horizontal scrollbar
    }
} // hideToolTip()


/// autogallery.js

//Usefull functions

//random calculation
rnd.today=new Date();
rnd.seed=rnd.today.getTime();

function rnd() {
        rnd.seed = (rnd.seed*9301+49297) % 233280;
        return rnd.seed/(233280.0);
};

function rand(number) {
        return Math.ceil(rnd()*number);
};

//self name
Object.prototype.selfRef=selfRef;
Object.prototype.objList=new Array();
function selfRef(arg)
{
	if (!this.objIndex)
	{
		this.objIndex=Object.prototype.objList.length;
		Object.prototype.objList[this.objIndex]=this;
	}
	return "Object.prototype.objList["+this.objIndex+"]";
}


//object definition
function ImageGallery(image1, image2, imagesVector, linkObject, linksVector)
{
	this.incr				=3;    // opacity increment
	this.speed				=50;   // speed in ms for the next opacity change
	this.opacity1			=0;    // image1 startOpacity
	this.opacity2			=100;  // image2 startOpacity
	this.imageTimeoutLow	=3000; // the amount of time to display a full image
	this.imageTimeoutHigh	=3000; // the amount of time to display a full image
	
	this.image1=image1;
	this.image2=image2;
	this.lastImage;
	
	this.imageIndex=1;
	this.s1=  this.incr;
	this.s2= -this.incr;
	
	this.linkObject=linkObject;
	this.imagesVector=imagesVector;
	this.linksVector=linksVector;
	
	this.Start=Start;
	this.SetImageOpacity=SetImageOpacity;
	this.WaitLoading=WaitLoading;
	this.StopAndChangeImage=StopAndChangeImage;
	this.GetImage=GetImage;
	this.SetLink=SetLink;
	this.GetTimeOut=GetTimeOut;
	this.Resume=Resume;

}

function GetTimeOut()
{
	var timeout=rand(this.imageTimeoutHigh-this.imageTimeoutLow) + this.imageTimeoutLow;
	return timeout;
}

function Start()
{	
	this.SetLink(0);
	this.image1.src=this.imagesVector[0];
	this.image2.src=this.imagesVector[1];
	this.imageIndex=2;
	this.SetImageOpacity();
}

function SetLink(imageNumber)
{
	var target;
	target="";
	if(this.linksVector!=null)
		target=this.linksVector[imageNumber];
		
	if(this.linkObject!=null)
		this.linkObject.href=target;
}



function GetImage(imageNumber)
{
	if(imageNumber==1)
		return this.image1;
	else
		return this.image2;
}

function SetImageOpacity()
{
	var stop=false;
	var imgStop;
	this.image1.style.cssText="Filter: Alpha(Opacity="+this.opacity1+"); -moz-opacity:"+this.opacity1+"%";	
	this.image2.style.cssText="Filter: Alpha(Opacity="+this.opacity2+"); -moz-opacity:"+this.opacity2+"%";
	this.opacity1+=this.s1;
	this.opacity2+=this.s2;
	if(this.opacity1>=100)
	{
		this.opacity1=100;
		this.s1=-this.incr;

		stop=true;
		imgStop=2;
	}
	if(this.opacity1<=0)
	{
		this.opacity1=0;
		this.s1=this.incr;
	}
	
	if(this.opacity2>=100)
	{
		this.opacity2=100;
		this.s2=-this.incr;

		stop=true;
		imgStop=1;
	}
	if(this.opacity2<0)
	{
		this.opacity2=0;
		this.s2=this.incr;
	}
	if(stop)
		eval(this.selfRef() + ".StopAndChangeImage("+imgStop+");");
	else
		window.setTimeout(this.selfRef() + ".SetImageOpacity()", this.speed);
}

function WaitLoading(imageNumber)
{
	var imageObject=this.GetImage(imageNumber)
	var timeout;
	timeout=this.GetTimeOut();
	if(imageObject.complete)
		window.setTimeout(this.selfRef() + ".SetImageOpacity();", timeout);
	else
		window.setTimeout(this.selfRef() + ".WaitLoading("+imageNumber+");", 500);
}


function StopAndChangeImage(imageNumber)
{
	var imageObject;
	imageObject=this.GetImage(imageNumber);
	if(this.imageIndex>=this.imagesVector.length)
		this.imageIndex=0;
		
	imageObject.src=this.imagesVector[this.imageIndex];
	this.SetLink(this.imageIndex++);
	if((this.imageTimeOutHigh==-1) || (this.imageTimeOutLow==-1))
		this.lastImage=imageNumber;
	else
		this.WaitLoading(imageNumber);
}

function Resume()
{
	this.WaitLoading(this.lastImage);
}





/// util.js


function tsrPopUp(filePath,height,width,attributes)
{
 var sScreenX = screen.width
 var sScreenY = screen.height
 var x = sScreenX - width
 var y = sScreenY - height
 var winLeft = x/2
 var winTop =  y/2 
 window.open(filePath,"","width=" + width + ",height=" + height + "," + attributes + ",left=" + winLeft + ",top=" + winTop)
}



function ShowHide(htmlElement)
{
	if(htmlElement.style.display=='none')
		htmlElement.style.display='block';
	else
		htmlElement.style.display='none';
}

function ForceShowHide(htmlElement, type)
{
	if(type)
		htmlElement.style.display='block';
	else
		htmlElement.style.display='none';
}

function QueryValue(key, value)
{
	this.key=key;
	this.value=value;
}

function QueryStringEncapsulator()
{
	this.keyValue=new Array();
	this.Add=QueryStringEncapsulatorAdd;
	this.ToString=QueryStringEncapsulatorToString;
	this.KeyValueSeparator=".";
	this.KeyValueSeparatorHex="%7C";
	this.ValuesSeparator="|";
	this.ValuesSeparatorHex="%2E";
	
}

function QueryStringEncapsulatorAdd(key, value)
{
	this.keyValue[this.keyValue.length]=new QueryValue(key, value)
}


function QueryStringEncapsulatorToString()
{
	var i;
	var finalString="";
	var val;
	for(i=0; i<this.keyValue.length; i++)
	{
		val=this.keyValue[i].value;
		val=val.replace(this.KeyValueSeparator, this.KeyValueSeparatorHex);
		val=val.replace(this.ValuesSeparator, this.ValuesSeparatorHex);
		finalString+=this.keyValue[i].key + this.KeyValueSeparator + escape(val) + this.ValuesSeparator;
	}
	if(this.keyValue.length>0)
		finalString=finalString.substr(0, finalString.length-1);
	
	return finalString;
}



/********************************************************************************

Name: 				Flash embed
Description:		Writeout flash code. Fixes Eolas update for IE as well.
@param	swf		String path to swf file
@param	width		Number value of movie width
@param	height	Number value of movie height

*********************************************************************************/

flash = new Object();
flash.insert = function(swf,width,height) {
	flashObject = '<embed src="'+swf+'" menu="false" quality="high" width="'+width+'px" height="'+height+'px" wmode="transparent"  type="application/x-shockwave-flash" salign="T" pluginspage="http://www.macromedia.com/go/getflashplayer" />'
	document.write(flashObject);
}


/// mm.js

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


