function mycarousel_news(carousel){
    jQuery('.jcarousel-control a').click(function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).attr("rel")));
        carousel.startAuto(0);
        return false;
    });

    // 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();
    });

};

function change_class(selected_element){
    for(var i=1; i <= 5; i++){
        if(i == selected_element){
            $('.rel'+i).addClass('a_active');
        }else{
            $('.rel'+i).removeClass('a_active');
        }
    }
    return false;
}

function programming_itemLoadCallback(carousel){
    change_class(carousel.first);
}


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(); });
};

jQuery(document).ready(function() {
	jQuery('#mycarousel').jcarousel({
		initCallback: mycarousel_initCallback, vertical: true, scroll: 8,
		// This tells jCarousel NOT to autobuild prev/next buttons
		buttonNextHTML: null, buttonPrevHTML: null, auto: 5, wrap: 'last', easing: 'swing', animation: 'slow'
	});
	jQuery('#first-carousel').jcarousel({
		initCallback: mycarousel_initCallback, auto: 5, wrap: 'last', easing: 'swing', animation: 'slow', scroll: 1, buttonNextHTML: null, buttonPrevHTML: null
	});
	jQuery('#third-carousel').jcarousel({
		initCallback: mycarousel_initCallback, wrap: 'last', easing: 'swing', animation: 'slow', scroll: 1
	});
	jQuery('#featured-news-carousel').jcarousel({
		initCallback: mycarousel_news, auto: 5, wrap: 'last', easing: 'swing', animation: 'fast', scroll: 1, buttonNextHTML: null, buttonPrevHTML: null, itemLoadCallback: programming_itemLoadCallback
	});

	$("#first-carousel, #mycarousel, #internet_pictures, #quotes, #featured .photo").css("visibility", "visible");
});

