/*
 * Copyright 2006, Jeffrey Palm.
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 * 
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

// The number of collections

var NUM_SUBS = 5;



var expanded = false;
function rmToggle() {
  if (expanded) {
    rmRetract(); 
  } else {
    rmExpand();
  }
}

function rmRetract() {
  note('rmRetract');

  var nudge = 0;

  for (var i=0; i<NUM_SUBS; i++) {
    setTimeout("rmSlideLeft('rmSub" + (NUM_SUBS-i) + "')", (i+1)*SUB_DELAY+nudge);
  }

  setTimeout("new Effect.Move('rmBottom', { duration:BOTTOM_DUR, x:0, y:-BOTTOM_Y, mode: 'relative' });",
	     SUB_DELAY);
	
  expanded = false;
}

function rmExpand() {
  note('rmExpand');

  new Effect.Move('rmBottom', { duration:BOTTOM_DUR, x:0, y:BOTTOM_Y, mode: 'relative' });

  var nudge = HEADSTART;

  for (var i=0; i<NUM_SUBS; i++) {
    setTimeout("rmSlideRight('rmSub" + (i+1) + "')", (i+1)*SUB_DELAY+nudge);
  }

  expanded = true;
}


var SUB_X = 15;
var SUB_DUR = 0.6;
var SUB_DELAY = 270;

var BOTTOM_Y_PER_SUB = 28;
var BOTTOM_Y = NUM_SUBS * BOTTOM_Y_PER_SUB;
var BOTTOM_DUR = 2.0;

var HEADSTART=SUB_DELAY;

function rmSlideRight(el) {
  new Effect.Appear(el, { duration:SUB_DUR });
  new Effect.Move(el,   { duration:SUB_DUR, x:SUB_X, y:0, mode: 'relative' });
}

function rmSlideLeft(el) {
  new Effect.Move(el,   { duration:SUB_DUR, x:-SUB_X, y:0, mode: 'relative' });
  new Effect.Fade(el, { duration:SUB_DUR });
}

function note(msg) {
  //$('debug').innerHTML=msg;
}

