// burningdiv
//
// Burning Div v0.4 - jQuery effect
// Copyright (c) 2009 Peter Medl
//
// License: MIT and GPL
// http://www.opensource.org/licenses/mit-license.php
// http://www.gnu.org/licenses/gpl.html
// do anything you want with the code but don`t claim its yours
// Homebase: http://www.atomad.de
// 
// Usage (from html doc)
// // override defaults for resolution, speed, height
// var options = {
//  res: 100,
//  speed: 100,
//  height: 20
//
// }
// $('myDiv').burningdiv('imgDiv', options);


(function($) { 
$.fn.burningdiv = function(imgID,options) {
	var config = {'res': '100','speed': '10','height': '20'};
	stripeobj = function(){
		this.items = Array();
		this.runner = 0; // for functions
		this.timer = null;
	}
	imgitem = function(theobj,width,height)
	{
  		this.obj = theobj;
  		this.width = width;
  		this.height = height;
	}
	
	var thestripe = new stripeobj();
  	//var $this = $( this ); 
   	if (options) $.extend(config, options);
	
	var sine = 0;
	// some effects functions
	function anim(){
		for (i=0;i<thestripe.items.length;i++){
			// randomizer use it with high values to give the illusion of fire e.g. resolution 300 speed 200
			//thestripe.items[i].obj.css("height", options['height']*Math.random(1)+"px");
			// sin wave; use runner value for iterator
			
			//thestripe.items[i].obj.css("height", options['height']+(Math.sin(i)*thestripe.runner));
			var newh = (options['height']+Math.sin(sine*options['height'])*thestripe.runner/100);
			thestripe.items[i].obj.css("height",newh);
			sine+=0.01;
			thestripe.runner+=1;
			if (thestripe.runner>720)thestripe.runner=0;
		}
	}
	
	return this.each(function() {
		// retrieve img obj
		var obj = $(this);
		var myimg = $("img", obj);  
		
		var imgwidth = Math.round(obj.width()/options['res']);
		//alert (imgwidth);
		// iterate through resolution number of img
		for (i=0;i<options['res'];i++){//options['res']
			var nimg = myimg.clone();
			//thestripe.items[thestripe.items.length]=nimg;
			thestripe.items[thestripe.items.length]=new imgitem(nimg,10,20);
			nimg.appendTo(obj);
			nimg.css("width", imgwidth+"px");
			nimg.css("height", "20px");
		}
		// rem org
		myimg.remove();
		//alert(thestripe.items.length);
		//myimg.css("border", "3px double red");
		//obj.css('left','100px');
		stripeobj.timer = setInterval(anim,options['speed']);
    });
 ;}
})(jQuery);

/*
// helper
function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

*/
