ijs.featured_posts_controller = {
	
	'moving': false,
	'current': 0,
	'wrapper_height': 200,
	'interval': 10000,
	'interval_id': false,
	
	'show': function(id){
		
		if(this.moving === false && this.current != id){
			
			this.moving = id;
			this.moving_obj = this.posts[this.moving];
			this.current_obj = this.posts[this.current];
			
			ijs.css.set_opacity(this.moving_obj, 0);
			ijs.css.set_opacity(this.current_obj, 300);
			
			this.current_obj.style.top  = '0px';
			this.moving_obj.style.top = '0px';
			
			this.current_obj.style.zIndex = 1;
			this.moving_obj.style.zIndex = 2;
			
			this._p = this._v = 0;
			this.show_anim();
			
			}
			
		},
	
	'show_anim': function(){
		
		this._v += 0.5;
		this._p += this._v;
		
		this.current_obj.style.top = parseInt(this._p / 100 * this.wrapper_height) + 'px';
		
		ijs.css.set_opacity(this.moving_obj, parseInt(this._p));
		ijs.css.set_opacity(this.current_obj, 100 - parseInt(this._p));
		
		
		if(this._p < 100){
			setTimeout(function(){ ijs.featured_posts_controller.show_anim(); }, 10);
			}
		else{
			
			this.as[this.moving].className = this.as[this.current].className;
			this.as[this.current].className = '';
			
			this.current = this.moving;
			this.current_obj = this.moving_obj;
			this.moving = this.moving_obj = false;
			
			clearInterval(this.interval_id);
			this.interval_id = setInterval(function(){ijs.featured_posts_controller.interval_act();}, this.interval);
			}
		
		},
	
	'interval_act': function(){
		
		if(!this.moving)
			if(this.current == this.as.length-1)
				this.show(0);
			else
				this.show(this.current + 1);
		
		},
	
	'init': function(){
		
		this.main_wrapper = ijs.$$('featured_posts').first();
		this.as = ijs.$$('featured_posts_buttons', this.main_wrapper).first().getElementsByTagName('a');
		this.posts = ijs.$$('featured_posts_posts', this.main_wrapper).first().getElementsByTagName('li');
		this.current = 0;
		
		for(var i = 0, c = this.as.length; i < c ; ++i){
			this.as[i]._id = i;
			this.posts[i].style.position = 'absolute';
			if(i)
				this.posts[i].style.top = this.wrapper_height + 'px';
			this.as[i].onclick = function(){
				ijs.featured_posts_controller.show( this._id );
				return false;
				}
			
			}
		
		this.interval_id = setInterval(function(){ijs.featured_posts_controller.interval_act();}, this.interval);
		
		return false;
		
		}
	
	
	};


ijs.onload(function(){ijs.featured_posts_controller.init();});