/*
	JSFader 2008
	Fading utility for image slideshow made by johnnyseyd@gmail.com
	
	This tool fades an list of images fading in selected container (element).
	
	-------------------------------------------------------------------------
	-------------------------------------------------------------------------
	-------------------------------------------------------------------------
	
	Simply include this sctipt in your HTML, for example:
	<script type="text/javascript" src="JSFader.js"></script>
	
	and make an image container element, for example:
	<div id="box" style="border: 1px solid black; float: right;"></div>
	
	than include script like this:
	<script>
	<!--
		var fader = new JSFader('box');
		fader.setVisibleTime(2000);
		fader.setFadeTime(1000);
		fader.addImage('img/A.gif');
		fader.addImage('img/B.gif');
		fader.addImage('img/C.gif');
		fader.addImage('img/D.gif');
		fader.addImage('img/E.gif');
		fader.addImage('img/F.gif');
		fader.init();
	//-->
	</script>
	
	... and thats all!
	
	You have to create a new instance of JSFader object
	width parameter ID of container element, or direct an element object.
	
	Than you can set timing, visible time is how long will be visible each picture,
	and fade time how long will take fade between two pictures.
	It must be set in miliseconds (1000ms = 1sec).
	Default visible time is 1000ms and fade time is also 1000ms.
	
	Using method .addImage you can set an picture list (how many you want)
	and it will fade in that order which you will add it. It takes an string url of a picture.
	
	At last you have init (run) fader by method .init.
	
	And thats all....
	
	Recomendations:
	All pictures must have the same size. Container element size will be set automaticaly.
	If pictures are diffrent sized, container must be set at the minimum size (automaticaly).
	If you want set your own size (less then optimal minimal) set it throught style.
	
	You can make more instances of JSFader on one page and make more fading containers at same page.
	
	Have a good time!

*/


var JSFader=function($r){if(typeof($r)=='string')$r=document.getElementById($r);this.b=$r;this.b.style.position='relative';
this.b.style.overflow='hidden';this.g=new Array();this.$=new Array();};n=JSFader.prototype;n.b=null;n.g=null;n.$=null;n.J=0;
n.t=1000;n.H=1000;n.a=0;n.$m=function(_,h){_.onload=_.onerror=null;this.J++;_.$p=true;_.P=_.width;_.M=_.height;this.N();this.T();
};n.N=function(){var $e=10000;var $f=10000;for(var U=0;U<this.$.length;U++){var _=this.$[U];if(_.$p){if(_.P<$e)$e=_.P;if(_.M<$f)
$f=_.M;} };if(this.b.offsetWidth>$e||!this.b.style.width)this.b.style.width=$e+'px';if(this.b.style.height>$f||!this.b.style.height)
this.b.style.height=$f+'px';this.w=parseInt(this.b.style.width);this.v=parseInt(this.b.style.height);};n.$j=function(_,h){
_.onload=_.onerror=null;this.g.splice(h,1 );this.$.splice(h,1 );this.T();};n.T=function(){if(this.J==this.$.length)this.$q();};
n.I=function($i){for(var U=0;U<this.$.length;U++){var $n=$i&&U+1==this.$.length?100:0;if(U>0)o(this.$[U],$n);if($n==0&&U!=0)
this.$[U].style.display='none';this.b.appendChild(this.$[U]);} };n.$q=function(){this.I();this.a=0;this.X=this.Q.$$(this);
this.D=this.$g.$$(this);this.p(0,true);this.i();};n.C=25;n.p=function(h,G){var _=this.$[h];if(_.P>this.w||_.M>this.v){
var m=!G ?Math.round(Math.random()) :0;var u=!G ?Math.round(Math.random()) :0;var $t=m==0 ?1 :-1;var $u=u==0 ?1 :-1;
_.s=_.P-this.w;_.r=_.M-this.v;_.A=_.s*m;_.B=_.r*u;var $k=(this.t + this.H*2) / this.C/1.1;_.Y=(_.s*$t) / $k;_.Z=(_.r*$u) / $k;
if(Math.abs(_.Y)<0.2)_.Y=0;if(Math.abs(_.Z)<0.2)_.Z=0;_.style.left=Math.round(-_.A)+'px';_.style.top=Math.round(-_.B)+'px';
if(_.c){clearInterval(_.c);_.c=null;};if(_.Y!=0||_.Z!=0)_.c=setInterval(this.$d.$$(this,h),this.C);} };n.$d=function(h){
var $h=false;var _=this.$[h];_.A +=_.Y;_.B +=_.Z;if(_.A<0){_.A=0;$h=true;};if(_.B<0){_.B=0;$h=true;};if(_.A>_.s){_.A=_.s;
$h=true;};if(_.B>_.r){_.B=_.r;$h=true;};_.style.left=Math.round(-_.A)+'px';_.style.top=Math.round(-_.B)+'px';if($h){
clearInterval(_.c);_.c=null;} };n.W=null;n.i=function(){this.W=setTimeout(this.X,this.t);};n.Q=function(){this.a++;
if(this.a+1>this.$.length){this.a=0;this.I(true);};this.F();};n.l=50;n.F=function(){this.p(this.a);this.q=Math.round(this.H/this.l);
this.k=0;this.V=setTimeout(this.D,this.l);this.d=this.a==0 ?this.$.length-1 :this.a;this.$[this.d].style.display='block';
this.j=this.a==0 ?0 :this.a-1;this.$[this.j].style.display='block';};n.$g=function(){this.k++;var L=(this.k/this.q)*100;
if(this.k==this.q)L=100;if(this.a==0) L=100-L;if(this.k<this.q)this.V=setTimeout(this.D,this.l);else this.i();o(this.$[this.d],L);
if(this.k==this.q)this.$[this.a==0 ?this.d :this.j].style.display='none';};n.setVisibleTime=function($v){this.t=$v;};n.setFadeTime=function($v)
{this.H=$v;};n.addImage=function($w){var h=this.g.length;this.g[h]=$w;var _=this.$[h]=new Image();_.onload=this.$m.$$(this,_,h);
_.onerror=this.$j.$$(this,_,h);var $y=_.style;$y.position='absolute';$y.left='0';$y.top='0';};n.init=function(){
for(var U=0;U<this.$.length;U++)this.$[U].src=this.g[U];};Function.prototype.$$=function($o){var $l=this;var $c=Array.O(arguments);
return function(){return $l.apply($o,Array.concat($c,arguments));} };Array.concat=function(){var K=[];for(var U=0;U<arguments.length;U++)
for(var $x=0;$x<arguments[U].length;$x++)K.push(arguments[U][$x]);return K;};Array.O=function($_){var K=[];for(var U=1;U<$_.length;U++)
K.push($_[U]);return K;};o=function(S,z){if(z>100) z=100;if(document.all&&!window.opera)S.style.filter='Alpha(Opacity='+parseInt(z)+')';
else if(!document.all&&!window.opera&&document.getElementById)S.style.MozOpacity=parseFloat(z)/100;else S.style.opacity=parseFloat(z)/100;};

