var id_menu = "album_menu" //ID do container das miniaturas
var id_legenda = "album_legenda" //ID do container das miniaturas

var id_nav = "album_nav" //ID da navegação
var id_img_principal = "fotop" // ID da foto principal
var imagens = ""
var legendas = "";
var stateDisabled = "style='cursor:pointer;filter:alpha(opacity=50);opacity:0.5;'";
var stateEnabled = "style='cursor:pointer;filter:alpha(opacity=100);opacity:1;'";
var srcFotoPrincipal = "<%=fullurl%>/imagens/produtos/media_";
var srcFotoMiniatura = "<%=fullurl%>/imagens/produtos/mini2_";
var vfotop = 0 //INDEX da foto atual


function criaNavegacao(){
	obj = document.getElementById(id_nav)
	obj.innerHTML += "<img src='imagens/anterior.gif' style='cursor:pointer' onclick=\"anteriorImagem(img);\"  /> &nbsp;"
	obj.innerHTML += "<img src='imagens/proximo.gif' onclick=\"proximaImagem(img); \"  style='cursor:pointer' />"
}

function inicializaFotoPrincipal(arrayIMG){
	obj = document.getElementById(id_img_principal)
	obj.src = srcFotoPrincipal + arrayIMG[0];
	obj.className = arrayIMG[0];
	document.getElementById(id_legenda).innerHTML = leg[0] 
}

function inicializaAlbum(arrayIMG){
	criaMiniaturas(arrayIMG)
	criaNavegacao()
	inicializaFotoPrincipal(arrayIMG)

}

function imageEnabled(obj){
	obj.style.filter = "alpha(opacity=100)"
	obj.style.opacity = "1";
}		

function imageDisabled(obj){
	obj.style.filter = "alpha(opacity=50)"
	obj.style.opacity = "0.5";
}

function criaMiniaturas(arrayIMG){
	
	obj = document.getElementById(id_menu)
	for (i=0;i<arrayIMG.length-1;i++){
		str = ""
		if(vfotop == i ){
			str += stateEnabled;
		}else{
			str += stateDisabled;
		}
	
		obj.innerHTML += "<img title='"+leg[i]+"' onclick=\"trocaImagem('"+arrayIMG[i]+"',"+i+",this)\" "+str+" class='"+arrayIMG[i]+"' src='"+srcFotoMiniatura+arrayIMG[i]+"' height='45' width='50' hspace='1' vspace='1'> ";
		
	}

}

function trocaImagem(arquivo,index,obj){
	document.getElementById(id_img_principal).src=srcFotoPrincipal+arquivo;
	document.getElementById(id_legenda).innerHTML = leg[index] 
	vfotop=index;
	
	setEnabled(obj);
}

function proximaImagem(arrayIMG,maxIndex){
	if(vfotop<arrayIMG.length-2){vfotop += 1}
	document.getElementById(id_img_principal).src = srcFotoPrincipal + arrayIMG[vfotop];
	document.getElementById(id_legenda).innerHTML = leg[vfotop] 
	setEnabledByIndex(vfotop);
	
}

function anteriorImagem(arrayIMG){
	if(vfotop!=0){vfotop -= 1}
	document.getElementById(id_img_principal).src = srcFotoPrincipal + arrayIMG[vfotop];
	document.getElementById(id_legenda).innerHTML = leg[vfotop] 
	setEnabledByIndex(vfotop);
}
function setEnabledByIndex(index){
	objs = document.getElementById(id_menu).getElementsByTagName("img");
	for(i=0;i<=objs.length;i++){
		if(objs[i]){
			if(i==index){
				imageEnabled(objs[i]);
			}else{
				imageDisabled(objs[i]);
			}
		}
	}
}		

function setEnabled(obj){
	objs = document.getElementById(id_menu).getElementsByTagName("img");
	for(i=0;i<=objs.length;i++){
		if(objs[i]){
			imageDisabled(objs[i]);
		}
	}
	imageEnabled(obj);
}		
		
var t1
var fade = 0;
var velocidade = 50

function mostrar(id){
	//MM_swapImage('Image10','','imagens/menu07a.jpg',1)
	obj = document.getElementById(id)
	obj.style.display =""
	if(fade < 100){
		
		fade += velocidade
		obj.style.opacity = fade/100;
		obj.style.filter="Alpha(opacity="+fade+",finishOpacity=100, startX=0)';"
		setTimeout("mostrar('"+id+"')",0)
	}else{
	
	}

}
function ocultar(id){
	//MM_swapImgRestore()
	obj = document.getElementById(id)
	if (fade!=0){
		
		fade -= velocidade
		obj.style.filter="Alpha(opacity="+fade+", finishOpacity=0, startX=100)';"
		obj.style.opacity = fade/100;
		if (fade==0){
			obj.style.display="none"
		}
		setTimeout("ocultar('"+id+"')",0)

	}else{
		obj.style.display="none"
		obj.style.filter="Alpha(opacity=0)';"
		obj.style.opacity = 0;
	}
}

function maximoCheckboxarCheckbox(nome, maximoCheckbox){
    for (var i=0; i<nome.length; i++){
        nome[i].onclick=function(){
        var num_marcados=0;
        for (var i=0; i<nome.length; i++)
            num_marcados+=(nome[i].checked)? 1 : 0
        if (num_marcados>maximoCheckbox){
            alert("O número máximo de elementos que podem ser selecionados é "+maximoCheckbox);
            this.checked=false;
            }
        }
    }
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function maximoCheckboxarCheckbox(nome, maximoCheckbox){
    for (var i=0; i<nome.length; i++){
        nome[i].onclick=function(){
        var num_marcados=0;
        for (var i=0; i<nome.length; i++)
            num_marcados+=(nome[i].checked)? 1 : 0
        if (num_marcados>maximoCheckbox){
            alert("O número máximo de elementos que podem ser selecionados é "+maximoCheckbox);
            this.checked=false;
            }
        }
    }
}

	function oculta(){
    document.getElementById('menu').style.visibility='hidden';
	}

	function mostra(){
    document.getElementById('menu').style.visibility='visible';
	}
