jQuery.noConflict();
var limit = 2;

jQuery(document).ready(function() {
	
	init_topProjects();
	jQuery('.prev').hide();
	
	function init_topProjects() {
		jQuery("#hotspots .news-list-item-hotspots").wrapAll("<div id='effect-container'><div id='effect-container-effect'></div></div>");
		jQuery("#effect-container").after('<div id="ctrl"></div>');
		jQuery(".news-list-morelink-hotspots a").attr('rel','more');
		jQuery("#ctrl").html('<a class="prev" href="#">&nbsp;</a><a class="next" href="#">&nbsp;</a><div style="clear: both; float:none;"></div>');
		for(i = 0; i < jQuery("#hotspots .news-list-item-hotspots").length; i+=limit)
		{
			if (jQuery("#hotspots .news-list-item-hotspots").eq(i).length > 0)
			{
				jQuery("#hotspots .news-list-item-hotspots").filter(function(index) {
					return (index < (i+limit) && index >= i);
				}).wrapAll("<div class='page'></div>");			
			}
		}
	}
	jQuery('#effect-container').serialScroll({
		items:'.page',
		prev:'a.prev',
		next:'a.next',
		duration: 500,
		stop:true,
		cycle:false,
		easing:'easeOutQuint',
		jump:true,
		onBefore:function( e, elem, $pane, $items, pos ){
			jQuery('.prev').add(jQuery('.next')).show();
			if( pos == 0 )
				jQuery('.prev').hide();
			else if( pos == $items.length-1 )
				jQuery('.next').hide();
		}
	});
	
	jQuery('a[rel~=more]').click(function() {
		window.location.href = this.href;
	});
	
	function mycarousel_initCallback(carousel)	{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });
 
    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });
 
    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
	};
	
	var items = 0;
	var scroll = 1;
	jQuery('#regionwelsland-carousel li').each(function(){
		items++;
	});
	if (items<4) scroll = 0;
								
    jQuery('#regionwelsland-carousel').jcarousel({
    	wrap: 'circular',
		visible: 3,
		auto: 10,
		scroll: scroll,
		initCallback: mycarousel_initCallback
    });
});
