var curpage=1;
var timer=null;
var stopped=true;
var imagesWidth=null;
var imagesHeight=null;
var slideHeight=0;
function rpb() 
{
    var obj=document.getElementsByName('pause');
    if (obj) 
    {
        for (i=0;i <= (obj.length-1);i++) 
        {
            obj[i].src="ext-funcway/editor/images/btn_pausa.gif";
        }
    }
}

function fnc_next_ie(x)
{
if(!x) {
    if (stopped)
    {rpb();}
    if (curpage == 0 || curpage>numpages)
    {curpage=1;}
    stop();
    var obj=document.getElementById('rota'+curpage);
      obj.style.filter="alpha(opacity=60)";
      timer=setTimeout('fnc_next_ie(1)',150);
/*} else if(x==1) {
    var obj=document.getElementById('rota'+curpage);
      obj.style.filter="alpha(opacity=20)";
      timer=setTimeout('fnc_next_ie(2)',120);
*/
} else {
    var obj=document.getElementById('rota'+curpage);
    obj.style.visibility = "hidden";
    obj.style.display = "none";
    obj.style.height = "1px";
    obj.style.zIndex = 1;
    obj.style.filter="alpha(opacity=100)";
    curpage++;
    if (curpage>numpages)
        curpage = 1;
    var obj=document.getElementById('rota'+curpage);
    obj.style.filter="alpha(opacity=0)";
    obj.style.visibility = "visible";
    obj.style.display = "block";
    obj.style.height = slideHeight +"px";
    var timer = 0;
    for(i = 0; i <= 100; i++) {
        setTimeout("opacity_ie('"+curpage+"',"+i+")",(timer * 15));
        timer++;
    }
    obj.style.filter="alpha(opacity=100)";
    start();
    }
}

function opacity_ie(rota,porc) {
    var _obj = document.getElementById('rota'+rota);
    _obj.style.filter="alpha(opacity="+porc+")";
}

function fnc_next(x)
{
    if(!x) {
    if (stopped)
    {rpb();}
    if (curpage == 0 || curpage>numpages)
    {curpage=1;}
    stop();

    var obj=document.getElementById('rota'+curpage);
      obj.style.opacity=0.6;
      timer=setTimeout('fnc_next(1)',150);
    } else if(x==1) {
    var obj=document.getElementById('rota'+curpage);
      obj.style.opacity=0.2;
      timer=setTimeout('fnc_next(2)',150);
    } else if(x==2) {
    var obj=document.getElementById('rota'+curpage);
    obj.style.visibility = "hidden";
    obj.style.display = "none";
    obj.style.height = "1px";
    obj.style.opacity=1;
    curpage++;
    if (curpage>numpages)
        curpage = 1;

    var obj=document.getElementById('rota'+curpage);
    obj.style.opacity=0.5;

    obj.style.visibility = "visible";
    obj.style.display = "block";
    obj.style.height = slideHeight +"px";

      timer=setTimeout('fnc_next(3)',150);
    } else {
    var obj=document.getElementById('rota'+curpage);
    obj.style.opacity=1;
    start();
    }
}

function fnc_prev()
{
    if (stopped)
        rpb();

    if (curpage == 0 || curpage>numpages)
        curpage=1;
    stop();

    var obj=document.getElementById('rota'+curpage);
    obj.style.visibility = "hidden";
    obj.style.display = "none";
    obj.style.height = "1px";
    
    curpage--;
    if (curpage<=0)
        curpage = numpages;
    var obj=document.getElementById('rota'+curpage);
    obj.style.visibility = "visible";
    obj.style.display = "block";
    obj.style.height = slideHeight + "px";
    start();
}

function stopstart(img) {
    if (stopped) {
        img.src="ext-funcway/editor/images/"+img.id+".gif";
        img.onmouseover="sgppnov(this);";
        img.onmouseout="sgppnou(this);";
        start();
    } else {
        img.src="ext-funcway/editor/images/"+img.id+"_over.gif";
        img.onmouseover="";
        img.onmouseout="";
        stop();
    }
}

function stop() {
    if (!(stopped)) {
        clearTimeout(timer);
        stopped=true;
    }
}
function start() {
   if (document.all){
    timer=setTimeout('fnc_next_ie(0)',8000);
   } else {
    timer=setTimeout('fnc_next(0)',8000);
   }
    stopped=false;
}

function firsthide()
{
    //Oculto cada una de las imagenes
    for (i=1;i <= numpages;i++)
    {
        var obj=document.getElementById('rota'+i);
        if(i==1) 
        {
           // imagesWidth  = document.getElementById('img1').width;
           // imagesHeight = document.getElementById('img1').height;
            imagesWidth  = 240;
            imagesHeight = 180;
        }
        //slideHeight = imagesHeight + 85;
        slideHeight = imagesHeight + 60;
        obj.style.visibility="hidden";
        obj.style.display = "none";
        obj.style.height = "1px";
        obj.style.overflow ="hidden";
        obj.style.top = "0px";
        obj.style.position = "relative";
        obj.style.border = "0px solid";
        obj.style.zIndex = 1;
    }

    //Ubico la botonera segun el alto de la primer imagen
    if (numpages > 1)
    {
        var botonera=document.getElementById('botoneraSlide');
        var top = imagesHeight + 12;
        var left = imagesWidth - 89;
        botonera.style.visibility = "visible";
        botonera.style.display = "block";
        botonera.style.top = top + "px";
        botonera.style.left = left+ "px";
        botonera.style.zIndex = "5";
    }

    //Muestro la primer imagen
    curpage = 1;
    var obj=document.getElementById('rota'+curpage);
    obj.style.visibility = "visible";
    obj.style.display = "block";
    obj.style.height = slideHeight + "px";
    start();
}

function sgppnov(img)
{
    img.src='ext-funcway/editor/images/'+img.id+'_over.gif';
}
function sgppnou(img)
{
    img.src='ext-funcway/editor/images/'+img.id+'.gif';
}
