// open external links in new window
(function() {
	var localDomain = location.protocol+'//'+location.hostname;
	$('a[href^="http"]').not('[href^="'+localDomain+'"]').attr('target', '_blank');
})();

// add show-hide button to info panes in work section
(function() {
	var $toggle = $('<a href="#" class="toggle"></a>');
	$toggle.click(function() {
		$(this).parent().toggleClass('collapsed', 250);
		return false;
	});
	$('#work .info').append($toggle);
})();

// image scroller for work section
(function() {
	$('#work .scroller').scrollable({
		keyboard: true,
		speed: 500,
		onBeforeSeek: function(e, i) {
			// get the current slide
			current = this.getIndex();
			
			// find the info panes that are visible and hide them
			this.getItems().not(':eq('+current+')').find('.info').removeClass('collapsed').addClass('hidden');
		},
		onSeek: function(e, i) {
			// animate info pane for current slide
			this.getItems().eq(i).find('.info').removeClass('hidden', 250);
		}
	}).navigator({
		navi: '.scroller-nav'
	});
})();

// toggleval on form fields
(function() {
	$('[data-placeholder]', '#contact-column .fields').each(function() {
		if(!$(this).val()) {
			$(this).toggleVal({
				populateFrom: 'custom',
				text: $(this).data('placeholder')
			});
		}
	});
})();

// remove placeholder values on form submit if unchanged
(function() {
	$('#contact-column form').submit(function() {
		$(':toggleval', this).not(':changed').val('');
	});
})();
