/*  Prototype: an object-oriented Javascript library, version 1.2.1
 *  (c) 2005 Sam Stephenson <sam@conio.net>
 *
 *  THIS FILE IS AUTOMATICALLY GENERATED. When sending patches, please diff
 *  against the source tree, available from the Prototype darcs repository. 
 *
 *  Prototype is freely distributable under the terms of an MIT-style license.
 *
 *  For details, see the Prototype web site: http://prototype.conio.net/
 *
/*--------------------------------------------------------------------------*/

var Prototype = {
  Version: '1.2.1'
}

var Class = {
  create: function() {
    return function() { 
      this.initialize.apply(this, arguments);
    }
  }
}

var Abstract = new Object();

Object.prototype.extend = function(object) {
  for (property in object) {
    this[property] = object[property];
  }
  return this;
}

Function.prototype.bind = function(object) {
  var method = this;
  return function() {
    method.apply(object, arguments);
  }
}

Function.prototype.bindAsEventListener = function(object) {
  var method = this;
  return function(event) {
    method.call(object, event || window.event);
  }
}

Number.prototype.toColorPart = function() {
  var digits = this.toString(16);
  if (this < 16) return '0' + digits;
  return digits;
}

var Try = {
  these: function() {
    var returnValue;
    
    for (var i = 0; i < arguments.length; i++) {
      var lambda = arguments[i];
      try {
        returnValue = lambda();
        break;
      } catch (e) {}
    }
    
    return returnValue;
  }
}

/*--------------------------------------------------------------------------*/

var PeriodicalExecuter = Class.create();
PeriodicalExecuter.prototype = {
  initialize: function(callback, frequency) {
    this.callback = callback;
    this.frequency = frequency;
    this.currentlyExecuting = false;
    
    this.registerCallback();
  },
  
  registerCallback: function() {
    setTimeout(this.onTimerEvent.bind(this), this.frequency * 1000);
  },
  
  onTimerEvent: function() {
    if (!this.currentlyExecuting) {
      try { 
        this.currentlyExecuting = true;
        this.callback(); 
      } finally { 
        this.currentlyExecuting = false;
      }
    }
    
    this.registerCallback();
  }
}

/*--------------------------------------------------------------------------*/
// document.getElementById(element)
/*--------------------------------------------------------------------------*/
/*
function $() {
	var elements = new Array();
	for (var i=0; i<arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string') element = document.getElementById(element);
		if (arguments.length == 1) return element;
		elements.push(element);
	}
	return elements;
}
*/
/*--------------------------------------------------------------------------*/

if (!Array.prototype.push) {
  Array.prototype.push = function() {
		var startLength = this.length;
		for (var i = 0; i < arguments.length; i++)
      this[startLength + i] = arguments[i];
	  return this.length;
  }
}

if (!Function.prototype.apply) {
  // Based on code from http://www.youngpup.net/
  Function.prototype.apply = function(object, parameters) {
    var parameterStrings = new Array();
    if (!object)     object = window;
    if (!parameters) parameters = new Array();
    
    for (var i = 0; i < parameters.length; i++)
      parameterStrings[i] = 'x[' + i + ']';
    
    object.__apply__ = this;
    var result = eval('obj.__apply__(' + 
      parameterStrings[i].join(', ') + ')');
    object.__apply__ = null;
    
    return result;
  }
}
/*--------------------------------------------------------------------------*/

document.getElementsByClassName = function(className) {
  var children = document.getElementsByTagName('*') || document.all;
  var elements = new Array();
  
  for (var i = 0; i < children.length; i++) {
    var child = children[i];
    var classNames = child.className.split(' ');
    for (var j = 0; j < classNames.length; j++) {
      if (classNames[j] == className) {
        elements.push(child);
        break;
      }
    }
  }
  
  return elements;
}

/*--------------------------------------------------------------------------*/

