Event.observe(window, 'load', function() {
	homeFeature();
});

/* ==============================================================
   ======================== Home Feature ========================
   ============================================================== */
   
var featurePosition = 0;
   
function homeFeature() {
	if($('homeFeature') != undefined){			
		$$('#homeFeature li').each(function(elm){ 
			elm.setStyle("display: block");
			if(!elm.hasClassName("current")){
				elm.down('.title').setStyle("top: 61px;");
				elm.down('.headline').setStyle("top: 78px;");
				elm.down('.link').setStyle("top: 320px;");
			}
		});
		setTimeout('featureTransition()', 8000);
	}
}

function featureTransition() {
	var elmCount = $$('#homeFeature li').size();
	
	var elm = $$('#homeFeature .current')[0];
	
	if(elmCount > 1){
		elm.fade({duration: 0.6, afterFinish: function(){ 
			$$('#homeFeature .current .heading .title')[0].setStyle("top: 61px;");
			$$('#homeFeature .current .heading .headline')[0].setStyle("top: 78px;");
			$$('#homeFeature .current .link')[0].setStyle("top: 320px;");
			
			elm.removeClassName('current');
			elm.setStyle('display: block');
			
			var nextElm = $$('#homeFeature .next')[0];
			
			nextElm.removeClassName('next');
			nextElm.addClassName('current');
			
			if(elmCount - 1 == featurePosition) {
				$$('#homeFeature li')[1].addClassName('next');
			} else if(elmCount - 1 == featurePosition + 1){
				$$('#homeFeature li')[0].addClassName('next');
			}
			else {
				$$('#homeFeature li')[featurePosition + 2].addClassName('next');
			}
			setTimeout('featureTransition()', 8000);		
		}});
		
		$$('#homeFeature .next .heading .title')[0].morph('top: 21px;', {duration: 0.3});
		$$('#homeFeature .next .heading .headline')[0].morph('top: 38px;', {duration: 0.5});
		$$('#homeFeature .next .link')[0].morph('top: 280px;', {duration: 0.5});
	}			
	
	if(featurePosition == elmCount - 1){
		featurePosition = 0;
	}
	else {
		featurePosition ++;
	}
}
