/******************************************************************************
Name:    SiMa Content Fader JS
Version: 2.0 (Juli 2010)
Author:  Michael Preis @ SiMa Design
Support: http://www.simadesign.de
******************************************************************************/

jQuery.noConflict();
// Newsfader

var container_arrow = '.teaser_icatch';
var fadetimer_arrow = 7000;

// Move elements

function movebyclick_arrow(box_restcount_arrow) {

	// check if the object isn't allready shown
	if ( jQuery(container_arrow + ' .sima_slider_boxcount:eq('+ box_restcount_arrow +')').is(':hidden') )
	{

 		// fade-out the visible object
 		jQuery(container_arrow + ' .sima_slider_boxcount:visible').fadeOut(1000);

		// fade action
		jQuery(container_arrow + ' .sima_slider_boxcount:eq('+ box_restcount_arrow +')').fadeIn(1000);

		// Change the Border and opacity of the click-element
		jQuery(container_arrow + ' li.sima_fader_click').css("background-color", "");
		jQuery(container_arrow + ' li.sima_fader_click.'+box_restcount_arrow).css("background-color", "#2c7acc");
		
	}
	
	/* restart the Slide-Per-Time frequenz */
	clearInterval(sliderIntervalID_arrow);
	
	sliderIntervalID_arrow = setInterval(function(){
		doFade_arrow("forward");
	},fadetimer_arrow);

}

function doFade_arrow(direction) {
 
 		// fade-out the visible object
 		jQuery(container_arrow + ' .sima_slider_boxcount:visible').fadeOut(1000);
		
		// check if the object wasn't the last one
		var nextbox_arrow = jQuery(container_arrow + ' .sima_slider_boxcount:visible').next(container_arrow + ' .sima_slider_boxcount').length;
		var prevbox_arrow = jQuery(container_arrow + ' .sima_slider_boxcount:visible').prev(container_arrow + ' .sima_slider_boxcount').length;
		
		if (direction == "forward")
		{
			if ( nextbox_arrow > 0 )
			{
				
				var boxcount = jQuery(container_arrow + " .sima_slider_boxcount").index(jQuery(container_arrow + " .sima_slider_boxcount:visible"));
				var boxcountnew = boxcount + 1;
		
				// Change the Border and opacity of the click-element
				jQuery(container_arrow + ' li.sima_fader_click.'+boxcount).css("background-color", "");
				jQuery(container_arrow + ' li.sima_fader_click.'+boxcountnew).css("background-color", "#2c7acc");

				// fade in the next object
				jQuery(container_arrow + ' .sima_slider_boxcount:visible').next(container_arrow + ' .sima_slider_boxcount').fadeIn(1000);
	
			}
			else
			{
				// fade-in the first element
				jQuery(container_arrow + ' .sima_slider_boxcount:first').fadeIn(1000);
				// Change the Border and opacity of the click-element
				jQuery(container_arrow + ' li.sima_fader_click').css("background-color", "");
				jQuery(container_arrow + ' li.sima_fader_click.0').css("background-color", "#2c7acc");
			}
			
			
		}
		else if (direction == "previous")
		{
			if ( prevbox_arrow > 0 )
			{

				var boxcount = jQuery(container_arrow + " .sima_slider_boxcount").index(jQuery(container_arrow + " .sima_slider_boxcount:visible"));
				var boxcountnew = boxcount - 1;
					
				// Change the Border and opacity of the click-element
				jQuery(container_arrow + ' li.sima_fader_click.'+boxcount).css("background-color", "");
				jQuery(container_arrow + ' li.sima_fader_click.'+boxcountnew).css("background-color", "#2c7acc");
				
				// fade in the next object
				jQuery(container_arrow + ' .sima_slider_boxcount:visible').prev(container_arrow + ' .sima_slider_boxcount').fadeIn(1000);
								
			}
			else
			{
				// fade-in the first element
				jQuery(container_arrow + ' .sima_slider_boxcount:last').fadeIn(1000);
				// Change the Border and opacity of the click-element
				jQuery(container_arrow + ' li.sima_fader_click').css("background-color", "");
				jQuery(container_arrow + ' li.sima_fader_click:last').css("background-color", "#2c7acc");
			}
		}
}

jQuery(function(){

		// change the cursor to a pointer
		jQuery(container_arrow + ' .sima_fader_click').mouseover(function() {
		  jQuery(this).css('cursor', 'pointer')
		});

		// set the configuration for the fader
		jQuery(container_arrow + ' .sima_slider_boxcount').css({"position":"absolute"});
		jQuery(container_arrow + ' .sima_slider_boxcount').css({"display":"none"});
		jQuery(container_arrow + ' .sima_slider_boxcount:first').css({"display":"block"});


		// set border Color
		jQuery(container_arrow + ' .sima_fader_click.0').css("background-color", "#2c7acc");
		jQuery(container_arrow + ' .sima_fader_click.0').css("opacity", "1.0");

		// Fade per time

		 sliderIntervalID_arrow = setInterval(function(){
			doFade_arrow("forward");
		},fadetimer_arrow);


		// Fade per click

		jQuery(container_arrow + ' li.sima_fader_click').click(function() {  
			
			var box_restcount_arrow = jQuery(this).attr("alt");
			movebyclick_arrow(box_restcount_arrow);

		} );
	 
		jQuery(container_arrow + ' div.highlight_articles_right a').click(function() {  
	
			jQuery(container_arrow + ' .sima_slider_boxcount').stop(true,true);
	
			doFade_arrow("forward");
			
			/* restart the Slide-Per-Time frequenz */
			clearInterval(sliderIntervalID_arrow);
			
			sliderIntervalID_arrow = setInterval(function(){
				doFade_arrow("forward");
			},fadetimer_arrow);
			
			return false;
		
		} );

		jQuery(container_arrow + ' div.highlight_articles_left a').click(function() {  
	
			jQuery(container_arrow + ' .sima_slider_boxcount').stop(true,true);
	
			doFade_arrow("previous");
			
			/* restart the Slide-Per-Time frequenz */
			clearInterval(sliderIntervalID_arrow);
			
			sliderIntervalID_arrow = setInterval(function(){
				doFade_arrow("forward");
			},fadetimer_arrow);
			
			return false;
		
		} );

});