var Element = {
  toggle: function() {
    for (var i = 0; i < arguments.length; i++) {
      var element = $(arguments[i]);
      element.style.display = 
        (element.style.display == 'none' ? '' : 'none');
    }
  },

  hide: function() {
    for (var i = 0; i < arguments.length; i++) {
      var element = $(arguments[i]);
      element.style.display = 'none';
    }
  },

  show: function() {
    for (var i = 0; i < arguments.length; i++) {
      var element = $(arguments[i]);
      element.style.display = '';
    }
  },

  remove: function(element) {
    element = $(element);
    element.parentNode.removeChild(element);
  },
   
  getHeight: function(element) {
    element = $(element);
    return element.offsetHeight; 
  }
}

var Toggle = new Object();
Toggle.display = Element.toggle;



/*--------------------------------------------------------------------------*/

var Effect = new Object();

Effect.Highlight = Class.create();
Effect.Highlight.prototype = {
  initialize: function(element) {
    this.element = $(element);
    this.start  = 153;
    this.finish = 255;
    this.current = this.start;
    this.fade();
  },
  
  fade: function() {
    if (this.isFinished()) return;
    if (this.timer) clearTimeout(this.timer);
    this.highlight(this.element, this.current);
    this.current += 17;
    this.timer = setTimeout(this.fade.bind(this), 250);
  },
  
  isFinished: function() {
    return this.current > this.finish;
  },
  
  highlight: function(element, current) {
    element.style.backgroundColor = "#ffff" + current.toColorPart();
  }
}


Effect.Fade = Class.create();
Effect.Fade.prototype = {
  initialize: function(element) {
    this.element = $(element);
    this.start  = 100;
    this.finish = 0;
    this.current = this.start;
    this.fade();
  },
  
  fade: function() {
    if (this.isFinished()) { this.element.style.display = 'none'; return; }
    if (this.timer) clearTimeout(this.timer);
    this.setOpacity(this.element, this.current);
    this.current -= 10;
    this.timer = setTimeout(this.fade.bind(this), 50);
  },
  
  isFinished: function() {
    return this.current <= this.finish;
  },
  
  setOpacity: function(element, opacity) {
    opacity = (opacity == 100) ? 99.999 : opacity;
    element.style.filter = "alpha(opacity:"+opacity+")";
    element.style.opacity = opacity/100 /*//*/;
  }
}

Effect.Scale = Class.create();
Effect.Scale.prototype = {
  initialize: function(element, percent) {
    this.element = $(element);
    this.startScale    = 1.0;
    this.startHeight   = this.element.offsetHeight;
    this.startWidth    = this.element.offsetWidth;
    this.currentHeight = this.startHeight;
    this.currentWidth  = this.startWidth;
    this.finishScale   = (percent/100) /*//*/;
    if (this.element.style.fontSize=="") this.sizeEm = 1.0;
    if (this.element.style.fontSize.indexOf("em")>0)
       this.sizeEm      = parseFloat(this.element.style.fontSize);
    if(this.element.effect_scale) {
      clearTimeout(this.element.effect_scale.timer);
      this.startScale  = this.element.effect_scale.currentScale;
      this.startHeight = this.element.effect_scale.startHeight;
      this.startWidth  = this.element.effect_scale.startWidth;
      if(this.element.effect_scale.sizeEm) 
        this.sizeEm    = this.element.effect_scale.sizeEm;      
    }
    this.element.effect_scale = this;
    this.currentScale  = this.startScale;
    this.factor        = this.finishScale - this.startScale;
    this.options       = arguments[2] || {}; 
    this.scale();
  },
  
  scale: function() {
    if (this.isFinished()) { 
      this.setDimensions(this.element, this.startWidth*this.finishScale, this.startHeight*this.finishScale);
      if(this.sizeEm) this.element.style.fontSize = this.sizeEm*this.finishScale + "em";
      if(this.options.complete) this.options.complete(this);
      return; 
    }
    if (this.timer) clearTimeout(this.timer);
    if (this.options.step) this.options.step(this);
    this.setDimensions(this.element, this.currentWidth, this.currentHeight);
    if(this.sizeEm) this.element.style.fontSize = this.sizeEm*this.currentScale + "em";
    this.currentScale += (this.factor/10) /*//*/;
    this.currentWidth = this.startWidth * this.currentScale;
    this.currentHeight = this.startHeight * this.currentScale;
    this.timer = setTimeout(this.scale.bind(this), 50);
  },
  
  isFinished: function() {
    return (this.factor < 0) ? 
      this.currentScale <= this.finishScale : this.currentScale >= this.finishScale;
  },
  
  setDimensions: function(element, width, height) {
    element.style.width = width + 'px';
    element.style.height = height + 'px';
  }
}

