var CB = (function () {

	var W = window,
		SHOWCASE = (window.location.hash == '#showcase'),
		SHOWCASETOP = 305;
	
	SHOWCASE && W.scrollTo(0, 0);
	
	function easeOutStrong(t, b, c, d) {
    	return -c * ((t = t / d - 1) * t * t * t - 1) + b;
	}
	
	function getFrames(start, end, step, unit, easing) {
		var frames = [],
			len = Math.floor(end / step),
			i = 0,
			j = 0,
			t;
		!unit && (unit = '');
		for (; i < len; i++) {
			t = Math.floor(easing(i, start, (end - start), len, 1, 1)) + unit;
			if (!j || (t != frames[j - 1])) {
				frames[j++] = t;
			}
			start += step;
		}
		frames[j] = end + unit;
		return frames;
	}
	
	function scrollToCase() {
		var frames = getFrames(0, SHOWCASETOP, 3, null, easeOutStrong),
			l = frames.length,
			i = 0;

		var t = W.setInterval(
			function () {
				if (i < l) {
					W.scrollTo(0, frames[i]);
					i++;
				} else {
					W.clearInterval(t);
				}
			}, 20
		);
	}
	
	function checkWidth() {
		var minWidth = 1090,
			root = document.documentElement,
			clientWidth = root && root.clientWidth,
			body = document.body,
			bodyClass = 'narrow';
		if (!clientWidth) {
			return false;
		}
		if (clientWidth < minWidth) {
			body.className = bodyClass;
		} else if (bodyClass === body.className) {
			body.className = '';
		}
		return true;
	};
	
	W.onload = function () {
		SHOWCASE && document.getElementById('project-inner') && scrollToCase();
	};
	
	return {
		checkWidth: checkWidth	
	}

})();