var slideshowsData=[],slideshows=[],accordion,timers=[];

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

	/*	Preload mouseover images */
	
	new Asset.images(['/images/icons/icon-1o.png','/images/icons/icon-2o.png','/images/icons/icon-3o.png','/images/icons/icon-4o.png','/images/icons/icon-5o.png']);
	
	/*	Create mouseover effects for footer images */
	
	var footerIcons=$('footerIcons').getElements('img');
	footerIcons.each(function(value,key){
	
		value.addEvent('mouseover',function(){
		
			this.src=this.src.substr(0,this.src.length-4)+'o.png';
		
		});
	
		value.addEvent('mouseout',function(){
		
			this.src=this.src.substr(0,this.src.length-5)+'.png';
		
		});
	
	});
	
	/*	Apply slideshow where available */
	
	for(var i=0;i<slideshowsData.length;i++){
	
		if($('sectionSlideShow'+i)&&slideshowsData[i].length>0){
	
			slideshows[i]=new Slideshow('sectionSlideShow'+i,slideshowsData[i],{
			
				width:460,
				height:300,
				hu:'/biomechanix/images/',
				delay:6000,
				captions:true
			
			});
			
		}
	
	}
	/*	Apply accordion where available */
	
	if($('accordion')){
	
		accordion=new Accordion($('accordion'),'.toggler','.element',{
		
			'opacity':false,
			'onActive':function(toggler,element){
			
				toggler.setStyles({
				
					'border-top':'1px solid #333333',
					'color':'#000000'
				
				});
			
			},
			'onBackground':function(toggler,element){
			
				toggler.setStyles({
				
					'border-top':'1px solid #CCCCCC',
					'color':'#999999'
				
				});
			
			}
			
		});
	
	}
	
	/*	Initialize any forms */
	
	initializeForms($('mainContents'));
	
	/*	Set the countdown timer if available */
	
	for(var i in timers) if($('countdownDaysLeft'+i)) setCountDownItem.periodical(1000,timers[i],i);

});

function setCountDownItem(prefix){

	var currentTime=new Date();
	var days=(this-currentTime)/1000/60/60/24;
	var daysRound=Math.floor(days);
	var hours=(this-currentTime)/1000/60/60-(24*daysRound);
	var hoursRound=Math.floor(hours);
	var minutes=(this-currentTime)/1000/60-(24*60*daysRound)-(60*hoursRound);
	var minutesRound=Math.floor(minutes);
	var seconds=(this-currentTime)/1000-(24*60*60*daysRound)-(60*60*hoursRound)-(60*minutesRound);
	var secondsRound=Math.round(seconds);
	
	daysRound=daysRound<10?'0'+daysRound.toString():daysRound;
	hoursRound=hoursRound<10?'0'+hoursRound.toString():hoursRound;
	minutesRound=minutesRound<10?'0'+minutesRound.toString():minutesRound;
	secondsRound=secondsRound<10?'0'+secondsRound.toString():secondsRound;
	
	$('countdownDaysLeft'+prefix).set('text',daysRound);
	$('countdownTimeLeft'+prefix).set('text',hoursRound+':'+minutesRound+':'+secondsRound);

}