var jkiDBHAnimation = new Class
(/** @lends jkiDBHAnimation.prototype */{

	name: 'jkiLocationMap',
//	basepath: 'http://jki.local/320/htdocs/html/images/animation/',
//	basepath: 'http://jki320.jaykelly.net/html/images/animation/',
	basepath: 'http://www.dbhconsulting.com/html/images/animation/',
	container: null,
	els : {
	
		'yousee' : null,
    	'somuch' : null,
    	'letus' : null,
    	'accelerate' : null
	
	},
	paths : new Hash({
	
		'yousee' : null,
    	'somuch' : null,
    	'letus' : null,
    	'accelerate' : null
	
	}),
	
	/**
	* @constructor
	* @member jkiDBHAnimation
	*/
	initialize: function()
	{
	
		this.container = $('homeAnimation');
		this.createImagePaths();
		this.createElements();
		this.preloadImages();
	
	},
	
	createImagePaths: function()
	{
		
		this.paths.yousee = this.basepath+'animation00.png';
		this.paths.somuch = this.basepath+'animation01.png';
		this.paths.letus = this.basepath+'animation02.png';
		this.paths.accelerate = this.basepath+'animation03.png';
		
	},
	
	createElements: function()
	{
		
		this.els.yousee = new Element('div',{
			
			styles : {
			
				position : 'absolute',
				top : '131px',
				left : '52px',
				width : '436px',
				height : '27px',
				backgroundImage : "url('"+this.paths.yousee+"')",
				backgroundRepeat : 'no-repeat',
				backgroundPosition : 'top left'
					
			}
			
		});
		this.els.somuch = new Element('div',{
			
			styles : {
			
				position : 'absolute',
				top : '153px',
				left : '52px',
				width : '330px',
				height : '52px',
				backgroundImage : "url('"+this.paths.somuch+"')",
				backgroundRepeat : 'no-repeat',
				backgroundPosition : 'top left'
					
			}
			
		});
		this.els.letus = new Element('div',{
			
			styles : {
			
				position : 'absolute',
				top : '180px',
				left : '52px',
				width : '343px',
				height : '53px',
				backgroundImage : "url('"+this.paths.letus+"')",
				backgroundRepeat : 'no-repeat',
				backgroundPosition : 'top left'
					
			}
			
		});
		this.els.accelerate = new Element('div',{
			
			styles : {
			
				position : 'absolute',
				top : '290px',
				left : '155px',
				width : '427px',
				height : '69px',
				backgroundImage : "url('"+this.paths.accelerate+"')",
				backgroundRepeat : 'no-repeat',
				backgroundPosition : 'top left'
					
			}
			
		});
		
	},
	
	preloadImages: function()
	{
		
		var loadImages = Asset.images(
		
			[
				this.paths.yousee,
				this.paths.somuch,
				this.paths.letus,
				this.paths.accelerate
			],
			
			{
			    
			    onComplete: function(){
			    
			    	this.prepNodes();
			    	
			    }.bind(this)
			
			}
			
		);
		
	},
	
	prepNodes: function()
	{
		
		this.els.yousee.fade('hide');
		this.els.somuch.fade('hide');
		this.els.letus.fade('hide');
		this.els.accelerate.fade('hide');
		
		this.fixIEProblems(this.els.yousee, this.paths.yousee);
		this.fixIEProblems(this.els.somuch, this.paths.somuch);
		this.fixIEProblems(this.els.letus, this.paths.letus);
		this.fixIEProblems(this.els.accelerate, this.paths.accelerate);
		
		this.els.yousee.fade('hide');
		this.els.somuch.fade('hide');
		this.els.letus.fade('hide');
		this.els.accelerate.fade('hide');
		
		this.els.yousee.inject(this.container);
		this.els.somuch.inject(this.container);
		this.els.letus.inject(this.container);
		this.els.accelerate.inject(this.container);
		
		this.beginSequence();
		
	},
	
	beginSequence: function()
	{
		
		var first = new Fx.Morph(this.els.yousee,{duration: 750,transition: Fx.Transitions.linear});
		var second = new Fx.Morph(this.els.somuch,{duration: 750,transition: Fx.Transitions.linear});
		var third = new Fx.Morph(this.els.letus,{duration: 750,transition: Fx.Transitions.linear});
		var fourth = new Fx.Morph(this.els.accelerate,{duration: 500,transition: Fx.Transitions.linear});
		
		
		first.start({
			
			'opacity' : 1
				
		}).chain(function(){
			
			first.start({
				
				'top' : 72
					
			}).chain(function(){
				
				second.start({
					
					'opacity' : 1
						
				}).chain(function(){
					
					
					second.start({
						
						'top' : 113
							
					}).chain(function(){
						
						third.start({
							
							'opacity' : 1
								
						}).chain(function(){
							
							var wait = function(){
								
								fourth.start({
									
									'opacity' : 1
										
								});
								
							}.delay(500);
					
						});
							
					});
					
				});
				
			});
			
		});
		
	},
	
	fixIEProblems: function(node,url)
	{
		
		if (!Browser.Engine.trident)
			return false;
		
		node.setStyle('background-image','none');
		var fixMe = new Element('div');
		fixMe.setStyles({
			
			'width' : '100%',
			'height' : '100%'
			
		});
		fixMe.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+url+"',sizingMethod='scale')";
		fixMe.inject(node);
		return true;
		
	}
	
});

window.addEvent('load', function()
{

	var homeAnimation = new jkiDBHAnimation();
	
});
