$(function () {

	$('a[rel*=external]').click(function () {
		window.open(this.href);
		return false;
	});

	/* ----- Cufon ----- */
	Cufon.replace(['h1', 'h2', 'h4', '.quote', '.cufon-quote', '.sorry', '.bq-big'], { hover: true, fontFamily: 'Clarendon BT Bold' });
	Cufon.now();

	$(".btn-launch").attr("target", "_blank");

	/* ----- Variables ----- */

	var easing = "easeOutExpo";
	var speed = 200;

	$(".disabled").css({ opacity: 0.3 });

	/* ----- Mobile ----- */

	var winWidth = $(window).width();
	var wid = 481;

	if ($(window).width() < wid) {
		$('body').attr('id', 'mobile');
	} else {
		$('body').removeAttr('mobile');
	}

	/* ----- Lightbox ----- */

	Shadowbox.init({
		handleOversize: "drag",
		modal: true,
		overlayColor: "#000",
		overlayOpacity: 0.8
	});

	/* ----- Hovers ----- */

	if ($(window).width() > 481) {

		$('.share').hover(function () {
			$(this).toggleClass("link-hover");
			$(this).children("#reveal").slideToggle(speed, easing);
			return false;
		});

		$(".cycle-wrap a, .solid, .grid-box, .feature-image a, .grid-image a").hover(function () {
			$(this).children(".image-hover").not(':animated').fadeIn(250);
		}, function () {
			$(this).children(".image-hover").fadeOut(250);
		});

		$("#btt").css({ opacity: 0.3 });

		$("#btt").hover(function () {
			$(this).stop().animate({ opacity: 1.0 }, 250);
		}, function () {
			$(this).stop().animate({ opacity: 0.3 }, 250);
		});

		$('#clients a img').fadeTo('fast', 0.5);

		$('#clients a img').hover(function () {
			$(this).fadeTo('slow', 1);
		}, function () {
			$(this).fadeTo('slow', 0.5);
		});

	}

	/* ----- Scroll ----- */

	$("#btt").click(function () {
		$.scrollTo(0, 1000);
		return false;
	});

	$("#hlComments").click(function () {
		$.scrollTo($("#comments"), 2000);
		return false;
	});

	/* ----- Selectors ----- */

	$("#folio-list").each(function () { $(this).children("article:last").addClass("mb0"); });
	$(".work-image ul").each(function () { $(this).children("li:last").addClass("mb0"); });
	$("#neg").each(function () { $(this).children(".list-feature:last").addClass("mb0"); });
	//$(".box-info").each(function () { $(this).children("p:last").addClass("mb0"); });
	$('#body p + .btn-arrow').addClass("pusher");

	$("#boxes > li:last, #nav-social li:last, #logos li:last, #grid article:nth-child(3n), #folk li:nth-child(7n), .list-social li:last").addClass("mr0");
	$(".drop-inner-rpt > ul:nth-child(2n)").addClass("remove");
	$(".list-social-bot li:last, .aside-block-top p:last").addClass("mb0");
	$("#blog-list > li:last, #blog-comments li:last").addClass("bot");
	$("#nav-main li:last").addClass("main-last");

	//    $(".heading-sub").each(function () {
	//        if ($(this).children().size() < 1) {
	//            $(this).remove();
	//        }
	//    });

	/* ----- Folio Drop ----- */

	$("#nav-folio-list > li").hover(function () {
		if ($(this).children().size() > 1) {
			$(this).children(".drop").stop().slideToggle(0);
			$(this).toggleClass("open");
		}
	});

	/* ----- Footer Boxes ----- */

	var height = 0;
	$("#boxes > li .box-small").each(function () {
		if ($(this).height() > height) {
			height = $(this).height();
		}
	});

	$("#boxes > li .box-small").each(function () {
		$(this).height(height - 20);
	});

	/* ----- People ----- */

	var folkHeight = 0;
	$("#folk li").each(function () {
		if ($(this).height() > folkHeight) {
			folkHeight = $(this).height();
		}
	});

	$("#folk li").each(function () {
		$(this).height(folkHeight);
	});

	// Clear textareas on focus if they contain original helper text
	$('textarea').each(function () {
		$(this).data('orig', $(this).text());
		$(this).focus(function () {
			if ($(this).val() == $(this).data('orig')) { $(this).val(''); }
		});
		$(this).blur(function () {
			if ($(this).val() == '') { $(this).val($(this).data('orig')); }
		});
	});

});
