﻿var Akan = new Object();
//-----------------------------------------------------------------------------------
function ShowButton(PpcID, PboShow)
{	var oBtn;

	oBtn = document.getElementById(PpcID);
	if (!GboIsMSIE)
	{	if (PboShow && oBtn.src.indexOf('2.png') != -1) return;
	}
	if (oBtn.m_bOver == null) oBtn.m_bOver = 0;
	
	if (PboShow) oBtn.m_bOver++;
	else  oBtn.m_bOver--;
	if (oBtn.m_bOver == PboShow)
	{	if (!GboIsMSIE6)
		{	if (PboShow) oBtn.src = oBtn.src.replace('1.png', '2.png');
			else oBtn.src = oBtn.src.replace('2.png', '1.png');
		}
		else
		{	if (PboShow) oBtn.style.filter = oBtn.style.filter.replace('1.png', '2.png');
			else oBtn.style.filter = oBtn.style.filter.replace('2.png', '1.png');
		}
	}
}
//-----------------------------------------------------------------------------------
function AkanShowPics(PiStep)
{	var pcPager;

	Akan.oImg.style.visibility = 'hidden';
	Akan.oImg.style.position = 'absolute';
	Akan.oImg.style.top = '-1000px';
	Akan.oImg.style.left = '-1000px';
	if (Akan.iCurrIndex != -1)
	{	Akan.oImg.style.width = '';
		Akan.oImg.style.height = '';
		if (PiStep > 0)
		{	Akan.iCurrIndex++;
			if (Akan.iCurrIndex >= Akan.ppcPaths.length) Akan.iCurrIndex = 0;
		}
		if (PiStep < 0)
		{	Akan.iCurrIndex--;
			if (Akan.iCurrIndex < 0) Akan.iCurrIndex = Akan.ppcPaths.length - 1;
		}
		pcPager = "Foto " + (Akan.iCurrIndex + 1) + " de " + Akan.ppcPaths.length;
		if (GboIsMSIE) Akan.oInfo.innerText = pcPager;
		else Akan.oInfo.textContent = pcPager;
		Akan.oImg.src = Akan.pcBaseDir + Akan.ppcPaths[Akan.iCurrIndex];
		if (Akan.ppcPaths.length > 1) Akan.oImg.title = pcPager + "\nClique para avançar";
	}
}
//-----------------------------------------------------------------------------------
function AkanPicResize()
{	var dWidth = parseInt(Akan.oImg.offsetWidth);
	var dHeight = parseInt(Akan.oImg.offsetHeight);
	var dScale = Math.min(Akan.iMaxWidth / dWidth, Akan.iMaxHeight / dHeight);
	
	if (dScale < 1)
	{	Akan.oImg.style.width = Math.floor(dScale * dWidth);
		Akan.oImg.style.height = Math.floor(dScale * dHeight);
	}
	Akan.oImg.style.visibility = 'visible';
	Akan.oImg.style.position = Akan.oImg.style.left = Akan.oImg.style.top = '';
}
//-----------------------------------------------------------------------------------
function AkanShowPicsInit()
{	Akan.oImg = document.getElementById("m_oImg");
	Akan.oInfo = document.getElementById("m_oLPagerInfo");
	if (Akan.pcPaths != null)
	{	Akan.ppcPaths = Akan.pcPaths.split(',');
		if (Akan.ppcPaths != null)
		{ if (Akan.ppcPaths.length > 0) Akan.iCurrIndex = 0;
			if (Akan.ppcPaths.length > 1) Akan.oImg.style.cursor = "hand";
			else
			{ document.getElementById(Akan.pcTRImgID).style.visibility = "hidden";
				Akan.oImg.onclick = null;
			}
		}
	}
	AkanShowPics(0);
}
//-----------------------------------------------------------------------------------
function AkanThumbResize(PoImg, PiMaxWidth, PiMaxHeight, Pbo1Pass)
{	var dWidth = parseInt(PoImg.offsetWidth);
	var dHeight = parseInt(PoImg.offsetHeight);
	var dScale = Math.min(PiMaxWidth / dWidth, PiMaxHeight / dHeight);
	
	if ((dWidth != 0) && (dHeight != 0))
	{	if (dScale < 1)
		{	PoImg.style.width = Math.floor(dScale * dWidth);
			PoImg.style.height = Math.floor(dScale * dHeight);
		}
		PoImg.style.visibility = 'visible';
		PoImg.style.position = PoImg.style.left = PoImg.style.top = '';
		PoImg.boOK = 1;
	}
	else if (Pbo1Pass)
	{	if (Akan.oIDs == null) Akan.oIDs = new Array();
		Akan.oIDs.push(PoImg);
		PoImg.iMaxWidth = PiMaxWidth;
		PoImg.iMaxHeight = PiMaxHeight;
	}
}
//-----------------------------------------------------------------------------------
function RetryThumbResize()
{	var i, oImg, boDone;
	
	if (Akan.oIDs != null)
	{	boDone = 1;
		for (i = 0; i < Akan.oIDs.length; i++)
		{	oImg = Akan.oIDs[i];
			if (oImg.boOK != 1) AkanThumbResize(oImg, oImg.iMaxWidth, oImg.iMaxHeight, false);
			if (oImg.boOK != 1) boDone = 0;
		}
		if (boDone == 0) setTimeout(RetryThumbResize, 500);
	}
}