/**
 * Find the element in the current HTML document with the given id or ids
 * @see http://getahead.ltd.uk/dwr/browser/util/$
 */
var $;
if (!$ && document.getElementById) {
  $ = function() {
    var elements = new Array();
    for (var i = 0; i < arguments.length; i++) {
      var element = arguments[i];
      if (typeof element == 'string') {
        element = document.getElementById(element);
      }
      if (arguments.length == 1) {
        return element;
      }
      elements.push(element);
    }
    return elements;
  }
}
else if (!$ && document.all) {
  $ = function() {
    var elements = new Array();
    for (var i = 0; i < arguments.length; i++) {
      var element = arguments[i];
      if (typeof element == 'string') {
        element = document.all[element];
      }
      if (arguments.length == 1) {
        return element;
      }
      elements.push(element);
    }
    return elements;
  }
}

var ALTURA_FOTO = 700;

function zoomMundoIn()
{
	getAjax('ondeEstouTudo.html', 'divTudoHidden');
	$('divTudo').style.display = "none";
	$('divTudoHidden').style.display = "block";
}

var zoomFotoScrollY = 0;

var maxNumFoto = 1;
var numFoto = 1;
var pathFoto = "";
function zoomFotoIn_v2(pFoto, pMaxNumFoto)
{
	zoomFotoScrollY = document.body.scrollTop;
	maxNumFoto = pMaxNumFoto;

    innerHTMLFoto = "<img id='fotoZoom' src='" + pFoto + "' height='" + ALTURA_FOTO + "' title='Zoom -' class='hand'  border='2' onclick='javascript:zoomOut()'>"
	$('divTudoHidden').innerHTML = innerHTMLFoto;

	$('divTudo').style.display = "none";
	$('divTudoHidden').style.display = "block";
	$('divFotoNavig').style.display = "block";

    // adicionar o comentário da foto
	actualFoto = $('fotoZoom').src;
	pos = 0;
	while(actualFoto.indexOf("f", pos + 1) > 0)
		pos = actualFoto.indexOf("f", pos) + 1;

	pathFoto = actualFoto.substring(0, pos);
	numFoto = actualFoto.substring(pos, actualFoto.indexOf(".", pos));

	if ($('coment' + numFoto))
		novaFoto = innerHTMLFoto + "<br><font class='textoFoto_v2'>" + $('coment' + numFoto).innerHTML + "</font>";

	$('divTudoHidden').innerHTML = novaFoto;

    // links para foto anterior e foto próxima
	if (numFoto == 1)
	{
		$('linkPrevFoto').style.filter = "alpha(opacity=50)";
		$('linkPrevFoto').style.opacity = 0.5;
		$('linkPrevFoto').className = "";

		$('linkNextFoto').style.filter = "";
		$('linkNextFoto').style.opacity = 1;
		$('linkNextFoto').className = "hand";
	}
	else if (numFoto == maxNumFoto)
	{
		$('linkPrevFoto').style.filter = "";
		$('linkPrevFoto').style.opacity = 1;
		$('linkPrevFoto').className = "hand";

		$('linkNextFoto').style.filter = "alpha(opacity=50)";
		$('linkNextFoto').style.opacity = 0.5;
		$('linkNextFoto').className = "";
	}
	else
	{
		$('linkPrevFoto').style.filter = "";
		$('linkPrevFoto').style.opacity = 1;
		$('linkPrevFoto').className = "hand";

		$('linkNextFoto').style.filter = "";
		$('linkNextFoto').style.opacity = 1;
		$('linkNextFoto').className = "hand";
	}

	document.body.scrollTop = 0;
}

function prevFoto()
{
	if (numFoto > 1)
	{
		numFoto --;
		if (numFoto == 1)
		{
			$('linkPrevFoto').style.filter = "alpha(opacity=50)";
			$('linkPrevFoto').style.opacity = 0.5;
			$('linkPrevFoto').className = "";
		}
		else
		{
			if (numFoto < maxNumFoto)
			{
				$('linkNextFoto').style.filter = "";
				$('linkNextFoto').style.opacity = 1;
				$('linkNextFoto').className = "hand";
			}
		}
		novaFoto = "<img id='fotoZoom' src='" + pathFoto + numFoto + ".jpg' height='" + ALTURA_FOTO + "' title='Zoom -' class='hand'  border='2' onclick='javascript:zoomOut()'>";
		if ($('coment' + numFoto))
			novaFoto += "<br><font class='textoFoto_v2'>" + $('coment' + numFoto).innerHTML + "</font>";

		$('divTudoHidden').innerHTML = novaFoto;
	}
}

function nextFoto()
{
	if (numFoto < maxNumFoto)
	{
		numFoto ++;
		if (numFoto == maxNumFoto)
		{
			$('linkNextFoto').style.filter = "alpha(opacity=50)";
			$('linkNextFoto').style.opacity = 0.5;
			$('linkNextFoto').className = "";
		}
		else
		{
			if (numFoto > 1)
			{
				$('linkPrevFoto').style.filter = "";
				$('linkPrevFoto').style.opacity = 1;
				$('linkPrevFoto').className = "hand";
			}
		}
		novaFoto = "<img id='fotoZoom' src='" + pathFoto + numFoto + ".jpg' height='" + ALTURA_FOTO + "' title='Zoom -' class='hand'  border='2' onclick='javascript:zoomOut()'>";
		if ($('coment' + numFoto))
			novaFoto += "<br><font class='textoFoto_v2'>" + $('coment' + numFoto).innerHTML + "</font>";
		
		$('divTudoHidden').innerHTML = novaFoto;
	}
}

function zoomOut()
{
	$('divFotoNavig').style.display = "none";
	$('divTudoHidden').style.display = "none";
	$('divTudo').style.display = "block";
	document.body.scrollTop = zoomFotoScrollY;
}

function showPopupDiv(divElementId)
{
	document.body.scrollLeft = 0;
	document.body.scrollTop = 0;

    $("popupBackground").style.display="block";
    $(divElementId).style.display="block";

    var largTela =  Math.floor(document.body.clientWidth);
	var largDiv = Math.floor($(divElementId).offsetWidth);
	var altTela = document.body.clientHeight;
	var altDiv = Math.floor($(divElementId).offsetHeight);

    $("popupBackground").style.height=document.body.scrollHeight+"px";
    $("popupBackground").style.width=(largTela < 986 ? 986 : largTela)+"px";

    $(divElementId).style.left=((largTela/2)-(largDiv/2))+"px";
    $(divElementId).style.top=((altTela/2) - (altDiv/2))+"px";
}

function showPopupDivPage(pPage)
{
	$('divPopup').innerHTML = '';
	getAjax(pPage, "divPopup");
	showPopupDiv("divPopup");
	$('divPopup').style.top = '60px';
}

function closePopupDiv(divElementId)
{
    $(divElementId).style.display="none";
    $("popupBackground").style.display="none";
}

function imprime()
{
	$("divPagina").style.display="none";
	window.print();
	$("divPagina").style.display="block";
}

function _resizeFoto()
{
/*
    if ($('fotoZoom').offsetHeight > document.body.clientHeight - 50)// && $('fotoZoom').offsetWidth < 982)
	{
        alert('Largura da Foto: ' + $('fotoZoom').offsetWidth);
		$('fotoZoom').height = document.body.clientHeight - 50;
		return;
	}
	if ($('fotoZoom').offsetWidth > 982)
	{
		$('fotoZoom').width = 982;
		return;
	}
*/
}
