$(
	function() {
		/* Sony fly-out menu */
		$('#site-navigation>li').hover(
			function() { $(this).addClass('on').find('.sub-navigation').show(); },
			function() { $(this).removeClass('on').find('.sub-navigation').hide().siblings('.dropShadow').remove(); }
		);
		$('.training-category').delegate('li', 'hover', function() { $(this).toggleClass('on'); });

		/* Tabs for Learn to Earn page */
		if (document.getElementById('learn-to-earn')) {
			$('.page-navigation, section').delegate('a', 'click',
				function(e) {
					var anchor = e.target.href.split(/#/);
					if (anchor.length > 1) {
						e.preventDefault();
						$('section').hide();
						$('#'+anchor[1]).show();
					}
				}
			);
		}

		/* Overlay for e-mailing certificate */
		if (document.getElementById('report-card')) {
			$('.email-certificate').click(function(e) {
				var email_modal = $('<div>').attr('id', 'email-modal').css('display', 'none').appendTo('body');
				var certification_id = e.target.href.match(/email\/\d+/)[0].split(/\//)[1];
				email_modal.load(e.target.href, function() {
					email_modal.find('form').submit(function(e) {
						email_modal.load('?company_site/index/Sony/certification/email/'+certification_id, $(this).serializeArray());
						e.preventDefault();
					});
				});
				email_modal.dialog({ width: 530, height: 420, modal: true });
				e.preventDefault();
			});
		}

	}
);