Effect.Squish = Class.create();
Effect.Squish.prototype = {
  initialize: function(element) {
    this.element = $(element);
    new Effect.Scale(this.element, 1, { complete: this.hide.bind(this) } );
  },
  hide: function() {
    this.element.style.display = 'none';
  } 
}

Effect.Puff = Class.create();
Effect.Puff.prototype = {
  initialize: function(element) {
    this.element = $(element);
    this.opacity = 100;
    this.startTop  = this.element.top || this.element.offsetTop;
    this.startLeft = this.element.left || this.element.offsetLeft;
    new Effect.Scale(this.element, 200, { step: this.fade.bind(this), complete: this.hide.bind(this) } );
  },
  fade: function(effect) {
    topd    = (((effect.currentScale)*effect.startHeight) - effect.startHeight)/2;
    leftd   = (((effect.currentScale)*effect.startWidth) - effect.startWidth)/2;
    this.element.style.position='absolute';
    this.element.style.top = this.startTop-topd + "px";
    this.element.style.left = this.startLeft-leftd + "px";
    this.opacity -= 10;
    this.setOpacity(this.element, this.opacity); 
    if(navigator.appVersion.indexOf('AppleWebKit')>0) this.element.innerHTML += ''; //force redraw on safari
  },
  hide: function() {
    this.element.style.display = 'none';
  },
  setOpacity: function(element, opacity) {
    opacity = (opacity == 100) ? 99.999 : opacity;
    element.style.filter = "alpha(opacity:"+opacity+")";
    element.style.opacity = opacity/100 /*//*/;
  }
}

Effect.Appear = Class.create();
Effect.Appear.prototype = {
  initialize: function(element) {
    this.element = $(element);
    this.start  = 0;
    this.finish = 100;
    this.current = this.start;
    this.fade();
  },
  
  fade: function() {
    if (this.isFinished()) return;
    if (this.timer) clearTimeout(this.timer);
    this.setOpacity(this.element, this.current);
    this.current += 10;
    this.timer = setTimeout(this.fade.bind(this), 50);
  },
  
  isFinished: function() {
    return this.current > this.finish;
  },
  
  setOpacity: function(element, opacity) {
    opacity = (opacity == 100) ? 99.999 : opacity;
    element.style.filter = "alpha(opacity:"+opacity+")";
    element.style.opacity = opacity/100 /*//*/;
    element.style.display = '';
  }
}

Effect.ContentZoom = Class.create();
Effect.ContentZoom.prototype = {
  initialize: function(element, percent) {
    this.element = $(element);
    if (this.element.style.fontSize=="") this.sizeEm = 1.0;
    if (this.element.style.fontSize.indexOf("em")>0)
       this.sizeEm = parseFloat(this.element.style.fontSize);
    if(this.element.effect_contentzoom) {
      this.sizeEm = this.element.effect_contentzoom.sizeEm;
    }
    this.element.effect_contentzoom = this;
    this.element.style.fontSize = this.sizeEm*(percent/100) + "em" /*//*/;
    if(navigator.appVersion.indexOf('AppleWebKit')>0) { this.element.scrollTop -= 1; };
  }
}


/* PROTOTYPE II -------------------------------------------------------------------------------------------------------- */


// Copyright (c) 2005 Thomas Fuchs
// Permission granted to use this code as you like

