jQuery(function($) {
	
	var interval = setInterval(switch_slide, 4000);
	function switch_slide() {
		var current = $('#slider-nav a').index($('#slider-nav a.active'));
		var total = $('#slider-nav a').length;
		if (current == total - 1) {
			current = 0;
		} else {
			current++;
		}
		$('#slider-nav a:eq(' + current + ')').trigger('click');
		
	}
	
	$('#home-slider #slider-nav a').live('click', function() {
		var idx = $('#home-slider #slider-nav a').index($(this));
		if ($('#home-slider .slide:eq(' + idx + ')').is(':visible') || $('#home-slider .slide:animated').length) {
			return false;
		}
		$('#home-slider .slide:visible').fadeOut(1000);
		$('#home-slider .slide:eq(' + idx + ')').fadeIn(1000);
		$('#home-slider #slider-nav a.active').removeClass('active');
		$(this).addClass('active');
		clearInterval(interval);
		interval = setInterval(switch_slide, 4000);
		return false;
	});
	
	$('#calendar .head-cnt').each(function() {
		$(this).find('li:last').addClass('last');
	});
	
	$('.select-all input').change(function() {
		if ($(this).is(':checked')) {
			$('.download-item input').attr('checked', 'checked');
		} else {
			$('.download-item input').removeAttr('checked');
		}
	});
	
	$('#press-entries .press-entry-head').click(function() {
		var body = $(this).parent().find('.press-entry-body');
		if (body.is(':animated')) {
			return false;
		}
		if (body.is(':visible')) {
			body.slideUp();
			$(this).removeClass('expanded');
		} else {
			body.slideDown();
			$(this).addClass('expanded');
		}
	});
	
	$('.colorbox').colorbox();
	$('.colorbox-iframe').colorbox({
		iframe: true,
		width: 640,
		height: 480
	});
	
	$('.colorbox-inline').colorbox({
		inline: true,
		width: 672,
		height: 532
	});
	
	$('.galleria-gallery').galleria({
		width: 640,
		height: 480
	});
	
	$('#collab-sidebar-scroller').jScrollPane({
		showArrows: true
	});
	
	$('.buy-album').hover(
		function() {
			$(this).find('.buy-album-dd').show();	
		},
		function() {
			$(this).find('.buy-album-dd').hide();
		}	
	);
	
	$('.navigation ul li ul').each(function() {
		$(this).find('li:last').addClass('last');
	});
	
	$('#header .navigation ul li').hover(
		function() {
			$(this).find('ul').show();
		},
		function() {
			$(this).find('ul').hide();
		}
	);
	
	$('.colorbox-iframe').each(function() {
		$(this).append('<span></span>');
	});
	
	$('.music').each(function() {
		if (!$(this).children().length) {
			$(this).remove();
		}
	});
	
	function fix_background_position() {
		var width = $(window).width();
		if (width <= 1024) {
			$('body').css('background-position', '-210px 0');
		} else {
			$('body').css('background-position', 'center 0');
		}
	}
	
	fix_background_position();
	$(window).resize(function() {
		fix_background_position();
	});
});
