var currentslide=2;
var autosideshowint,tmptimer;
var activeflag=false;
if (document.images) {

   //Preload all the required images
  // rollover buttons images  
    right_off = new Image();
    right_off.src = "/images/btn_home_right_normal.png";
    right_on = new Image();
    right_on.src = "/images/btn_home_right_rollover.png";
    left_off = new Image();
    left_off.src = "/images/btn_home_left_normal.png";
    left_on = new Image();
    left_on.src = "/images/btn_home_left_rollover.png";
    preload_image_obj = new Image();
    image_url = new Array();
    image_url[0] = "/puerto_rico/images/puerto_rico_index_slide_1.jpg";
    image_url[1] = "/puerto_rico/images/puerto_rico_index_slide_2.jpg";
    image_url[2] = "/puerto_rico/images/puerto_rico_index_slide_3.jpg";

    var i = 0;
    for(i=0; i<image_url.length; i++) 
    preload_image_obj.src = image_url[i];
    //currentslide=image_url.length;
}
function rollover(name,typ) {
    if (document.images) 
    {
    document.getElementById('span_'+name).className=name+'arrow_'+typ;
    fullname = eval(  name+'_'+typ);
    document.images[name].src = fullname.src;

    }
}
/*
this is the onclick function for the slides
based on the currentslide variable decide the call to action
*/
function calltoaction()
{
//alert('calll to action'+currentslide)
clearInterval(autosideshowint);
clearInterval(tmptimer);

  if (currentslide==2)
  {
    //omnitureOnClick('navLocation:tbn', 'navName:emerald');
      location.href="/puerto_rico/oficinas/mas_informacion_oficinas.html";
  }
  else if (currentslide==1)
  {
        //omnitureOnClick('navLocation:tbn', 'navName:office');

      location.href="/puerto_rico/oficinas/oferta_garantia_producto.html";
  }
   else if (currentslide==3)
  {
    //omnitureOnClick('navLocation:tbn', 'navName:software');

      location.href="/puerto_rico/oficinas/index.html";
  }
   else if (currentslide==4)
  {

    //omnitureOnClick('navLocation:tbn', 'navName:online');
    //productLearnMore(31,'site:hrblock','linkname:Online_Split');
  }
}

/*
this is the onclick function for the slides
based on the index of the bottom section
*/
function calltoaction_bottomsection(indx)
{

  if (indx==2)
  {
    omnitureOnClick('navLocation:lbn', 'navName:secondlook');
      location.href="/puerto_rico/oficinas/second_look.html";
  }
  else if (indx==1)
  {
      omnitureOnClick('navLocation:lbn', 'navName:oficinas');

      location.href="/puerto_rico/oficinas/index.html";


  }
   else if (indx==3)
  {
    omnitureOnClick('navLocation:lbn', 'navName:sugerencias_sobre_taxes');

    location.href="/puerto_rico/sugerencias_sobre_taxes/index.html";
  }
   else if (indx==4)
  {
       omnitureOnClick('navLocation:lbn', 'navName:emerald_card');
		location.href="/puerto_rico/banco/emerald_card.html";

    
    //productLearnMore(31,'site:hrblock','linkname:Online_Split');
  }
}
var styleobj,animcnt=0,ts;
var inmotion=false;
/*
capture the style object and call animation
*/
function slidediv(divname,direction)
{
    styleobj = document.getElementById(divname).style;
    animatewidth(direction);
}
/*
animate the width of the div
*/
function animatewidth(direction) {
    if(animcnt<95) 
    {
        inmotion=true;
        styleobj.width = parseInt(styleobj.width) + 10 + 'px';
        if(direction==-1)
        styleobj.left = parseInt(styleobj.left) - 10 + 'px';
        animcnt++;
        ts1 = setTimeout("animatewidth('"+direction+"')",10);
    }
    else 
    {
        animcnt = 0;
        clearTimeout(ts);
        inmotion=false;
    }
}

/*
Move right and left function 
These functions re-create the div and animates the width.
*/
function moveslide(direction)
 {
     if (inmotion)
        return;
    var xPos =0;
    //update the last shown image
    //document.images['img0'].src=image_url[currentslide-1];     
    var divcontent="";
    //<div id='div0' style='height:306px;width:600px;position:absolute;'><img src='"+image_url[currentslide-1]+"' >  </div>"
    //check the direction of button click
    if (direction=='left')
    {
        if(currentslide==1){
           currentslide=image_url.length+1;
           }
         currentslide--;
         xPos =950;
    }
    if (direction=='right')
    {
        if(currentslide==image_url.length){
           currentslide=0;
           }
        currentslide++;
    }
    divcontent=divcontent+"<div id='div_slide' style='position:absolute;height:306px;width:0px;overflow:hidden;left:"+xPos+"px;'><img src='"+image_url[currentslide-1]+"' >  </div>"
    document.getElementById('slide_cover').innerHTML=divcontent
    slidediv('div_slide',(direction=='left')?-1:1);
        activeflag=false;

    tmptimer =setTimeout("check_for_idle_state()",7000);

}

/*left or right slide button is clicked
clear the timers
*/
function stopautomate(direction)
{
    clearInterval(autosideshowint);
    clearInterval(tmptimer);

    activeflag=true;
    moveslide(direction)

    //autosideshowint=setTimeout("moveslide('right')",5000)


}

function check_for_idle_state()
{
   if (activeflag==false)
   {
      moveslide('right');
   }
}
