var UnitSofa = {	
	baseColorboxParams: {
		opacity: 0.7,
		speed: 0,
		onOpen:function() {
			$('#cboxWrapper, #cboxOverlay').hide();
		},
		onComplete:function() {
			$('#cboxOverlay').fadeIn(300);
			setTimeout(function(){$('#cboxWrapper').fadeIn(300)}, 150);
		}
	},
	videoColorboxParams: {
		scrolling: false,
		onClosed: function(){
			window.location.replace(window.location.href.substring(0, window.location.href.indexOf('#')));
		}
	},
	handleHash: function() {
		if (window.location.hash) {
			var slug = window.location.hash.replace('#', '');
			var params = jQuery.extend({}, UnitSofa.videoColorboxParams, UnitSofa.baseColorboxParams);
			params.href = basePath + '/detail/' + slug + '.html',
			$.colorbox(params);
		}
	}
};

$(function() {
	$('.works a').each(function() {
		$(this).click(function(event) {
			event.preventDefault();
			var slug = this.id.substring(6);			
			window.location.replace('#' + slug);
			var params = jQuery.extend({}, UnitSofa.videoColorboxParams, UnitSofa.baseColorboxParams);
			params.href = basePath + '/detail/' + slug + '.html',
			$.colorbox(params);
		})
	});
	$('.colorbox').colorbox(UnitSofa.baseColorboxParams);
	
	var count = $('.scroll').hasClass('scroll2') ? 12 : 18;
	if ($('.scroll li').size() <= count) {
		$('#scroll-more').hide();
	}
	
	$('.scroll').serialScroll({
		items:'li',
		prev:'#scroll-back',
		next:'#scroll-more',
		step:5,
		axis:'y',
		duration:500,
		cycle:false,
		easing:'easeOutQuart',
		onBefore: function(event, el_target, el_scrolled, items, position) {
			var count = el_scrolled.hasClass('scroll2') ? 12 : 18;
			if (position + count >= items.length) {
				$('#scroll-more').hide();
			} else {
				$('#scroll-more').show();
			}
			if (position > 0) {
				$('#scroll-back').show();
			} else {
				$('#scroll-back').hide();
			}
		}
	})
	
});
