// JavaScript Document
function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}


//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 

function hb_Hide_PopPup(hbID)
{
 id=hbID; 
 opacStart=100; opacEnd=0.5; millisec=500;
 opacity(id, opacStart, opacEnd, millisec);
 //t1=setTimeout('document.getElementById(id).style.display="none"',1000);
 //t1=setTimeout('document.getElementById(id).style.display="block";opacity(id, opacStart, opacEnd, millisec)',0);
}

function hb_Show_PopPup(hbID)
{
 id=hbID; 
 //id='noteEditor';
 opacStart=0.5; opacEnd=100; millisec=500;
 opacity(id, opacStart, opacEnd, millisec);
 t1=setTimeout('document.getElementById(id).style.display="block";opacity(id, opacStart, opacEnd, millisec)',0);
};


rotator=function()
{
	this.hitems= null;
	this.selected=0;
	this.previous=null;
	this.next=null;
	this.containerID='mainArticle';
	this.OK=false;
	this.container=null;
	this.showAthomathic=true;
	this.QQ=0;
}

rotator.prototype.init=function()
{
	if (document.getElementById(this.containerID))
	{
		this.OK=true;
		this.container=document.getElementById(this.containerID);
		
	}
	else
	{
		this.OK=false;	
	}
	if (!this.OK) 
	 {
		 alert('the container layer for rotator is missing');
	 }
	else
	 {
		this.getItems();
		var randomnumber=Math.floor(Math.random()*this.QQ);
		if (this.OK)
		{
			//this.hideItem(this.selected);
			//this.showItem(1);			
		}
	 }
}

rotator.prototype.getItems=function()
{
	if (this.OK)
	{
		this.hitems=this.container.getElementsByTagName('div');
		this.OK=true;
		if (this.hitems.length<=2)
		 {
			 this.OK=false;
			 if (this.hitems.length==2)
			 {
				 this.hitems[0].style.display='block';
				 this.hitems[1].style.display='none';
			 }
		 }
		if (this.OK)
		{
			this.QQ=this.hitems.length-2;
			for (i=1; i<=this.QQ; i++)
			 {	
				this.hitems[i].style.display='none';
				this.hitems[i].style.top='0px';
				this.hitems[i].style.zoom=1;
			 }
		}
	}
	
}

/*functions for rotator*/
rotator.prototype.showNextItem=function(evnt)
{
 if (this.OK)
  {
	if((evnt!=null)&&(this.showAthomathic))
	 {
		 alert('You should turn Auto OFF');
	 }
	else
	{
		this.hideItem(this.selected);
		this.selected++;
		if (this.selected>this.QQ)
		 {
			this.selected=0; 
		 }
		this.showItem(this.selected);
	}
   }
}

rotator.prototype.showPreviousItem=function(evnt)
{
  if (this.OK)
   {
	if((evnt!=null)&&(this.showAthomathic))
	 {
		 alert('You should turn Auto OFF');
	 }
	else
	 {
		this.hideItem(this.selected);
		this.selected--;
		if (this.selected<0)
		 {
			this.selected=this.QQ;
		 }
		this.showItem(this.selected); 
	 }
   }
}
/*end functions for rotator*/

/*functions for show and hide*/
rotator.prototype.showItem=function(itemToShow)
{

	if ((this.OK) && (itemToShow!=null) && ((typeof itemToShow)=='number'))
	{
		//this.hitems[itemToShow].style.display='block';
		
		this.selected=itemToShow;
		//hb_Show_PopPup(this.hitems[itemToShow].id);
		idToshow=this.hitems[itemToShow].id;
		t1=setTimeout("hb_Show_PopPup(idToshow)",1000);
	}
	else
	{
		this.OK=false;
		alert('the value within showItem function is not valid');
	}
}

rotator.prototype.hideItem=function(itemToHide)
{

	if ((this.OK) && (itemToHide!=null) && ((typeof itemToHide)=='number'))
	{
		//this.hitems[itemToHide].style.display='none';
		hb_Hide_PopPup(this.hitems[itemToHide].id);
		
	}
	else
	{
		this.OK=false;
		alert('the value within hideItem function is not valid');
	}
}
/*end functions for show and hide*/


function doAutomatic()
{
	oRotator.showNextItem();
	oRotator.showAthomathic=true;
	hbTimer=setTimeout("doAutomatic()",10000);
}

function stopAutomatic()
{
	clearTimeout(hbTimer);
	oRotator.showAthomathic=false;
}

function switchAuto(elem)
{
	//alert((oRotator.showAthomathic)?'Automatic':'No Automatic');
	if (oRotator.showAthomathic)
	{
		
		stopAutomatic();
		//cambiar el texto para 'Auto On'
		elem.innerHTML='&nbsp;AUTO IS OFF&nbsp;';
		//activar botones the previous and next
	}
	else
	{
		//Cambiar texto para Auto Off
		elem.innerHTML='&nbsp;AUTO IS ON&nbsp;';
		//desactivar botones
		doAutomatic();
	}
}


var hbTimer;
oRotator=new (rotator);


