/* 
 * Author: Austin Siewert
 */

$(document).ready(function(){
	
	// radical web typography
	$('#mantra').lettering('lines');
	
	// Animate progress bar on each step
	$('.progress').click(function (){
		var progressBar = $(this).attr("progress");
		$('#progress_bar .ui-progress').animate({width: progressBar}, 1300, 'swing');
	});
	
	// Dynamically add numbers to process steps
	$('#process li').each(function() {
	        var count = $(this).index();
	        var plusOne = count + 1;
	        $(this).children('h2').prepend('<span>'+plusOne+'</span>');
	});
	
	// Cycle Process section callbacks
	function onTipOut() {
		$("#timeline span:visible").fadeOut('slow');
		$('#timeline li.activeSlide').addClass('completed');	
	}
	
	function onTipIn() {
		$("#timeline li.activeSlide span").fadeIn('slow');
		// remove class from any previou 
		$('#timeline li.activeSlide').nextAll().removeClass('completed');
	}
	
	// Cycles Process section
	$('#process_slide').cycle({
		pager:  '#timeline',
		before: onTipOut,
		after: onTipIn,
		pagerAnchorBuilder: function(idx, slide) {return '#timeline li:eq(' + (idx) + ') a';}
	}).cycle('pause');
	
	// Add tooltip for each step
	$('#timeline li').each(function(){
		var content = $(this).text();
		$(this).append('<span>'+content+'</span>');
	});
	
	// Fade in first tooltip
	$("#timeline li.activeSlide span").fadeIn('slow');	
	
	// Process section next slide
	$('#process li').each(function() {
	    var slide = $(this).index();
	    var nxtSlide = slide + 1;
	    $(this).children('.btn_bar').click(function() {
			if (nxtSlide < 5) {
				$('#process_slide').cycle(nxtSlide);
			} else {
				$('#process_slide').cycle(0);
			}
				return false; 
		});
	});
	
	// Cycle Process individual samples - generate unique navs
	$('.phase_slide').each(function(i) {
		$(this).before('<div class="phase_nav slide'+i+'">').cycle({
			pager: '.slide' + i
		}).cycle('pause');
	});
	
	// Get current slide height
	function tallestImg(curr, next, opts, fwd) {
		var tallest = 0;
		$('#portfolio section').each(function(){
			var bigger = $(this).height();
			if (bigger > tallest) {
				tallest = bigger;
			}
		});
		$('#portfolio').animate({height: tallest});
	}
	
	// Cycle Work section 
	$('#portfolio').cycle({
		pager:  '#port_nav',
		after: tallestImg,
		pagerAnchorBuilder: function(idx, slide) {return '#port_nav li:eq(' + (idx) + ') a';}
	}).cycle('pause');
	
	// Cycle Work individual samples - generate unique navs
	$('.work_slide').each(function(i) {
		$(this).before('<div class="work_nav work'+i+'">').cycle({
			pager: '.work' + i,
			after: tallestImg
		}).cycle('pause');
	});
	
	// replace text with numbers for work nav
	// $('#port_nav li a').each(function(i) {
	// 	 var navCount = i + 1;
	// 	 $(this).html(navCount);
	// });

	// Get Entry Heading/Title Height
	$('.entry h1').each(function() {
		var titleHt = $(this).outerHeight();
		var addHt = titleHt + 6;
		// Set side bar top margins
		$('.push').css({'margin-top': addHt});
	});
	
	// Subscribe label fadeout in footer
	$('#chimp label').inFieldLabels();
	
	// Subscribe label opt in disclosure
	$('#chimp input[type="text"]').focus(function(){
		$('.moreinfo').fadeIn('slow');
	})
	
	$('#chimp input[type="text"]').focusout(function(){
		$('.moreinfo').fadeOut('slow');
	})
	
	// Animate Back to Top
	$('#back-to-top').click(function(){
		$('html, body').animate({scrollTop:0}, 'slow');
			return false;
	});
	
	// Open external links in new window
	$("a.external").attr('target','_blank');
	
}); //End document.ready
