$(function() {

	/** 
	 * Cycle Plugin
	 * Cycle News
	 * ------------------------------------------------------------------*/
    var startingSlide = $('#news-container .layout_full').length - 1;
	$('#news-container').cycle({
		fx:     'scrollHorz',
		startingSlide: startingSlide,

		prev:   '#news-ctrl .prev', 
		next:   '#news-ctrl .next',
		after:   onAfter,
		before:	 onBefore,
		timeout: 0 ,
		height:        'auto',
		fit: false
	});	
	
	function onAfter(curr, next, opts) {	
		var index = opts.currSlide;		
		$('#news-ctrl .prev')[index == 0 ? 'hide' : 'show']();		
		$('#news-ctrl .next')[index == opts.slideCount - 1 ? 'hide' : 'show']();
		
		// Set container to new height
		//$('#news-container').height($(next).height());
		//console.log("After");

		$('#news-ctrl .container').fadeIn(500);
	}
	function onBefore(curr, next, opts) {
		//console.log("Start");
		$('#news-ctrl .container').hide();
		//$('#news-container').height($(next).height());
		
		var $ht = $(this).height();
		$(this).parent().animate({height: $ht});
		//$(this).parent().css({height: $ht});	
	}
	


	/** 
	 * Cycle Plugin
	 * Cycle Arbeiten
	 * ------------------------------------------------------------------*/
	$('#p-detail .ce_news_gallery').after('<div id="pager" class="nav">').cycle({
		fx:     'scrollHorz',
        timeout: 6000,
        pager:  '#pager',		
	});	
	// Stop slideshow after manuall click
	$('#p-detail #pager a').click(function(){ 
		$('#p-detail .ce_news_gallery').cycle('pause'); 
	}); 
	// Hide page if only one slide
	if ($('#p-detail #pager a').length <= 1) {
		$('#p-detail #pager a').hide();	
	}
	 
});
