$(function(){
	//portfolio gallery
	if($('#fb').length) {
		$('#fb a').addClass('opacity').attr('rel', 'fancybox');
		$('#fb a').fancybox({
			'imageScale': true,
			'padding': 0,
			'zoomOpacity': true,
			'zoomSpeedIn': 300,
			'zoomSpeedOut': 300,
			'zoomSpeedChange': 300,
			'overlayShow': true,
			'overlayColor': "#000000",
			'overlayOpacity': 0.8,
			'enableEscapeButton': true,
			'showCloseButton': true,
			'hideOnOverlayClick': true,
			'hideOnContentClick': false
		});
	}
	//lazyload
	$("img").lazyload({ threshold : 100, effect : "fadeIn" });
	//opacity
	opacity($('a.opacity'));
	//pagetop
	$("#totop").hide();
	$(window).scroll(function () {
		if ($(this).scrollTop() > 100) {
			$('#totop').fadeIn();
			} else {
			$('#totop').fadeOut();
		}
	});
	$("#totop a").click(function(){
		$('html,body').animate({ scrollTop: 0 }, 'slow', 'swing');
		return false;
	});
	if($('#works-list').length) {
		$('ul#works-list li').hover(function(){
				$(this).find('img').animate({top:'150px'},{queue:false,duration:500});
			}, function(){
				$(this).find('img').animate({top:'0px'},{queue:false,duration:500});
			});
	}
	//external link
	externalLink();
});

$(window).load(function() {
	//portfolio-list
	if($('#portfolio-list').length) {
		$('#portfolio-list').masonry({
			singleMode: true
		});
	}
});

//opacity for link hover
function opacity(target) {
	$(target).hover(function(){
		$(this).fadeTo(150,0.7);
	},function(){
		$(this).fadeTo(150,1);
	});
}

/* external link action */
function externalLink() {
	$("a[href*='http://']:not([href*='undergarden.com'])").unbind('click');
	$("a[href*='http://']:not([href*='undergarden.com'])").click(function(){
		window.open(this.href);
		return false;
	});
}
