$(init);

function init () {
	
	var scroller = new SmoothScroll();
	
	var photo_frame = new PhotoFrame('#main .body .text');
}


/* SmoothScroll */
function SmoothScroll () {
	//console.log("SmoothScroll(" + [] + ")");
	
	$('a[href^=#], area[href^=#]').click(this.scroll);
	$(document).mousewheel(this.onMouseWheel);
}

SmoothScroll.prototype.scroll = function () {
	//console.log("SmoothScroll.scroll(" + [] + ")");
	
	if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
		var $target = $(this.hash);
		$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
		if ($target.length) {
			var position = $target.offset().top;
			//position = Math.min(position, $(document).clientHeight - $('#container').outerHeight());
			$('html, body').stop().animate({scrollTop:position}, 800, "easeOutQuart");
			return false;
		}
	}
}

SmoothScroll.prototype.onMouseWheel = function () {
	//console.log("SmoothScroll.onMouseWheel(" + [] + ")");
	
	$('html, body').stop();
}


/* PhotoFrame */
function PhotoFrame (target) {
	//console.log("PhotoFrame(" + [target] + ")");
	
	$('img:not(.image img)', $(target)).wrap('<div style="text-align:center;"><div class="image" style="margin-left:auto; margin-right:auto;"></div></div>');
}


/* delegate */
function delegate (this_object, method) {
	//console.log("delegate" + [this_object, method] + ")");
	
	return function () { return method.apply(this_object, arguments); }
}

function delegateWithArgs (this_object, method, args, join_args) {
	//console.log("delegateWithArgs(" + [this_object, method, args, join_args] + ")");
	
	return function () {
		if (join_args) {
			var joined_args = new Array();
			var i;
			var length = arguments.length;
			for (i = 0; i < length; i++) {
				joined_args.push(arguments[i]);
			}
			joined_args = joined_args.concat(args);
			return method.apply(this_object, joined_args);
		}
		else {
			return method.apply(this_object, args);
		}
	}
}


