﻿$(document).ready(function() {

	var $shareThisButton = $('#shareThisMenu');
	var $shareThisMenu = $('ul.shareThisMenu_body', $shareThisButton);

	$('ul.shareThisMenu_body li:even').addClass('alt');
	$('img.shareThisMenu_head').click(function() {
		$shareThisMenu.slideToggle('fast');
	});

	// Treat the menu the same as the button
	$shareThisButton.add($shareThisMenu);
	// Set up a timeout handler on button and menu.  Upon leaving the button or one of the menus, hide it after a second.
	$shareThisButton.mouseleave(function() {
		$.doTimeout('shareThisMenuHide', 750, function() {
			$shareThisMenu.slideUp('fast');
		});
	});

	// Cancel the above timer if the mouse moves anywhere onto one of the menus.
	$shareThisButton.mousemove(function() {
		$.doTimeout('shareThisMenuHide');
	});

	$('.shareThisLink', $shareThisMenu).click(function() {

		var docUrl = encodeURIComponent(document.URL);

		var linkUrl = $(this).attr('href');
		var linkQuery = $(this).attr('data-submit_path');

		if (linkQuery) {
			linkUrl += $(this).attr('data-submit_path');
		}

		var docTitle = $('div.twoColTitle h1').value;

		var postLink = linkUrl.replace('[u]', docUrl).replace('[t]', docTitle);

		window.open(postLink);

		return false;
	});


	var $connectWithButton = $('#connectWithMenu');
	var $connectWithMenu = $('ul.connectWithMenu_body', $connectWithButton);

	$('ul.connectWithMenu_body li:even').addClass('alt');
	$('#connectWithButton').click(function() {
		$connectWithMenu.slideToggle('fast');
	});

	$connectWithButton.add($connectWithMenu);
	// Set up a timeout handler.  Upon leaving one of the menus, hide it after a second.
	$connectWithButton.mouseleave(function() {
		$.doTimeout('connectWithMenuHide', 750, function() {
			$connectWithMenu.slideUp('fast');
		});
	});

	// Cancel the above timer if the mouse moves anywhere onto one of the menus.
	$connectWithButton.mousemove(function() {
		$.doTimeout('connectWithMenuHide');
	});

	$('.connectWithLink', $connectWithMenu).click(function() {

		var docUrl = encodeURIComponent(document.URL);

		var linkUrl = $(this).attr('href');

		window.open(linkUrl, 'child', 'height=500,width=650,scrollbars=yes,resizable=yes');

		return false;
	});

});