// JavaScript Document

/*
Desenvolvido por:
	Oscar Guelfi
	oscar.guelfi@gmail.com
Data: 23/11/2010
Versão: v1.0
*/

var panelbox = {
	start_indices: function(id)
	{		
		try { 
			clearTimeout(timer); 
		} catch(err) { };
	
		try { 
			panelBoxSpeed = panelBoxSpeed; 
		} catch(err) {panelBoxSpeed = 15000;};
		
		try { 
			panelBoxIndices = panelBoxIndices; 
		} catch(err) {panelBoxIndices = true;};
		
		
		try { 
			panelBoxIndicesArray = panelBoxIndicesPosition.split(' '); 
			panelBoxIndicesPosition1 = panelBoxIndicesArray[0]; 
			panelBoxIndicesPosition2 = panelBoxIndicesArray[1];
		} catch(err) {
			panelBoxIndicesPosition1 = "bottom"; 
			panelBoxIndicesPosition2 = "right";
		};
		if(panelBoxIndicesPosition1==undefined || panelBoxIndicesPosition1==""){panelBoxIndicesPosition1 = "bottom"};
		if(panelBoxIndicesPosition2==undefined){panelBoxIndicesPosition2 = "right"};
		
		try { 
			panelBoxNavigation = panelBoxNavigation; 
		} catch(err) {panelBoxNavigation = true;};
				
		try { 
			panelBoxImagePosition = panelBoxImagePosition; 
		} catch(err) {panelBoxImagePosition = "left";};
		
		try { 
			panelBoxImageAnime = panelBoxImageAnime; 
		} catch(err) {panelBoxImageAnime = true;};
		
		try { 
			panelBoxTransparencyAttribute = panelBoxTransparencyAttribute; 
		} catch(err) {panelBoxTransparencyAttribute = "width";};
		
		try { 
			panelBoxTransparencySize = panelBoxTransparencySize; 
			if (panelBoxTransparencySize==0)
				panelBoxTransparencySize = 100;
		} catch(err) {panelBoxTransparencySize = 100;};
		
		try { 
			panelBoxTransparencyPosition = panelBoxTransparencyPosition; 
		} catch(err) {panelBoxTransparencyPosition = "right";};
		
		try { 
			panelBoxTransparencyAnime = panelBoxTransparencyAnime; 
		} catch(err) {panelBoxTransparencyAnime = true;};
					
		//scrollIntervalID=0;
		//currentIndex=0;   					
					
		divPanelBox = document.getElementById("panel_box");
				
		divTag = document.createElement("div");
		divTag.id = "panel_box_indices";
		divTag.className="panel_box_indices";
		divPanelBox.appendChild(divTag);		
		
					
		q=document.getElementsByTagName("div")
		t=q.length;
		
		count=0;
		var niz = new Array();
		for(i=0;i<t;i++)
		{
			if((q[i].id).substr(0,15)=="panel_box_data_")
			{
				count++;
				qual=q[i].id;
				document.getElementById(qual).style.display="none";
				
				if (panelBoxIndices)
				{
					spanTag = document.createElement("span");
					spanTag.id = "panel_box_indice_"+count;
					spanTag.className ="panel_box_indice";
					spanTag.innerHTML = count;
					spanTag.recordKey = count;
					spanTag.onclick = function(){
						//alert(this.recordKey);
						panelbox.show_data(this.recordKey);
					};
					divTag.appendChild(spanTag);
				}				
							
				if(qual=="panel_box_data_"+id)
				{					
					document.getElementById(qual).style.display="block";
					
					document.getElementById("panel_box_image_"+id).style[panelBoxImagePosition]=0;
					
					getPainelBoxTitle = document.getElementById("panel_box_title_"+id).innerHTML;
					getPainelBoxText = document.getElementById("panel_box_text_"+id).innerHTML;
					
					if(getPainelBoxTitle!="" && getPainelBoxText!="")
					{
						document.getElementById("panel_box_transparency_"+id).style[panelBoxTransparencyPosition]=0;
						
						if(panelBoxTransparencyAttribute=="height")
							document.getElementById("panel_box_transparency_"+id).style.width="100%";
							
						if(panelBoxTransparencyAttribute=="width")
							document.getElementById("panel_box_transparency_"+id).style.height="100%";
					}
					else
						document.getElementById("panel_box_transparency_"+id).style.display="none";
				}
			}
			
			if (!panelBoxIndices)
				document.getElementById("panel_box_indices").style.display="none";
			else
			{
				document.getElementById("panel_box_indices").style[panelBoxIndicesPosition1]=0;
				document.getElementById("panel_box_indices").style[panelBoxIndicesPosition2]=0;
			}
				
			
		}
			
		if (panelBoxNavigation)
		{
			divPanelBox = document.getElementById("panel_box");
			
			divNav = document.createElement("div");
			divNav.id = "panel_box_navigation";
			divNav.className ="panel_box_navigation";
			divPanelBox.appendChild(divNav);
			
			divPrev = document.createElement("div");
			divPrev.id = "panel_box_previous";
			divPrev.className ="panel_box_previous";
			divNav.appendChild(divPrev);
			
			aPrev = document.createElement("a");
			aPrev.id="PanelBoxPrevious";
			aPrev.href = "#";
			aPrev.className ="panel_box_previous_lk";
			divPrev.appendChild(aPrev);
			
			divNext = document.createElement("div");
			divNext.id = "panel_box_next";
			divNext.className ="panel_box_next";
			divNav.appendChild(divNext);
			
			aNext = document.createElement("a");
			aNext.id="PanelBoxNext";
			aNext.href = "#";
			aNext.className ="panel_box_next_lk";
			divNext.appendChild(aNext);
		}
			
		if(count==1)
		{
			try { 
				divPrev = document.getElementById("panel_box_navigation");
				divPrev.style.display="none";	
			} catch(err) {};

			try { 
				divIndices = document.getElementById("panel_box_indices");
				divIndices.style.display="none";
			} catch(err) {};
		}
		else
			panelbox.show_data(id);
	},
		
	show_data: function(id)
	{
		cod = id;
		
		try { 
			clearTimeout(timer); 
		} catch(err) { };
		
		q=document.getElementsByTagName("div")
		t=q.length;
		
		count=0;
		for(i=0;i<t;i++)
		{
			if((q[i].id).substr(0,15)=="panel_box_data_")
			{
				count++;
				qual=q[i].id;
				document.getElementById(qual).style.display="none";
				
				if (panelBoxIndices)
				{				
					spanTag = document.getElementById("panel_box_indice_"+count);
					spanTag.className ="panel_box_indice";
				}
			}
		}
		
		divSpan = document.getElementById("panel_box_data_"+id);
		divSpan.style.display="block";	
		
		document.getElementById("panel_box_image_"+id).style[panelBoxImagePosition]=0;
		
		getPainelBoxTitle = document.getElementById("panel_box_title_"+id).innerHTML;
		getPainelBoxText = document.getElementById("panel_box_text_"+id).innerHTML;

		//alert(document.getElementById("panel_box_image_"+id).innerHTML);
		getContentBoxImage = panelbox.trim(document.getElementById("panel_box_image_"+id).innerHTML);
		//alert(getContentBoxImage);
		if(getContentBoxImage=="")
		{
			//document.getElementById("panel_box_transparency_"+id).style.width="100%";
			panelbox.stripeIn("panel_box_transparency_"+id, "100", panelBoxTransparencyAttribute,'%');
		}
		else
		{
			if(getPainelBoxTitle!="" && getPainelBoxText!="")
			{
				document.getElementById("panel_box_transparency_"+id).style[panelBoxTransparencyPosition]=0;
				
				if(panelBoxTransparencyAttribute=="height")
					document.getElementById("panel_box_transparency_"+id).style.width="100%";
					
				if(panelBoxTransparencyAttribute=="width")
					document.getElementById("panel_box_transparency_"+id).style.height="100%";
				
				if(panelBoxTransparencyAnime)
					panelbox.stripeIn("panel_box_transparency_"+id, panelBoxTransparencySize, panelBoxTransparencyAttribute,'px');
					
				//panelbox.Scroll(id,"panel_box_transparency_"+id);	
			}
			else
				document.getElementById("panel_box_transparency_"+id).style.display="none";
		}
			
		if(panelBoxImageAnime)
			panelbox.fadeIn("panel_box_image_"+id, 0.1);
		
		
		if (panelBoxIndices)
		{
			spanTag = document.getElementById("panel_box_indice_"+id);
			spanTag.className ="panel_box_indice panel_box_indice_visited";
		}		
		
		id++;		
		if(id>count)
			id=1;
		
		if (panelBoxNavigation)
		{
			aPrev = document.getElementById("PanelBoxPrevious");
			aPrev.recordKey = cod-1;
			aPrev.onclick = function(){
				panelbox.show_data(this.recordKey);
			};
			
			if(cod<=1)
				aPrev.style.display="none";
			else
				aPrev.style.display="block";
			
			aNext = document.getElementById("PanelBoxNext");
			aNext.recordKey = cod+1;
			aNext.onclick = function(){
				panelbox.show_data(this.recordKey);
			};
			
			if(cod>=count)
				aNext.style.display="none";
			else
				aNext.style.display="block";
		}
		
		timer=window.setTimeout("panelbox.show_data("+id+");", panelBoxSpeed);
	},
	
	fadeOut: function(id, time)
	{
		target=document.getElementById(id);
		alpha=100;
		chronometer=(time*1000)/50;
		var i=setInterval(
				function()
				{
					if (alpha <= 0)
						clearInterval(i);
					panelbox.setAlpha(target, alpha);
					alpha -= 5;
				}, chronometer);
	},
	
	fadeIn: function(id, time)
	{
		target=document.getElementById(id);
		alpha=0;
		chronometer=(time*1000)/50;
		var i=setInterval(
				function()
				{
					if (alpha >= 100)
						clearInterval(i);
					panelbox.setAlpha(target, alpha);
					alpha += 5;
				}, chronometer);
	},
	
	setAlpha: function(target, alpha)
	{
		target.style.filter="alpha(opacity="+ alpha +")";
		target.style.opacity=alpha/100;
	},
	
	stripeOut: function(id, size, attribute, opt)
	{
		targett=document.getElementById(id);
		sizeObj=100;	
		chronometerr=(0.1*1000)/50;
		var j=setInterval(
				function()
				{
					if (sizeObj >= size)
						clearInterval(j);
					panelbox.stripeSize(targett, sizeObj, attribute, opt);
					sizeObj -= size/5;
				}, chronometerr);
	},
	
	stripeIn: function(id, size, attribute, opt)
	{
		targett=document.getElementById(id);
		sizeObj=0;	
		chronometerr=(0.1*1000)/50;
		var j=setInterval(
				function()
				{
					if (sizeObj >= size)
						clearInterval(j);
					panelbox.stripeSize(targett, sizeObj, attribute, opt);
					sizeObj += size/5;
				}, chronometerr);
	},
			
	stripeSize: function(targett, size, attribute, opt)
	{
		targett.style[attribute]=size + opt;
	},
	
	trim: function(str)
	{
		return str.replace(/^\s+|\s+$/g,"");
	}

	
	/*,Scroll: function(ind,id)
	{
		dir = ind ==currentIndex?0:ind<currentIndex?-1:1;
		steps = Math.abs(ind-currentIndex);

		scrollIntervalID = setInterval(function(){
			i=(steps*10)-1;
			return function(){
				if (i <= 0) 
					clearInterval(scrollIntervalID);
				elm = document.getElementById(id);                   
				elm.scrollLeft +=dir * 50;
				i--;   

				document.getElementById("panel_slider").innerHTML=elm.scrollLeft;

			}
		}(), 15);
		currentIndex=ind;
	}*/ 
	
}
