$(document).ready(function () {

    $("label").inFieldLabels();

	var index = 0, hash = window.location.hash;
	if (hash) {
		index = /\d+/.exec(hash)[0];
		index = (parseInt(index) || 1) - 1; // slides are zero-based
	}

	$('ul#slideshow').cycle({ 
		startingSlide: index,
		nowrap: 0,
		sync:0,
		fx: 'fade',
		speed: 200,
		height: 'auto',
		timeout: 0,
		cleartypeNoBg: true,
		after: onAfter,
		prev: 'a.prev',
		next: 'a.next'
	});

	$('a.texttoggle').click(function () { 
		$('#slideshow').toggle();
		$('#worknav').toggle();
		$('#textintro').toggle();
		$('p.textlink').toggle();
		$(this).toggleClass("active");
		return false;
    });

	$('a.signup').click(function () { 
		$('.subscribe').toggle();
		$(this).toggleClass("active");
		return false;
    });

	$('a.seevideo').click(function () { 
		$('#video iframe').toggle();
		$(this).toggleClass("active");
		return false;
    });

	function onAfter(curr,next,opts) {
		var caption = (opts.currSlide + 1) + ' / ' + opts.slideCount;
		$('#counter').html(caption);
		window.location.hash = opts.currSlide + 1;
	}	

	/* Fix bug in IE7 with a bit of Jquery, yay! */
	
	var zIndexNumber = 1000;
	$('div').each(function() {
		$(this).css('zIndex', zIndexNumber);
		zIndexNumber -= 10;
	});
	

});
