﻿function getPageSize() {
    var Imagem = arguments[0];    
          
	// PageWidth 

	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY)
	{
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} 
	else if (document.body.scrollHeight > document.body.offsetHeight)
	{
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else 
	{
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) 
	{
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} 
	else if (document.documentElement && document.documentElement.clientHeight) 
	{
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} 
	else if (document.body) {
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	if(yScroll < windowHeight) pageHeight = windowHeight;
	else pageHeight = yScroll;
	
	if(xScroll < windowWidth) pageWidth = windowWidth;
	else pageWidth = xScroll;
	
	//arrayPageSize = {pageWidth:pageWidth,pageHeight:pageHeight,windowWidth:windowWidth,windowHeight:windowHeight}
	
	// Page Scroll
	var yScroll;
	if (self.pageYOffset) yScroll = self.pageYOffset;
	else if (document.documentElement && document.documentElement.scrollTop) yScroll = document.documentElement.scrollTop;
	else if (document.body) yScroll = document.body.scrollTop;

	//arrayPageScroll = {yScroll:yScroll};
	//alert(pageWidth +"-"+ pageHeight + "|"+ windowWidth + "-"+ windowHeight +"|"+ yScroll);

	
	var d = document.getElementById("diContainer");
	switch(d.style.display)
	{
		case "none":
			HiddeShowSelect("hidde");
			if(!arguments[1])
			{
			    ShowAmpliada(1);
			}
			else
			{
			    ShowEnvia(1);
			}
			d.style.width = (pageWidth - 20) + "px";
			d.style.height = pageHeight + "px";
			w3Opacity.set(d.id,0);
			w3Opacity.fading(d.id,0,50,500);
			d.style.display = '';
			break;
		default:
			HiddeShowSelect("show");
			d.style.display = 'none';
			if(!arguments[1])
			{
			    ShowAmpliada(2);
			}
			else
			{
			    ShowEnvia(2);
			}
			break;
}
	alert(Imagem)
	
    try
    {
      BackGo(Imagem);   
   }
    catch(e){alert(e);}
}

function HiddeShowSelect()
{
	var d = document.getElementsByTagName("select");
	var i;
	
	for(i = 0; i < d.length; i++)
	{
		d[i].setAttribute("style","");
		switch(arguments[0])
		{
			case "hidde": d[i].style.display = 'none'; break;
			case "show": d[i].style.display = ''; break;
		}
	}
}

function ShowAmpliada()
{
	var div = document.getElementById('ampliada');
	switch(arguments[0])
	{
		case 1:
			w3Opacity.set(div.id,0);
			w3Opacity.fading(div.id,0,100,500);
			div.style.display = "";
			break;
		case 2:
			div.style.display = "none";
			break;
	}
}

function ShowEnvia()
{
	var div = document.getElementById('amigo');
	switch(arguments[0])
	{
		case 1:
			w3Opacity.set(div.id,0);
			w3Opacity.fading(div.id,0,100,500);
			div.style.display = "";
			break;
		case 2:
			div.style.display = "none";
			break;
	}
}

function BackGo()
{
    var Imagem = arguments[0];
    
	var Box = document.getElementById("boxRelacionada");
    var Rlac = document.getElementById("ListaRelacionadas");
    var NXB = document.getElementById("NextBack");
    var Link = document.getElementById("hrefAmigo");
	var Info = document.getElementById("info");
	var Desc = document.getElementById("Descricao");
    
    Rlac.innerHTML = "";
	Info.innerHTML = "";
	Desc.innerHTML = "";
    Link.href = "";
	Box.style.display = "none";

    ImagemShow = myImagens[Imagem].split(',');
    Relacionada = Relacao[Imagem].split(',');
    
	Link.href = "showroom.aspx?amigo="+ ImagemShow[0] +"&ex="+ ImagemShow[3];
	
	Info.innerHTML = ImagemShow[4];
	Desc.innerHTML = ImagemShow[5];
    
	var BoxShow = false;
	for (var Relaciona in Relacionada) 
    {    
		var Ar = Relacionada[Relaciona].split(';');
		Rlac.innerHTML += "<div class=\"tbm\" ><a href=\"/kit.aspx?Query=ProductPage&ProdTypeId="+ Ar[2] +"&ProdId="+ Ar[3] +"\">"+ Ar[0] + "<br /><img src=\""+ Ar[1] +"\"></a></div>";
		if(Ar[0].length > 0)
		{
			BoxShow  = true;
		}
    }
	
	if(BoxShow)
	{
		Box.style.display = "";
	}
    
    var back = eval(arguments[0]) - 1;
    var next = eval(arguments[0]) + 1;
    
    if(back < 0)
	{
        back = eval(myImagens.length) - 1;
	}
    
    if(next == myImagens.length)
	{
        next = 0;      
	}
    
    if(myImagens.length > 1)
    {        
      NXB.innerHTML = "<span style=\"cursor:pointer\" onclick=\"BackGo("+ back +")\" >« anterior </span> | <span style=\"cursor:pointer\" onclick=\"BackGo("+ next +")\" >próxima »</span>"
    }
	
	var GImg = document.getElementById("Fotos");
	var WaitI = document.getElementById("WaitImg");
	GImg.style.display = "none";
	WaitI.style.display = "";

	GImg.src = "arquivos/galeria/" + ImagemShow[0] + "_" + ImagemShow[3];	
	GImg.setAttribute('width',ImagemShow[1]);
	GImg.setAttribute('height',ImagemShow[2]);
	GImg.onload = new Function("Show(this)");
}

function Show()
{
	var Waiti = document.getElementById("WaitImg");
	Waiti.style.display = "none";
	arguments[0].style.display = "";
}
