jQuery(document).ready(function() {
	
	$('.top > ul > li').hover( function() {
		$(this).addClass('hover');
		$(this).children('.sub_menu').stop(true,true).fadeIn(500);
	}, function() {
		$(this).removeClass('hover');
		$(this).children('.sub_menu').stop(true,true).fadeOut(500);
	});
	
	$('.button span').textShadow();
	
	$('.carousel > ul').jcarousel({
		auto: 5,
		scroll: 1,
		animation: 500,
		wrap: 'circular',
        buttonNextHTML: null,
        buttonPrevHTML: null,
		initCallback: mycarousel_initCallback,
		itemVisibleInCallback: initActive
    });
	
});

function initActive(carousel) {
	var d = (((carousel.options.size*100)+carousel.last)%carousel.options.size);
	d = (d == 0) ? carousel.options.size : d;
	$('.jcontrol a').removeClass('active');
	$('.jcontrol a#jcontrol-a-'+d).addClass('active');
	$('.jtext').each(function() {
		$(this).css('display', 'none');
	});
	$('.jtext#box_'+d).fadeIn(700);
}

function mycarousel_initCallback(carousel)
{
	var jcHtml = "";
	for ( var i = 1; i <= carousel.options.size; i++ ) {
		jcHtml += '<a href="#" id="jcontrol-a-'+i+'">'+i+'</a>';
	}
	$('.jcontrol').html(jcHtml);
	jQuery('.jcontrol a').bind('click', function() {
		carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
		return false;
	});
	// Disable autoscrolling if the user clicks the prev or next button.
	
	jQuery('#butRight').bind('click', function() {			
		carousel.next();
		carousel.startAuto(0);
		return false;
	});

	jQuery('#butLeft').bind('click', function() {			
		carousel.prev();
		carousel.startAuto(0);
		return false;
	});

	// Pause autoscrolling if the user moves with the cursor over the clip.
	carousel.clip.hover(function() {
		carousel.stopAuto();
	}, function() {
		carousel.startAuto();
	});
};
