$(document).ready(function() {

    jQuery.easing.def = "easeOutQuad";

	$('#shortcuts li.normal a').click(function() {
        $('#page-text').toggleClass('normal').removeClass('medium large');
        $('#team-text').toggleClass('normal').removeClass('medium large');
	});
	$('#shortcuts li.medium a').click(function() {
        $('#page-text').toggleClass('medium').removeClass('normal large');
        $('#team-text').toggleClass('medium').removeClass('normal large');
	});
	$('#shortcuts li.large a').click(function() {
        $('#page-text').toggleClass('large').removeClass('normal medium');
        $('#team-text').toggleClass('large').removeClass('normal medium');
	});
	// $('#shortcuts li.print a').click(function() {
	// 	window.print(); return false; 
	// });

    $('#shortcuts li.email a').click(function() {
        return addthis_sendto('email');
    });

    $('#shortcuts li.print a').click(function() {
        return addthis_sendto('print');
    });

    addthis.button($('#shortcuts li.share a')[0], {});

    $('#newsletter-box').each(function() {
        var newsletter_box = $(this);
        $('input:submit', newsletter_box).click(function() {
            var data = {};
            data['email'] = $('input#newsletter', newsletter_box).val();
            $.post('/family/contact/newsletter/', data, function(data) {
                var obj = JSON.parse(data);
                if (obj.success) {
                    $('.success', newsletter_box).text(obj.message);
                    $('.error', newsletter_box).text('');
                } else {
                    $('.success', newsletter_box).text('');
                    $('.error', newsletter_box).text(obj.message);
                }
            });
        });
    });

	$('body.family #splash-nav > li').hoverIntent(
		function () {
			$('div.splash-nav-drop', this).slideDown('fast');
		},
		function () {
			$('div.splash-nav-drop', this).slideUp('fast');
			$('#nav-container').animate({width: 273});
		}
	);
	
	$('body.business #splash-nav > li').hoverIntent(
		function () {
			$('div.splash-nav-drop', this).slideDown('fast');
			$('#nav-container').animate({width: 500});
		},
		function () {
			$('div.splash-nav-drop', this).slideUp('fast');
			$('#nav-container').animate({width: 273});
		}
	);
	
	$('body.financial #splash-nav > li').hoverIntent(
		function () {
			$('div.splash-nav-drop', this).slideDown('fast');
		},
		function () {
			$('div.splash-nav-drop', this).slideUp('fast');
			$('#nav-container').animate({width: 273});
		}
	);
	
	$('body.retirement #splash-nav > li').hoverIntent(
		function () {
			$('div.splash-nav-drop', this).slideDown('fast');
		},
		function () {
			$('div.splash-nav-drop', this).slideUp('fast');
			$('#nav-container').animate({width: 273});
		}
	);
	
	$('#related-content-tab').toggle(
		function () {
			$('#related-content-container').animate({right: '0'}, 200);
		},
		function () {
			$('#related-content-container').animate({right: '-388'}, 200);
		}
	);
	
	$('#related-content a.close').click(function() {
		$('#related-content-container').animate({right: '-388'}, 200);
	});
	
	$('ul.people li:nth-child(even)').addClass('even');
	
	// We need #main-content to be the same height as the sidebars
	// $('#content-container #left-sidebar, #content-container #main-content, #content-container #right-sidebar').equalHeightColumns();
	
	/* #sidebar-nav
	---------------------------------- */
	$('#sidebar-nav li.inactive > ul').hide();
	$('#sidebar-nav > li.active').addClass('keepopen');
	
	$('#sidebar-nav > li.inactive').click(function () {
		$('#sidebar-nav > li:not(.keepopen)').removeClass('active').addClass('inactive');
		$(this).removeClass('inactive').addClass('active');

        $('#sidebar-nav > li.inactive').children('ul').slideUp('fast');
        $('#sidebar-nav > li.active').children('ul').slideDown('fast');
	});
	
	$('#sidebar-nav li li.inactive').hoverIntent(function () {
        $(this).children('ul').slideDown('fast');
	},function () {
        $(this).children('ul').slideUp('fast');
	});
	
	/* #navigation
	---------------------------------- */
	$('#navigation li .dropdown').parent().prepend('<em class="toggle">Toggle</em>').addClass('hasDrop');
	$('#navigation li:nth-child(2n+1)').addClass('odd');
	
	$('#navigation li').hover(function(){
		// slide down the .dropdown and add necessary classes
		var dd = $(this).children('.dropdown');
		if(dd.length > 0){
			$(this).addClass('open');
			dd.slideDown(200);
		}
	}, function(){
		$(this).removeClass('open');
		$(this).children('.dropdown').slideUp(100);
	});
	
	/* #promo
	---------------------------------- */
	// Add Nivo slider to main images
	$('.nivo').nivoSlider({ pauseTime: 6000, controlNav: false, directionNav: false });
	// Add a class to parent if more than one .page exists so that they will float
	$('#promo .panel').each(function(){
		if($(this).children('.page').length > 1) {
			$(this).addClass('multi clear');
		}
	});

    // // Enable visibility
    $('#promo .panel_container').css({visibility: 'visible'});

	// Initially position the panel out to the right ------
	$('#promo ul li .panel_container').each(function(){
		var right = 705 + $(this).outerWidth();
		$(this).css({right: '-'+right+'px'});
	});
	// Sliding effect on active #promo navigation items ------
	$("#promo > ul > li > a").click(function(){
		// kill the active state and reset widths
		$('#promo > ul > li.active').each(function(){
			var cn = $(this).children('.panel_container');
			var right = 705 + cn.outerWidth();
			$(this).removeClass('active');
            cn.siblings('a').css({width: 181});
			if(cn.length > 0){
				cn.stop().animate({right: '-'+right+'px'});
			}
		});
		
		// active and animate the hovered anchor..
		$(this).parent().addClass('active');
		$(this).animate({width: 201});
		// slide the panel out from the right
		$(this).siblings('.panel_container').stop().animate({right: '-705px'});
	});
			
    /* .poll
    ------------------------------------ */
    // Add ajax click logic to all .poll forms
    $('form.poll').each(function() {
        poll = $(this);
        poll_slug = poll.attr('name');
        poll_url = poll.attr('action');

        poll.children(':submit').click(function() {
            choice_slug = $('input:radio:checked', poll).val();
            $('#home-poll').load(poll_url, {'poll-slug': poll_slug, 'choice-slug': choice_slug});
            return false;
        });
    });
});
$(document).ready(function() {
    /* .poll
    ------------------------------------ */
    // Add ajax click logic to all .poll forms
    $('form.poll').each(function() {
        poll = $(this);
        poll_slug = poll.attr('name');
        poll_url = poll.attr('action');

        $(':radio').change(function() {
            choice_slug = $('input:radio:checked', poll).val();
            $('#home-poll').load(poll_url, {'poll-slug': poll_slug, 'choice-slug': choice_slug});
            return false;
        });
    });

    $('#other-staffers').tabs('#featured-answer-wrapper > div');
	
	// An admittedly ugly fix, but I need to use :before for a workaround, and IE7- needs something there as well..
	$('#content-container').prepend('<span class="before"/>');
});

