
  var link_array = new Array();
  var arr_actual = 0;
  
  var page_size = 5;
  var page = 1;
  var cycle=true;
  
  var hover=-1;
  
  var dissolve_speed = 10;
  var dissolve_step = 0.1;
  
  var dis_next = -1;

  function arr_add_link(id, id2, head, text,head_rewrite) {

    var link = Array();
    
    link['id'] = id;
    link['id2'] = id2;
    link['text'] = text;
    link['head'] = head;
    link['head_rewrite'] = head_rewrite;
    link['t2'] = new Image; link['t2'].src  = "medialib/"+id2+".1.t2.jpg";
    link['t2c'] = new Image;link['t2c'].src = "medialib/"+id2+".1.t2c.jpg";
    link['h'] = new Image;  link['h'].src   = "medialib/"+id2+".1.h.jpg";

    //link_array[id2] = link;
    link_array.push(link);
  }
  
  function dissolve() {
      d = document.getElementById('dissolve');

      if (d.style.opacity>0) {
        d.style.opacity = d.style.opacity-dissolve_step;
        d.style.filter="alpha(opacity="+Math.round((d.style.opacity-dissolve_step)*100)+")";
        setTimeout("dissolve();",dissolve_speed);
      } else {
        if (dis_next != -1) {
          double_check(dis_next_id,dis_next);
          dis_next = -1;
        }
          
      }
  
  }
  
  function double_check(id,j) {
 
    if (j==hover) {
      d = document.getElementById('dissolve');

      //Rounding = IE FIX
      if (Math.round(d.style.opacity) == 0) {
        t = document.getElementById('frame_'+id);
        
        //light actual
        t.getElementsByTagName('img')[0].src = link_array[j]['t2c'].src;
        o = document.getElementById('content');
        d.style.background = o.style.background;
        d.style.opacity = 1;
        d.style.filter="alpha(opacity=100)";
         
        o.style.background = "transparent url("+link_array[j]['h'].src+") no-repeat scroll 0%";
  
        //dark others
        for (i=0; i<link_array.length;i++) {
          if (i!=j)
            document.getElementById('frame_'+link_array[i]['id2']).getElementsByTagName('img')[0].src = link_array[i]['t2'].src;
        }
  
        o.getElementsByTagName('h2')[0].innerHTML = link_array[j]['head'];
        o.getElementsByTagName('span')[0].innerHTML = link_array[j]['text'];
        o.getElementsByTagName('a')[0].href = ''+link_array[j]['head_rewrite']+'/?id='+link_array[j]['id'];
  
        cycle=false;
  
        arr_actual=((page-1)*page_size) + j + 1;
        if (arr_actual >= page_size*page) arr_actual = page_size*(page-1);
        if (arr_actual >= link_array.length) arr_actual = page_size*(page-1);
        
        setTimeout("dissolve();",dissolve_speed);
  
      } else {
        dis_next = j;
        dis_next_id = id;
      }
  /*
        t = document.getElementById('frame_'+id);
  
      
        //light actual
        t.getElementsByTagName('img')[0].src = link_array[j]['t2c'].src;
        o = document.getElementById('content');
        o.style.background = "transparent url("+link_array[j]['h'].src+") no-repeat scroll 0%";
  
        //dark others
        for (i=0; i<link_array.length;i++) {
          if (i!=j)
            document.getElementById('frame_'+link_array[i]['id2']).getElementsByTagName('img')[0].src = link_array[i]['t2'].src;
        }
  
        o.getElementsByTagName('h2')[0].innerHTML = link_array[j]['head'];
        o.getElementsByTagName('span')[0].innerHTML = link_array[j]['text'];
        o.getElementsByTagName('a')[0].href = 'browse.php?id='+link_array[j]['id'];
  
        cycle=false;
  
        arr_actual=((page-1)*page_size) + j + 1;
        if (arr_actual >= page_size*page) arr_actual = page_size*(page-1);
        if (arr_actual >= link_array.length) arr_actual = page_size*(page-1);
  
  */
    }
  }

  function thumb_hover(id,j) {
    t = document.getElementById('frame_'+id);

    //alert(t);

    t.style.cursor='pointer';
    

    //check whether to stop
    hover=j;
    setTimeout("double_check("+id+","+j+");",120);
    
//    double_check(id,j);

  }

  function thumb_out(t,j) {
//    t.style.cursor='arrow';
//    t.getElementsByTagName('img')[0].src = link_array[j]['t2'].src;

    cycle=true;
    hover=-1;

  }

  function auto_cycle() {
  
    if (cycle) {
      t = document.getElementById('frame_'+link_array[arr_actual]['id2']);
      t.getElementsByTagName('img')[0].src = link_array[arr_actual]['t2c'].src;

      //dark others
      for (i=0; i<link_array.length;i++) {
        if (i!=arr_actual)
          document.getElementById('frame_'+link_array[i]['id2']).getElementsByTagName('img')[0].src = link_array[i]['t2'].src;
      }


      o = document.getElementById('content');
      d = document.getElementById('dissolve');
      d.style.background = o.style.background;
      d.style.opacity = 1; 
      d.style.filter="alpha(opacity=100)";
      o.style.background = "transparent url("+link_array[arr_actual]['h'].src+") no-repeat scroll 0%";

      o.getElementsByTagName('h2')[0].innerHTML = link_array[arr_actual]['head'];
      o.getElementsByTagName('span')[0].innerHTML = link_array[arr_actual]['text'];
      o.getElementsByTagName('a')[0].href = ''+link_array[arr_actual]['head_rewrite']+'/?id='+link_array[arr_actual]['id'];


      arr_actual++;

      if (arr_actual >= page_size*page) arr_actual = page_size*(page-1);
      if (arr_actual >= link_array.length) arr_actual = page_size*(page-1);

      setTimeout("dissolve();",dissolve_speed);

    }

    setTimeout("auto_cycle()",5000);

  }
  
  function next_page() {
    page ++;
    if (page >2) page = 2;

    arr_actual = page_size * (page-1);
    
  }

  function prev_page() {
    page --;
    if (page < 1) page = 1;

    arr_actual = page_size * (page-1);

  }

/*  var i = 0;

  function thumb_hover(t,j) {
    t.style.cursor='hand';
    t.getElementsByTagName('img')[0].src = img_buffer[j*3+1].src;
    o = document.getElementById('content');
    o.style.background = "transparent url("+img_buffer[j*3+2].src+") no-repeat scroll 0%";
  }

  function thumb_out(t,j) {
    t.style.cursor='arrow';
    t.getElementsByTagName('img')[0].src = img_buffer[j*3].src;
  }

  function load_thumb(id) {
    img_buffer[i*3  ] = new Image();
    img_buffer[i*3  ].src = "medialib/"+id+".1.t2.jpg";
    img_buffer[i*3+1] = new Image();
    img_buffer[i*3+1].src = "medialib/"+id+".1.t2c.jpg";
    img_buffer[i*3+2] = new Image();
    img_buffer[i*3+2].src = "medialib/"+id+".1.h.jpg";

    i++;
  }
*/
