$(document).ready(function () {
	Cufon.replace('#statement h2, .page_titles h2, .section h1, #content h1, .case-study h2', {
		fontFamily: 'Stag Sans-Light'
	});
	Cufon.replace('.navigation li a, #breadcrumbs li a', {
		fontFamily: 'Stag Sans-Book',
		hover: true,
		hoverables: { a: true }
	});
	Cufon.replace('#items li a, .right .section h2, .column h2', {
		fontFamily: 'Stag Sans-Medium',
		hover: true,
		hoverables: { a: true }
	});
	
	$('.thumbs a').click(function (e) {
		e.preventDefault();
		$('.thumbs a').removeClass('active');
		$(this).addClass('active');
		
		$('#current_image img').hide().remove();
		$('#current_image').html("<img src='"+ $(this).attr('href') +"' alt='' style='display:none' />");
		$('#current_image img').show();
	});
	
	$('#items li a').click(function (e) {
		e.preventDefault();
		$('#items li a').removeClass('active');
		$(this).addClass('active');
		Cufon.refresh();
		
		$('#tab_content .box:visible').hide();
		var item = $(this).attr('href').substr(1);
		$('#'+ item).show();
	});
	
	var protectedPdfUrl;
	$('.protected a').click(function(e) {
		var parentDiv = $(this).parent();
		protectedPdfUrl = $(this).attr('href');

		
		$.ajax({
			url: protectedPdfUrl,
			method: 'get',
			beforeSend: function() {
				parentDiv.slideUp();
			},
			success: function(data) {
				parentDiv.html(data).removeClass('pdf').slideDown();
			}

		});
		
		return false;
	});
	
	// hack to hide careers nav item from display
	$('#header li:last').hide();
	
	$('.protected #send').live('click', function() {
		var form = $(this).parents('.protected').eq(0);
		
		form.find('p.errors').text('');
		
		var hasErrors = false;
		
		form.find('.element').removeClass('error');
		
		if(form.find('#name').val() == '') {
			form.find('p.errors').text('name is required.');
			form.find('#name').parent('.element').addClass('error');
			hasErrors = true;
		}
		
		if(form.find('#email').val() == '') {
			form.find('p.errors').text('email is required.');
			form.find('#email').parent('.element').addClass('error');
			hasErrors = true;
		}
		
		if(!hasErrors) {
			var interests = form.find('input[type=checkbox]:checked');
			var intVal = '';
			if(interests) {
				interests.each(function(index) {
					intVal += $(this).val() + ',';
				});	
			}
			var postData = 'name=' + form.find('#name').val() + '&email=' + form.find('#email').val() + '&receive_offers=' + intVal + '&send=send';
			
			$.ajax({
				type: 'post',
				url: protectedPdfUrl,
				data: postData,
				success: function(data) {
					form.slideUp().html('<p>Thank you, your download should begin shortly. If it doesn\'t, click <a href="'+data+'">here</a> to manually start it.</p>').slideDown();
					
					window.location = data;
				}
			});
		}
		
		return false;
	});
});

Shadowbox.init({
	players : ['flv'],
	height  : 360,
    width   : 640
});