/******************************************************************************
 *
 * figureof8.js - class FigureOfEight 1.0.0
 *
 * Copyright (c) 2007 NI-Lab.
 *
 * Author: NI-Lab.
 * Access: http://www.nilab.info/
 * Since : 2007-01-09
 *
 *****************************************************************************/

/*
 * class FigureOfEight License
 *
 * Copyright (c) 2007 NI-Lab.
 *
 * 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.
 */
///////////////////////////////////////////////////////////////////////////
// class FigureOfEight (中途半端なクラス化)

	// Ref.
	// - StopGeek.com Neat Trick With Javascript | Programming #1 stop for your daily dose of geek!
	//   http://stopgeek.com/neat-trick-with-javascript.html
	//
	// original code:
	// javascript:R=0; x1=.1; y1=.05; x2=.25; y2=.24; x3=1.6; y3=.24; x4=300; y4=200; x5=300; y5=200; DI=document.getElementsByTagName("img"); DIL=DI.length; function A(){for(i=0; i-DIL; i++){DIS=DI[ i ].style; DIS.position='absolute'; DIS.left=(Math.sin(R*x1+i*x2+x3)*x4+x5)+"px"; DIS.top=(Math.cos(R*y1+i*y2+y3)*y4+y5)+"px"}R++}setInterval('A()',5); void(0);

	// Ref.
	// - Uno, dos, tres, quatro!setIntervalの引数にオブジェクトメソッドを渡す
	//   http://blog.33rpm.jp/technology/studying_javascript.html
	Function.prototype.FigureOfEight_bind = function(object) {
		var __method = this;
		return function() {
		return __method.apply(object, arguments);
		}
	}

	/**
	 * @param elements NodeList
	 * @param interval 移動間隔(ミリ秒)
	 */
	function FigureOfEight(elements, interval){

		this.DI  = elements;
		this.DIL = this.DI.length;

		if(interval){
			this.interval = interval;
		}else{
			this.interval = 30; // default interval
		}

		this.R   = 0;
		this.x1  = 0.1;
		this.y1  = 0.05;
		this.x2  = 0.25;
		this.y2  = 0.24;
		this.x3  = 1.6;
		this.y3  = 0.24;
		this.x4  = 200;
		this.y4  = 150;
		this.x5  = 200;
		this.y5  = 150;
		this.itv = null;
	}

	FigureOfEight.prototype.start = function(){
		if(!this.itv){
			this.itv = setInterval(this.move.FigureOfEight_bind(this), this.interval);
		}
	}

	FigureOfEight.prototype.stop = function(){
		if(this.itv){
			clearInterval(this.itv);
			this.itv = null;
		}
	}

	FigureOfEight.prototype.move = function(){
		for(var i=0; i - this.DIL; i++){
			var DIS = this.DI[i].style;
			DIS.position = 'absolute';
			DIS.left = (Math.sin(this.R * this.x1 + i * this.x2 + this.x3) * this.x4 + this.x5) + "px";
			DIS.top = (Math.cos(this.R * this.y1 + i * this.y2 + this.y3) * this.y4 + this.y5) + "px";
		}
		this.R++;
	}

///////////////////////////////////////////////////////////////////////////
