var speed = 4;
var timerId;
var limit;
var gallery_max;

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function changeImage( id, src )
{
  /* load the image */
  var img = MM_findObj(id);
  
  /* change the image */
  if ( img != null )
  {
    img.src = src;
  }
}

function galleryPrev()
{
  timerId = setInterval("galleryPrevStep()", 70);
}

function galleryNext()
{
  if ( limit >= 0 )
  {
    /* save the end */
    timerId = setInterval("galleryNextStep()", 70);
  }
}


function galleryStop()
{
  /* remove gallery calls */
  clearInterval(timerId);
  
  /* restore original pictures */
  changeImage( "gallery_control_previous", "http://www.campingheeg.nl/nl/photogallery/left.gif" );
  changeImage( "gallery_control_next", "http://www.campingheeg.nl/nl/photogallery/right.gif" );
}

function galleryPrevStep()
{  
  /* load the container */
  var container = MM_findObj("gallery_pics_container");
  
  /* change left-value */
  var new_pos = (parseInt( container.style.left ) + speed);

  if ( new_pos < 0 )
  {
    /* change image */
    changeImage( "gallery_control_previous", "http://www.campingheeg.nl/nl/photogallery/lefthover.gif" );
    container.style.left = new_pos + "px";  
  }
  else if ( container.style.left != 0 )
  {
    /* change image */
    changeImage( "gallery_control_previous", "http://www.campingheeg.nl/nl/photogallery/left.gif" );
     
    /* change position */
    container.style.left = "0px";
    
    /* stop de procedure */
    clearInterval(timerId);
  }
}

function galleryNextStep()
{ 
  /* load the container */
  var container = MM_findObj("gallery_pics_container");

  /* change left-value */
  var new_pos = (parseInt( container.style.left ) - speed);
  
  if ( new_pos > (-1)*limit )
  {
    /* change image */
    changeImage( "gallery_control_next", "http://www.campingheeg.nl/nl/photogallery/righthover.gif" );  
    container.style.left = new_pos + "px";  
  }
  else if ( container.style.left != 0 )
  {
    /* change image */
    changeImage( "gallery_control_next", "http://www.campingheeg.nl/nl/photogallery/right.gif" ); 
      
    /* change position */
    container.style.left = (-1*limit) + "px";
    
    /* stop de procedure */
    clearInterval(timerId);
  } 
}

function resizeGallery()
{
  /* load the objects */
  var obj1 = MM_findObj("gallery");
  var view = MM_findObj("gallery_pics_view");
  var obj_width = parseInt( obj1.offsetWidth );
  view.style.width = (obj_width-74) + "px";
  limit = gallery_max - (obj_width-74);
}
