
anim={};
anim.preload=["./gfx/b1/1.jpg","./gfx/b1/2.jpg","./gfx/b1/3.jpg","./gfx/b1/4.jpg","./gfx/b2/1.jpg","./gfx/b2/2.jpg","./gfx/b2/3.jpg","./gfx/b2/4.jpg","./gfx/b3/1.jpg","./gfx/b3/2.jpg","./gfx/b3/3.jpg","./gfx/b3/4.jpg"];
anim.color1=["#E8B320","#FADF96","#722811","#483118","#A5713D"];
anim.color2=['#94C046','#B58515','#E1DECE','#F7C5A6','#EFCD37'];
anim.color3=['#736C00','#8C9D79','#7D6566','#CEB866','#818070'];

anim.waitTime1=3500;
anim.waitTime2=4000;
anim.waitTime3=4500;

anim.c1=0;
anim.c2=0;
anim.c3=0;
anim.c1c=0;
anim.c2c=0;
anim.c3c=0;


anim.colorate1 = function(){
    this.c1c++;
    this.c1c=this.c1c%this.color1.length;
    $('div.d1').animate({backgroundColor: ""+anim.color1[anim.c1c]},1000,function(){ setTimeout("anim.colorate1()",anim.waitTime3+Math.floor(Math.random()*1000-500)); });
}

anim.colorate2 = function(){
    this.c2c++;
    this.c2c=this.c2c%this.color2.length;
    $('div.d2').animate({backgroundColor: ""+anim.color2[anim.c2c]},1000,function(){ setTimeout("anim.colorate2()",anim.waitTime1+Math.floor(Math.random()*1000-500)); });
}

anim.colorate3 = function(){
    this.c3c++;
    this.c3c=this.c3c%this.color3.length;
    $('div.d3').animate({backgroundColor: ""+anim.color3[anim.c3c]},1000,function(){ setTimeout("anim.colorate3()",anim.waitTime2+Math.floor(Math.random()*1000-500)); });
}

anim.animate1 = function(){
	this.c1++;
	this.c1=this.c1%4;
	var dir='./gfx/b1/';
	var bnum='1';
	var nextImg =  $("<img></img>");
	$(nextImg).attr("src",dir+(this.c1+1)+".jpg");
	$(nextImg).unbind("load");
	$(nextImg).bind("load",function(){
		$('#b'+bnum+"o").stop(true,true).hide(0,function(){
			$('#b'+bnum+"o img").attr('src',dir+(anim.c1+1)+".jpg");
			$('#b'+bnum+"o").fadeIn(1000,function(){
				$('#b'+bnum).attr('src',dir+(anim.c1+1)+".jpg");
				$('#b'+bnum+"o").hide(0);				
			});			
		});		
		setTimeout("anim.animate1()", anim.waitTime1);
	});
	
}

anim.animate2 = function(){
	this.c2++;
	this.c2=this.c2%4;
	var dir='./gfx/b2/';
	var bnum='2';
	var nextImg =  $("<img></img>");
	$(nextImg).attr("src",dir+(this.c2+1)+".jpg");
	$(nextImg).unbind("load");
	$(nextImg).bind("load",function(){
		$('#b'+bnum+"o").stop(true,true).hide(0,function(){
			$('#b'+bnum+"o img").attr('src',dir+(anim.c2+1)+".jpg");
			$('#b'+bnum+"o").fadeIn(1000,function(){
				$('#b'+bnum).attr('src',dir+(anim.c2+1)+".jpg");
				$('#b'+bnum+"o").hide(0);
			});
		});
		setTimeout("anim.animate2()", anim.waitTime2);
	});

}

anim.animate3 = function(){
	this.c3++;
	this.c3=this.c3%4;
	var dir='./gfx/b3/';
	var bnum='3';
	var nextImg =  $("<img></img>");
	$(nextImg).attr("src",dir+(this.c3+1)+".jpg");
	$(nextImg).unbind("load");
	$(nextImg).bind("load",function(){
		$('#b'+bnum+"o").stop(true,true).hide(0,function(){
			$('#b'+bnum+"o img").attr('src',dir+(anim.c3+1)+".jpg");
			$('#b'+bnum+"o").fadeIn(1000,function(){
				$('#b'+bnum).attr('src',dir+(anim.c3+1)+".jpg");
				$('#b'+bnum+"o").hide(0);
			});
		});
		setTimeout("anim.animate3()", anim.waitTime3);
	});

}

anim.preloadImages = function(){
	var nextImg = [];
	for(var i=0;i<anim.preload.length;i++){
		nextImg[i] =  $("<img></img>");
		$(nextImg[i]).attr("src",anim.preload[i]);
	}
}

$().ready(function(){
	anim.preloadImages();
	setTimeout("anim.animate1()", anim.waitTime1);
	setTimeout("anim.animate2()", anim.waitTime2);
	setTimeout("anim.animate3()", anim.waitTime3);
	setTimeout("anim.colorate1()", anim.waitTime3);
	setTimeout("anim.colorate2()", anim.waitTime1);
	setTimeout("anim.colorate3()", anim.waitTime2);
});
