/**
 * FeaturedArticles - article rotator
 *
 * @version		1.0.1
 *
 * @license		MIT-style license
 * @author		Constantin Boiangiu <constantin [at] php-help.ro>
 * @copyright	Author
 */

var FeaturedArticles=new Class({Implements:[Options],options:{container:null,slides:null,slideDuration:null,effectDuration:1000,fadeDist:null,fadePosition:null,stopSlideOnClick:true,autoSlide:true,infoContainers:null,visibleInfo:false,navigationHeight:null,navigationNums:true},initialize:function(A){this.setOptions(A);if(!$(this.options.container)||!this.options.slides){return}this.currentKey=0;this.container=$(this.options.container);this.start()},start:function(){this.prepareSlides();this.injectNavigation();if(this.options.autoSlide){this.period=this.startSlides.bind(this).periodical(this.options.slideDuration||5000);this.container.addEvents({mouseenter:function(A){$clear(this.period);this.infos[this.currentKey].morph({bottom:0})}.bind(this),mouseleave:function(A){this.period=this.startSlides.bind(this).periodical(this.options.slideDuration||5000);this.infos[this.currentKey].morph({bottom:-500})}.bind(this)})}if(this.options.infoContainers){this.infoEffects()}},infoEffects:function(){this.infos=this.container.getElements(this.options.infoContainers);this.infos.setStyles({bottom:this.options.visibleInfo?0:-500});this.infos.set("morph",{wait:false,duration:1000,transition:"back:in:out"})},prepareSlides:function(){this.slides=this.container.getElements(this.options.slides);this.slides.set("morph",{wait:false,duration:this.options.effectDuration||800,transition:"cubic:out"});this.totalSlides=this.slides.length;this.slides.setStyles({position:"absolute",top:0,left:0,opacity:0});this.slides[this.currentKey].setStyle("opacity",1)},injectNavigation:function(){var A=new Element("div",{"class":"FA_navigation",styles:{opacity:0,height:0},morph:{wait:false,duration:900,transition:"sine:out"}}).injectAfter(this.container);this.navLinks=[];this.slides.each(function(C,B){this.navLinks[B]=new Element("a",{html:this.options.navigationNums?B+1:"",href:"#",title:"Click to navigate",events:{click:function(D){D.preventDefault();$clear(this.period);this.goToSlide(B);if(!this.options.stopSlideOnClick&&this.options.autoSlide){this.period=this.startSlides.bind(this).periodical(this.options.slideDuration||5000)}}.bind(this)}}).injectInside(A);if(B==this.currentKey){this.navLinks[B].addClass("active")}}.bind(this));A.morph({opacity:1,height:this.options.navigationHeight||30})},startSlides:function(){var A=this.currentKey+1>=this.totalSlides?0:this.currentKey+1;this.goToSlide(A)},goToSlide:function(A){if(A==this.currentKey){return}var B=this.options.fadePosition=="left"?"left":"top";switch(B){case"top":this.slides[this.currentKey].morph({opacity:0,top:this.options.fadeDist});this.slides[A].setStyle(B,-this.options.fadeDist).morph({opacity:1,top:0});break;case"left":this.slides[this.currentKey].morph({opacity:0,left:this.options.fadeDist});this.slides[A].setStyle(B,-this.options.fadeDist).morph({opacity:1,left:0});break}this.navLinks[this.currentKey].removeClass("active");this.navLinks[A].addClass("active");this.currentKey=A}});

window.addEvent('domready', function(){
	new FeaturedArticles({
		container: 'FA_featured_articles',
		slides: '.FA_article',
		slideDuration:5000,
		effectDuration:1000,
		fadeDist:600,
		fadePosition:'left',
		stopSlideOnClick: false,
		autoSlide: true,
		infoContainers: '.FA_info',
		visibleInfo: false,
		navigationHeight: 21,
		navigationNums: false // if true, numbers will appear
	});
})