/**
 * We use the initCallback callback
 * to assign functionality to the controls
 */
function mycarousel_initCallback(carousel) {
    jQuery('.jcarousel-control a').bind('mouseenter', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
        return false;
    });

    jQuery('.jcarousel-scroll select').bind('change', function() {
        carousel.options.scroll = jQuery.jcarousel.intval(this.options[this.selectedIndex].value);
        return false;
    });

    jQuery('#mycarousel-next').bind('mouseenter', function() {
        carousel.next();
        return false;
    });

    jQuery('#mycarousel-prev').bind('mouseenter', function() {
        carousel.prev();
        return false;
    });

	jQuery(".jcarousel-control a").mouseover(function(){
		// clear all the classes from 'a' tags
    	$('.jcarousel-control a').removeClass();
    	//add 'on' class to hovered element
    	$(this).addClass("on");
    });

};
// Ride the carousel...
jQuery(document).ready(function() {
    jQuery("#mycarousel").jcarousel({
        scroll: 1,
		animation: "fast",
		vertical: true,
        initCallback: mycarousel_initCallback,
        // This tells jCarousel NOT to autobuild prev/next buttons
        buttonNextHTML: null,
        buttonPrevHTML: null
    });
	
	$('#moreTopStories .minus').bind("click", moreTopStoriesHideLast);
	$('#moreTopStories .plus').bind("click", moreTopStoriesShowNext);
	
});

function moreTopStoriesReduce(){
	while($('#moreTopStories li:visible').length > 8){	//hide the last three new items
		moreTopStoriesHideLast();
	}
}

function moreTopStoriesShowNext(){	
	var hiddenLis = $('#moreTopStories li:hidden');
	if((hiddenLis.length) > 0){
		$(hiddenLis[0]).show();	
	}
}
	
function moreTopStoriesHideLast(){	
	var visibleLis = $('#moreTopStories li:visible');	
	var o = 0;
	o = $('#moreTopStories li:visible').length;		
	if(o > 0){
		$(visibleLis[o-1]).hide();
	}
}
