/******************************************************************************
Name:    SiMa Content Fader JS
Version: 2.0 (Juli 2010)
Author:  Michael Preis @ SiMa Design
Support: http://www.simadesign.de
******************************************************************************/

jQuery.noConflict();
// Newsfader


// Move elements

function doFade(direction) {
 
 		// fade-out the visible object
 		jQuery('.sima_slider_boxcount:visible').fadeOut(1000);
		
		// check if the object wasn't the last one
		var nextbox = jQuery('.sima_slider_boxcount:visible').next('.sima_slider_boxcount').length;
		var prevbox = jQuery('.sima_slider_boxcount:visible').prev('.sima_slider_boxcount').length;
		
		if (direction == "forward")
		{
			if ( nextbox > 0 )
			{
				// fade in the next object
				jQuery('.sima_slider_boxcount:visible').next('.sima_slider_boxcount').fadeIn(1000);
			}
			else
			{
				// fade-in the first element
				jQuery('.sima_slider_boxcount:first').fadeIn(1000);
			}
		}
		else if (direction == "previous")
		{
			if ( prevbox > 0 )
			{
				// fade in the next object
				jQuery('.sima_slider_boxcount:visible').prev('.sima_slider_boxcount').fadeIn(1000);
			}
			else
			{
				// fade-in the first element
				jQuery('.sima_slider_boxcount:last').fadeIn(1000);
			}
		}
}

jQuery(function(){

		// set the configuration for the fader
		jQuery('.sima_slider_boxcount').css({"position":"absolute"});
		jQuery('.sima_slider_boxcount').css({"left":"0"});
		jQuery('.sima_slider_boxcount').css({"top":"0"});
		jQuery('.sima_slider_boxcount').css({"display":"none"});
		jQuery('.sima_slider_boxcount:first').css({"display":"block"});

		// Fade per time

		 sliderIntervalID = setInterval(function(){
			doFade("forward");
		},5000);


		// Fade per click
		 
		jQuery('div.highlight_articles_right a').click(function() {  
	
			jQuery('.sima_slider_boxcount').stop(true,true);
	
			doFade("forward");
			
			/* restart the Slide-Per-Time frequenz */
			clearInterval(sliderIntervalID);
			
			sliderIntervalID = setInterval(function(){
				doFade("forward");
			},5000);
			
			return false;

//			var box_restcount = this.id;			
//			movebyclick(box_restcount);
		
		} );

		jQuery('div.highlight_articles_left a').click(function() {  
	
			jQuery('.sima_slider_boxcount').stop(true,true);
	
			doFade("previous");
			
			/* restart the Slide-Per-Time frequenz */
			clearInterval(sliderIntervalID);
			
			sliderIntervalID = setInterval(function(){
				doFade("forward");
			},5000);
			
			return false;

//			var box_restcount = this.id;			
//			movebyclick(box_restcount);
		
		} );

});
