$j(function(){
	// sub navi fix
	if($j('ul.children').is(':visible')) {
		$j('#access').addClass('with-subnavi');
	}
	// banner randomizer
	if(!$j('body').hasClass('home')) {
		var r = Math.ceil(Math.random()*2);
		switch(r) {
			case 1: $j('#banner').css('background-position', 'left top'); break;
			case 2: $j('#banner').css('background-position', 'left bottom'); break;
		}
	}
	// artists gallery functionality
	if($j('#artists').length || $j('#artists-carousel').length) {
		$j('.artist-thumb').bind('mouseover', function(e){
			$j(this).css('z-index', '99');
			var lm = $j(this).children('.artist-info').outerWidth()/2;
			var offset = 0;
			
			if($j('#artists-carousel').length) {
				var maskWidth = $j('.jcarousel-clip').width();
				var pos = $j('#artists-carousel').position();
				var posLi = $j(this).parent('li').position();
				var facePos = pos.left + posLi.left + 53;
				if(facePos - lm < 0) offset = facePos - lm - 5;
				else if(facePos + lm > maskWidth) offset = facePos + lm - maskWidth + 5;
			}
			
			$j(this).children('.artist-info').css({'display' : 'block', 'margin-left' : '-'+(lm+offset)+'px'});
		});
		$j('.artist-thumb').bind('mouseout', function(e){
			$j(this).css('z-index', '1');
			$j(this).children('.artist-info').hide();
		});
		
		if($j('#artists-carousel').length) {
			$j('#artists-carousel').jcarousel({
				auto: 4,
				wrap: 'last',
				initCallback: carousel_initCallback
			});
		}
	}
});

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