Effect2 = {}

/* ------------- transitions ------------- */

Effect2.Transitions = {}
Effect2.Transitions.linear = function(pos) {
	return pos;
}
Effect2.Transitions.sinoidal = function(pos) {
	return (-Math.cos(pos*Math.PI)/2) + 0.5;
}
Effect2.Transitions.reverse  = function(pos) {
	return 1-pos;
}
Effect2.Transitions.flicker = function(pos) {
	return ((-Math.cos(pos*Math.PI)/4) + 0.75) + Math.random(0.25);
}
Effect2.Transitions.wobble = function(pos) {
	return (-Math.cos(pos*Math.PI*(9*pos))/2) + 0.5;
}

/* ------------- core effects ------------- */

Effect2.Base = function() {};
Effect2.Base.prototype = {
  setOptions: function(options) {
	this.options = {
	  transition: Effect2.Transitions.sinoidal,
	  duration:   1.0,   // seconds
	  fps:        25.0,  // max. 100fps
	  sync:       false, // true for combining
	  from:       0.0,
	  to:         1.0
	}.extend(options || {});
  },
  start: function(options) {
	this.setOptions(options || {});
	this.currentFrame = 0;
	  this.startOn  = new Date().getTime();
	  this.finishOn = this.startOn + (this.options.duration*1000);
	  if(this.options.beforeStart) this.options.beforeStart(this);
	if(!this.options.sync) this.loop();	
  },
  loop: function() {
	 timePos = new Date().getTime();
	 if(timePos >= this.finishOn) {
		this.render(this.options.to);
		if(this.finish) this.finish(); 
		if(this.options.afterFinish) this.options.afterFinish(this);
		return;	
	 }
	 pos   = (timePos - this.startOn) / (this.finishOn - this.startOn);
	 frame = Math.round(pos * this.options.fps * this.options.duration);
	 if(frame > this.currentFrame) {
		this.render(pos);
		this.currentFrame = frame;
	 }
	 this.timeout = setTimeout(this.loop.bind(this), 10);
  },
  render: function(pos) {
	 if(this.options.transition) pos = this.options.transition(pos);
	 pos  = pos * (this.options.to-this.options.from);
	 pos += this.options.from; 
	 if(this.options.beforeUpdate) this.options.beforeUpdate(this);
	 if(this.update) this.update(pos);
	 if(this.options.afterUpdate) this.options.afterUpdate(this);	
  },
  cancel: function() {
	 if(this.timeout) clearTimeout(this.timeout);
  }
}

Effect2.Parallel = Class.create();
Effect2.Parallel.prototype = (new Effect2.Base()).extend({
  initialize: function(effects) {
	this.effects = effects || [];
	 this.start(arguments[1]);
  },
  update: function(position) {
	 for (var i = 0; i < this.effects.length; i++)
		this.effects[i].render(position);	
  },
  finish: function(position) {
	 for (var i = 0; i < this.effects.length; i++)
		if(this.effects[i].finish) this.effects[i].finish(position);
  }
});

Effect2.Opacity = Class.create();
Effect2.Opacity.prototype = (new Effect2.Base()).extend({
  initialize: function() {
	this.element = $(arguments[0] || document.rootElement);
	options = {
	  from: 0.0,
	  to:   1.0
	}.extend(arguments[1] || {});
	this.start(options);
  },
  update: function(position) {
	this.setOpacity(position);
  }, 
  setOpacity: function(opacity) {
	opacity = (opacity == 1) ? 0.99999 : opacity;
	this.element.style.opacity = opacity;
	this.element.style.filter = "alpha(opacity:"+opacity*100+")";
  }
});

