
var StopTop=0;
var intervalId=0;
var CurrentHeight=0;
var LastHeight=0;
var i=1;
var currentPage=0;
var TotalPages=0;
var CurrentVideo="";
var LastActive="0";
function ShowPlay(object)
{
object.childNodes[0].style.visibility='visible';
}

function HiddePlay(object)
{
object.childNodes[0].style.visibility='hidden';
}

function advancePage(pageindex,id,height,direction,fromPage)
{   var sepuede=false;
    if(intervalId==0)
    {  
     
     //miramos si se puede depende de si viene de flecha o pagina
    if(fromPage==true)
    { if(currentPage<TotalPages)
        {sepuede=true;}}
    else
    {if(parseInt(currentPage+1)<TotalPages)
        { sepuede=true;}}
        
        
        if(sepuede==true)
        {
            var GalleryDiv= document.getElementById(id);
            var MaxHeight= parseInt(GalleryDiv.style.height);
            StopTop= parseInt(LastHeight) - parseInt(height);
            LastHeight=StopTop;
            if(Math.abs(MaxHeight)<Math.abs(StopTop))
            {return false;}
            if(fromPage==false)
            {currentPage=currentPage+1;}
			
			if(pageindex=="-1")
			{
				pageindex=parseInt(LastActive)+1;
			}
			//Cambiamos la pagina activa
			document.getElementById(LastActive).className="";
			LastActive=pageindex;
			document.getElementById(pageindex).className="page-nav-active";

            intervalId=setInterval('MoveDiv(\''+id+'\','+height+',\''+direction+'\',\''+pageindex+'\')',20);
        }
    }
}



function ForwardPage(pageindex,id,height,direction,fromPage)
{   
    if(intervalId==0)
    {
        if(currentPage>0 || ((currentPage==0) && (fromPage==true)))
        {
            var GalleryDiv= document.getElementById(id);
            StopTop= parseInt(LastHeight) + parseInt(height);
            LastHeight=StopTop;
            if(fromPage==false)
            {currentPage=currentPage-1;}
			if(pageindex=="-1")
			{
				pageindex=parseInt(LastActive)-1;
			}
			//Cambiamos la pagina activa
			document.getElementById(LastActive).className="";
			LastActive=pageindex;
			document.getElementById(pageindex).className="page-nav-active";


            intervalId=setInterval('MoveDivDown(\''+id+'\','+height+',\''+direction+'\',\''+pageindex+'\')',20);
        }
    }
}
function MoveDiv(id,height,direction,pageindex)
{   
    
    var GalleryDiv= document.getElementById(id);
    i=i+1;
    
    
    CurrentHeight=CurrentHeight-((height/(parseInt(GalleryDiv.style[direction].length+(i*1)))));
   
    //CurrentHeight=LastHeight-((LastHeight/(parseInt(GalleryDiv.style[direction].length+(i*2)))));
    GalleryDiv.style[direction]=CurrentHeight+"px";
    if(parseInt(CurrentHeight)<=StopTop)
    {   
      
        GalleryDiv.style[direction]=StopTop+"px";
        clearInterval(intervalId);
		
        intervalId=0;
        i=1;
        return;
    }
}

function MoveDivDown(id,height,direction,pageindex)
{
     var GalleryDiv= document.getElementById(id);
    i=i+1;
    CurrentHeight=CurrentHeight+(((parseInt(GalleryDiv.style[direction].length/height+(i*2)))));
   // CurrentHeight=LastHeight+((LastHeight/(parseInt(GalleryDiv.style[direction].length+(i*2)))));
    if(CurrentHeight>0)
    {CurrentHeight=0;}
    GalleryDiv.style[direction]=CurrentHeight+"px";

    if(parseInt(CurrentHeight)>=StopTop || CurrentHeight==0)
    {   
        
        GalleryDiv.style[direction]=StopTop+"px";
        
        clearInterval(intervalId);
		
        intervalId=0;
        i=1;
        return;
    }
}


function Pagination(MoveLenght,divName,direction)
{
    var pageBrowser=document.getElementById('PageBrowser');
    
    
    
    var TotalAlto=document.getElementById(divName).offsetHeight;
    TotalPages=parseInt(TotalAlto)/MoveLenght;
    //alert(TotalPages);
    var OutPut="";
    var x=0;

    for(x=0;x<TotalPages;x++)
    {
        OutPut+="<a  id=\""+x+"\"  onclick=\"CheckPage("+x+",'"+divName+"',"+(MoveLenght)+",'"+direction+"');\"> "+parseInt(x+1)+"</a>";
    }
    TotalPages=x;
    pageBrowser.innerHTML=OutPut;
}

function CheckPage(pageindex,id,height,direction)
{
    if(intervalId==0)
    {   
        if(currentPage!=pageindex)
        {
            var diff=0;
            if(parseInt(pageindex)<currentPage)
            {
                diff=currentPage-pageindex;
                currentPage=parseInt(pageindex);
                ForwardPage(pageindex,id,(height*diff),direction,true)
            }
            else
            {
                diff=pageindex-currentPage;
                currentPage=parseInt(pageindex);
                advancePage(pageindex,id,(height*diff),direction,true)
            }
        }
    }


}

function changeStatusClose(object)
{
    object.className=object.className+"_over";
}
function RestoreStatusClose(object)
{
    object.className=object.className.replace('_over','');
}



