// ******* References Script - jaeck-ag.ch *******
// ******* © by nexbyte gmbh, switzerland *******
// ******* create: 08.11.2001 - tbruederli *******
// ******* modify: 07.02.2003 - tbruederli *******

// configuration vars
var scroll_speed = 20;
var slide_speed = 20;
var slide_step = 20;
var ref_height = 260;
var loop, timer, reflayerpos;

// init the reference scroller
function init_ref()
  {
  // create layer objects
  o_scroller = new layer_object('scroller');
  o_refstrip = new layer_object('refstrip','scroller');

  set_reflayer_pos();
  o_scroller.show(1);
  o_refstrip.scroll = do_scroll;
//  o_refstrip.width = refstrip_length;

  window.onresize = function(e){ setTimeout('set_reflayer_pos()', 5); };
  }

function set_reflayer_pos()
  {
  reflayerpos = get_image_pos('refposimage');
  o_scroller.move(reflayerpos.x, reflayerpos.y+2);
  }
  
// start scrolling (onmousedown)
function scroll(move)
  {
  loop = true;
  o_refstrip.scroll(move);
  }

// execute the scrolling
function do_scroll(move)
  {
	if(loaded && bw.dhtml && loop)
    {
  	if((move>0 && this.x*(-1)<this.width-o_scroller.clip_width) || (move<0 && this.x<0))
      {
		  this.move(this.x+(move*-1),this.y);
      timer = setTimeout(this.obj+'.scroll('+move+')',scroll_speed);
  	  }
    else if(this.width>o_scroller.clip_width )
      {
      if(move>0) this.move((this.width-o_scroller.clip_width)*(-1),this.y);
      else if(move<0) this.move(0,this.y);
      loop = false;
      }
    else
      loop = false;
    }
  }

// stop the scrolling (onmouseup)
function no_scroll()
  {
	loop = false;
	if(timer) clearTimeout(timer);
  }

var current_ref = '';
var ref_busy = false;

// show a fererences layer
function show_ref(id)
  {
  var which = 'ref-'+id;
  if(ref_busy) return false;
  if(current_ref && current_ref.name==which) return false;
  else if(current_ref) hide_ref(1);

  var ref_layer = new layer_object(which);
  if(!ref_layer.elm) return false;

  ref_layer.slide = ref_slide;
  ref_layer.clip(0,ref_layer.width,1,0);
  ref_layer.move(reflayerpos.x, reflayerpos.y-2);

  ref_busy = true;
  ref_layer.show(1);
  ref_layer.slide('in',0,'ref_busy=false');
  current_ref = ref_layer;

  return false;
  }

// hide the current references layer
function hide_ref(keep)
  {
  if(current_ref)
    {
    ref_busy = true;
    var action = current_ref.obj+'.show(0);ref_busy=false' + ((keep==null) ? ';current_ref=null' : '');
    if(current_ref.timer) clearTimeout(current_ref.timer);
    current_ref.slide('out', ref_height, action);
    }

  return false;
  }

// clip and move the layer - looks like moving out behind something
function ref_slide(dir,y,action)
  {
  var h = (dir=='in') ? y+slide_step : y-slide_step;
  var pos = (dir=='in') ? this.y-slide_step : this.y+slide_step;

  if((dir=='in' && h<ref_height) || (dir=='out' && h>0))
    {
    this.clip(0,this.width,h,0);
    this.move(this.x,pos);
    this.timer = setTimeout(this.obj+'.slide(\''+dir+'\','+h+',\''+action+'\')', slide_speed);
    }
  else
    {
    h = (dir=='in') ? ref_height : 1;
    pos = (dir=='in') ? reflayerpos.y-2-ref_height : reflayerpos.y-2;

    this.clip(0,this.width,h,0);
    this.move(this.x,pos);
    eval(action);
    }
  }

var ref_script = true;