Effect2.MoveBy = Class.create();
Effect2.MoveBy.prototype = (new Effect2.Base()).extend({
 initialize: function(element, toTop, toLeft) {
	 this.element      = $(element);
	 this.originalTop  = 
	 this.element.style.top ? parseFloat(this.element.style.top) : 0;
   this.originalLeft = 
	 this.element.style.left ? parseFloat(this.element.style.left) : 0;
   this.toTop        = toTop;
	 this.toLeft       = toLeft;
   if(this.element.style.position == "")
	 this.element.style.position = "relative";
   this.start(arguments[3]);
 },
 update: function(position) {
	topd  = this.toTop  * position + this.originalTop;
	leftd = this.toLeft * position + this.originalLeft;
 this.setPosition(topd, leftd);
 },
 setPosition: function(topd, leftd) {
	 this.element.style.top  = topd  + "px";
   this.element.style.left = leftd + "px";
 }
});

Effect2.Scale = Class.create();
Effect2.Scale.prototype = (new Effect2.Base()).extend({
  initialize: function(element, percent) {
	this.element = $(element);
	options = {
	  scaleX: true,
	  scaleY: true,
	  scaleContent: true,
	  scaleFromCenter: false,
	  scaleMode: 'box',        // 'box' or 'contents'
	  scaleFrom: 100.0
	}.extend(arguments[2] || {});
	this.originalTop    = this.element.offsetTop;
	this.originalLeft   = this.element.offsetLeft;
	if (this.element.style.fontSize=="") this.sizeEm = 1.0;
	if (this.element.style.fontSize && this.element.style.fontSize.indexOf("em")>0)
	   this.sizeEm      = parseFloat(this.element.style.fontSize);
	this.factor = (percent/100.0) - (options.scaleFrom/100.0);
	if(options.scaleMode=='box') {
	  this.originalHeight = this.element.clientHeight;
	  this.originalWidth  = this.element.clientWidth; 
	} else 
	if(options.scaleMode=='contents') {
	  this.originalHeight = this.element.scrollHeight;
	  this.originalWidth  = this.element.scrollWidth;
	}
	this.start(options);
  },

  update: function(position) {
	currentScale = (this.options.scaleFrom/100.0) + (this.factor * position);
	if(this.options.scaleContent && this.sizeEm) 
	  this.element.style.fontSize = this.sizeEm*currentScale + "em";
	this.setDimensions(
	   this.originalWidth * currentScale, 
	   this.originalHeight * currentScale);
  },

  setDimensions: function(width, height) {
	if(this.options.scaleX) this.element.style.width = width + 'px';
	if(this.options.scaleY) this.element.style.height = height + 'px';
	if(this.options.scaleFromCenter) {
	  topd  = (height - this.originalHeight)/2;
	  leftd = (width  - this.originalWidth)/2;
	  if(this.element.style.position=='absolute') {
		if(this.options.scaleY) this.element.style.top = this.originalTop-topd + "px";
		if(this.options.scaleX) this.element.style.left = this.originalLeft-leftd + "px";
	  } else {
		if(this.options.scaleY) this.element.style.top = -topd + "px";
		if(this.options.scaleX) this.element.style.left = -leftd + "px";
	  }
	}
  }
});

/* ------------- prepackaged effects ------------- */

Effect2.Fade =	function(element) {
  options = {
	from: 1.0,
	to:   0.0,
	afterFinish: function(effect) 
	  { Element.hide(effect.element);
		effect.setOpacity(1); } 
	}.extend(arguments[1] || {});
  new Effect2.Opacity(element,options);
}
Effect2.Appear =	function(element) {
  options = {
	 from: 0.0,
	 to:   1.0,
	 beforeStart: function(effect)  
	   { effect.setOpacity(0);
		   Element.show(effect.element); },
	 afterUpdate: function(effect)  
	   { Element.show(effect.element); }
  }.extend(arguments[1] || {});
  new Effect2.Opacity(element,options);
}

Effect2.Puff = function(element) {
  new Effect2.Parallel(
   [ new Effect2.Scale(element, 200, { sync: true, scaleFromCenter: true }), 
	 new Effect2.Opacity(element, { sync: true, to: 0.0, from: 1.0 } ) ], 
	 { duration: 1.0, 
		afterUpdate: function(effect) 
		 { effect.effects[0].element.style.position = 'absolute'; },
		afterFinish: function(effect)
		 { Element.hide(effect.effects[0].element); }
	 }
 );
}

