/*
 *  Function rollPreload()
 *
 *  Carrega as imagens passadas como argumentos
 */
function rollPreload() {
   imagens = [];
   for (i = 0; i < arguments.length; i++) {
        imagens[i]     = new Image();
        imagens[i].src = arguments[i];
    }
}

/*
 *  Function rollOver(imagem)
 *
 *  Troca a nomeada como 'imagem.ext' por outra imagem nomeada como 'imagem_over.ext'
 *  Ex: apresentacao.gif por apresentacao_over.gif
 */
function rollOver(imagem) {
   imagem_split = imagem.src.split('/');
   imagem_src = imagem_split[imagem_split.length - 1].split('.');
   imagem_nome = imagem_src[0];
   imagem_extensao = imagem_src[1];
   imagem_split[imagem_split.length - 1] = imagem_nome + '_over.' + imagem_extensao;
   imagem.src = imagem_split.join('/');
}

/*
 *  Function rollOut(imagem)
 *
 *  Troca a nomeada como 'imagem_over.ext' por outra imagem nomeada como 'imagem.ext'
 *  Ex: apresentacao_over.gif por apresentacao.gif
 */
function rollOut(imagem) {
   imagem_split = imagem.src.split('/');
   imagem_src = imagem_split[imagem_split.length - 1].split('.');
   imagem_nome = imagem_src[0];
   imagem_extensao = imagem_src[1];
   imagem_split[imagem_split.length - 1] = imagem_nome.substring(0, imagem_nome.length - 5) + '.' + imagem_extensao;
   imagem.src = imagem_split.join('/');
}

/*
 *  Function openURL
 *
 *  Redireciona a página para o valor do select box
 *  Ex: openURL(this)
 */

function openURL(fieldname) { 
    var newIndex = fieldname.selectedIndex; 
    if (newIndex != 0) { 
        window.location.assign( fieldname.options[newIndex].value ); 
    }
}

function abreLayer(layerWidth, layerHeight, iframeUrl) {
    if (window.innerHeight && window.scrollMaxY) {	
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }

    if (self.innerHeight) {	// all except Explorer
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }	

    // for small pages with total height less then height of the viewport
    if (yScroll < windowHeight){
        pageHeight = windowHeight;
    } else { 
        pageHeight = yScroll;
    }

    // for small pages with total width less then width of the viewport
    if (xScroll < windowWidth){	
        pageWidth = windowWidth;
    } else {
        pageWidth = xScroll;
    }

    // container
    document.getElementById('layercontainer').style.top = '0px';
    document.getElementById('layercontainer').style.left = '0px';
    document.getElementById('layercontainer').style.width = pageWidth + 'px';
    document.getElementById('layercontainer').style.height = pageHeight + 'px';

    // content
    contentTop = 75;
    contentLeft = (pageWidth / 2) - (layerWidth / 2);

    document.getElementById('layercontent').style.top = contentTop + 'px';
    document.getElementById('layercontent').style.left = contentLeft + 'px';
    document.getElementById('layercontent').style.width = layerWidth + 'px';
    document.getElementById('layercontent').style.height = layerHeight + 'px';

    // close
    document.getElementById('layerclose').style.top = (contentTop + 10) + 'px';
    document.getElementById('layerclose').style.left = ((contentLeft + layerWidth) - 70) + 'px';
    document.getElementById('layerclose').style.width = '50px';
    document.getElementById('layerclose').style.height = '13px';

    // iframe layer
    document.getElementById('iframelayer').style.top = '0px';
    document.getElementById('iframelayer').style.left = '0px';
    document.getElementById('iframelayer').style.width = layerWidth + 'px';
    document.getElementById('iframelayer').style.height = layerHeight + 'px';

    // iframe content
    document.getElementById('iframecontent').style.width = layerWidth + 'px';
    document.getElementById('iframecontent').style.height = layerHeight + 'px';
    document.getElementById('iframecontent').src = iframeUrl;

    // visibilidade
    document.getElementById('layercontainer').style.visibility = 'visible';
    document.getElementById('layercontent').style.visibility = 'visible';
    document.getElementById('layerclose').style.visibility = 'visible';
}

function fechaLayer() {
    document.getElementById('layercontainer').style.visibility = 'hidden';
    document.getElementById('layercontent').style.visibility = 'hidden';
    document.getElementById('layerclose').style.visibility = 'hidden';
    document.getElementById('iframecontent').src = '';
}
