/*
*
* Copyright (c) 2006 Millstream Web Software
* 
* 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.
* 
* 
* 
* 
*/

/*
* Effect.Bounce
* Written by: Andrew Tetlaw http://tetlaw.id.au
* moves an elements up & down; once full hieght, once 40% of that height.
* Option:default
* height:100 // hieght, in pixels, of bounce
* fps:100 // Frames per second of the animation
*/

Effect.Bounce = function(element, options) {
  element = $(element);
  var opt = Object.extend({
  	height : 100,
		fps : 100
  }, {} | options);
  var oldStyle = {
    top: element.getStyle('top'),
    left: element.getStyle('left') };
    var h = opt.height;
		var f = opt.fps;
    return new Effect.Move(element, 
      { x: 0, y: 0-h,duration: 0.17, fps:f, afterFinishInternal: function(effect) {
    new Effect.Move(effect.element,
      { x: 0, y: h, duration: 0.18, fps:f, afterFinishInternal: function(effect) {
    new Effect.Move(effect.element,
      { x: 0, y: 0-(Math.round(h*0.4)), duration: 0.16, fps:f, afterFinishInternal: function(effect) {
    new Effect.Move(effect.element,
      { x: 0, y: Math.round(h*0.4), duration: 0.14, fps:f, afterFinishInternal: function(effect) {
        effect.element.undoPositioned();
        effect.element.setStyle(oldStyle);     	
      }}) }}) }}) }});
}


/*
* Class: Bouncer
* Written by: Andrew Tetlaw http://tetlaw.id.au
* takes a list and performs a bounce effect on a random list element at a regular interval
* Option:default
* interval:2 // how often to bounce a list item
*/
var Bouncer = Class.create();
 
Bouncer.prototype = {
	initialize : function(element, options) {
		this.element = $(element);
		this.options = Object.extend({
	  	interval : 2
 	 }, {} | options);
		this.items = $A(this.element.getElementsByTagName('LI'));
		var i = this.options.interval;
		new PeriodicalExecuter(this.bounceRandom.bind(this), i); 
	},
	bounceRandom : function() {
		var idx = Math.round(Math.random()*(this.items.length-1));
		new Effect.Bounce(this.items[idx]);
	}	
}