Effect2.BlindUp = function(element) {
  $(element).style.overflow = 'hidden';
  new Effect2.Scale(element, 0, 
	{ scaleContent: false, 
	scaleX: false, 
	afterFinish: function(effect) 
	  { Element.hide(effect.element) } 
  }.extend(arguments[1] || {})
  );
}

Effect2.BlindDown = function(element) {
  $(element).style.height   = '0px';
  $(element).style.overflow = 'hidden';
  Element.show(element);
  new Effect2.Scale(element, 100, 
	  { scaleContent: false, 
		  scaleX: false, 
		  scaleMode: 'contents',
		  scaleFrom: 0
	}.extend(arguments[1] || {})
  );
}

Effect2.SwitchOff = function(element) {
	new Effect2.Appear(element,
	  { duration: 0.4,
		 transition: Effect2.Transitions.flicker,
		 afterFinish: function(effect)
		  {  effect.element.style.overflow = 'hidden';
			  new Effect2.Scale(effect.element, 1, 
			   { duration: 0.3, scaleFromCenter: true,
				  scaleX: false, scaleContent: false,
				  afterUpdate: function(effect) { 
					 if(effect.element.style.position=="")
					   effect.element.style.position = 'relative'; },
				  afterFinish: function(effect) { Element.hide(effect.element); }
			   } )
		  }
	  } )
}

Effect2.DropOut = function(element) {
	new Effect2.Parallel(
	  [ new Effect2.MoveBy(element, 100, 0, { sync: true }), 
		new Effect2.Opacity(element, { sync: true, to: 0.0, from: 1.0 } ) ], 
	  { duration: 0.5, 
		 afterFinish: function(effect)
		   { Element.hide(effect.effects[0].element); } 
	  });
}

Effect2.Shake = function(element) {
	new Effect2.MoveBy(element, 0, 20, 
	  { duration: 0.05, afterFinish: function(effect) {
	new Effect2.MoveBy(effect.element, 0, -40, 
	  { duration: 0.1, afterFinish: function(effect) { 
	new Effect2.MoveBy(effect.element, 0, 40, 
	  { duration: 0.1, afterFinish: function(effect) {	
	new Effect2.MoveBy(effect.element, 0, -40, 
	  { duration: 0.1, afterFinish: function(effect) {	
	new Effect2.MoveBy(effect.element, 0, 40, 
	  { duration: 0.1, afterFinish: function(effect) {	
	new Effect2.MoveBy(effect.element, 0, -20, 
	  { duration: 0.05, afterFinish: function(effect) {	
	}}) }}) }}) }}) }}) }});
}

Effect2.SlideDown = function(element) {
  $(element).style.height   = '0px';
  $(element).style.overflow = 'hidden';
  $(element).childNodes[0].style.position = 'relative';
  Element.show(element);
  new Effect2.Scale(element, 100, 
	 { scaleContent: false, 
		scaleX: false, 
		scaleMode: 'contents',
		scaleFrom: 0,
		afterUpdate: function(effect) 
		  { effect.element.firstChild.style.bottom = 
			  (effect.originalHeight - effect.element.clientHeight) + 'px'; }
	}.extend(arguments[1] || {})
  );
}

Effect2.SlideUp = function(element) {
  $(element).style.overflow = 'hidden';
  $(element).childNodes[0].style.position = 'relative';
  Element.show(element);
  new Effect2.Scale(element, 0, 
	 { scaleContent: false, 
		scaleX: false, 
		afterUpdate: function(effect) 
		  { effect.element.firstChild.style.bottom = 
			  (effect.originalHeight - effect.element.clientHeight) + 'px'; },
	afterFinish: function(effect)
	  { Element.hide(effect.element); }
   }.extend(arguments[1] || {})
  );
}


