﻿/* -----------------------------------------------
   Floating layer - v.1
   (c) 2006 www.haan.net
  ------------------------------------------------ */
//id do div que aparece como popup
var idDiv='layer1';
var x = 150;
var isGalleryOpen = false;
//o documento pode ainda nao ter largura
try
{
    x = changeXCoord();
}
catch(err)
{
}

var y = 70;
//guarda o item com que ouve o over, para que se quando passar o timeout mostrat ai o popup
var idItem = 0;
function visualizaTimeout(conteudo,id)
{
    if (!isGalleryOpen)
    {
        idItem = id;
        setTimeout("visualiza(\"" + conteudo + "\",\"" + id + "\")",1500);
    }
}

function visualiza(conteudo,id)
{
    closeDiv(idDiv);
    
    //so mostra se o div estiver vazio, e se o temporizador tiver sido activado com este mesmo id
    if((document.getElementById(idDiv).innerHTML == '') && (idItem != 0) && (id == idItem))
    {
        
        changeDivContent(conteudo);
        changeXCoord();
        setVisible(idDiv,true);
        placeIt(idDiv);
        
        //como o div e o mesmo para a timeline e a galeria coloca-o no tamanho da galeria
        document.getElementById(idDiv).style.width = "620px";
    }
}

//visualiza um item multimedia
function visualizaMM(conteudo)
{
    isGalleryOpen = true;
    var divObj = document.getElementById(idDiv);
    var tableObj = document.getElementById(idDiv).firstChild;
    
    closeDiv(idDiv);

    
    setVisible(idDiv,true);
    divObj.style.width = "0px";
    changeDivContent(conteudo);
    changeXCoord();
    placeIt(idDiv);
}

function setDivWidth()
{
    var contentTableWidth = document.getElementById(idDiv).firstChild.scrollWidth;
    document.getElementById(idDiv).style.width = contentTableWidth + "px";   
}

function setVisible(obj)
{
	obj = document.getElementById(obj);
	obj.style.visibility = (obj.style.visibility == 'visible') ? 'hidden' : 'visible';
}
function placeIt(obj)
{
	obj = document.getElementById(obj);
	if (document.documentElement)
	{
		theLeft = document.documentElement.scrollLeft;
		theTop = document.documentElement.scrollTop;
	}
	else if (document.body)
	{
		theLeft = document.body.scrollLeft;
		theTop = document.body.scrollTop;
	}
	theLeft += x;
	theTop += y;
	
	//so actualiza se necessario, para nao "piscar" no firefox
    if (obj.style.visibility == 'visible')
    {
        obj.style.top = theTop + 'px';
        obj.style.left = theLeft + 'px';
    }
}

//o que faz quando fazemos scroll
function scrollEvent()
{
    window.onscroll = function(){
        if ((document.getElementById(idDiv) != "null") && (document.getElementById(idDiv).style.visibility == 'visible'))
        {
            self.setTimeout("self.placeIt('" + idDiv + "')",500)
        }
    };
}

//no ie6 da erro mas funciona, assim ja evita o erro
try
{
        scrollEvent();
}
catch(err)
{
//Handle errors here
}

/*altera o conteudo do div*/
function changeDivContent(content)
{
    obj = document.getElementById(idDiv);
    obj.innerHTML = content
}

function getWidth()
{
    var winW;
    //var winH;

    if (parseInt(navigator.appVersion)>3) 
    {
     if (navigator.appName=="Netscape") 
     {
      winW = window.innerWidth;
      //winH = window.innerHeight;
     }
     if (navigator.appName.indexOf("Microsoft")!=-1) 
     {
      winW = document.body.offsetWidth;
      //winH = document.body.offsetHeight;
     }
    }

    return winW;
}

//altera a posicao x, tenta colocar ao centro
function changeXCoord()
{
    //var larguraDiv = 600
    var larguraDiv = document.getElementById(idDiv).scrollWidth;
    x = (getWidth() / 2) - (larguraDiv / 2);
    return x;
}

function closeDiv(obj)
{
    obj = document.getElementById(obj);
    obj.style.visibility = 'hidden';
    obj.innerHTML = '';
}

//fecha o div quando estamos a ver uma galeria, para que afectemos isGalleryOpen,
//com o objectivo de manter o popup da galeria aberto quando passamos por uma timeline 
function closeGalleryDiv(obj)
{
    closeDiv(obj);
    isGalleryOpen = false;
}
