var curvyCornersVerbose = false;

$(document).ready(function()
{
	// Right sidbar on modules.
	var moduleHeightTotal = 0;
	$('#sidebar .module').each(function()
	{
		moduleHeightTotal += $(this).outerHeight();
		if( $('.text', this).outerHeight() > 54 )
		{
			$('.right', this).css({
				display: 'block',
				height: ($('.text', this).outerHeight() - 27 - 27) + 'px'
			});
		}
	});

	// Top Navigation rollover.
	$('#topnav_careers').hover(function()
	{
		// 60 = padding, ie = 65
		var padding = 60;
		if( $.browser.msie && $.browser.version.substr(0,2)=="6." )
		{
			var padding = 65;
		}
		$('#hover_careers').width($(this).position().left + $(this).width() - padding).show();
		$('a', $(this)).addClass('selected');
		var settings = {
			      tl: { radius: 27 },
			      bl: { radius: 27 },
			      br: { radius: 27 },
			      antiAlias: true
			    }
		curvyCorners(settings, '#hover_careers');
		$(this).addClass('topnav_careers_dark');
	}, function()
	{
		$('#hover_careers').hide();
		$('a', $(this)).removeClass('selected');
		$(this).removeClass('topnav_careers_dark');
	});

	// Sub navigation rollovers.
	$('#subnav li a[rel]').each(function()
	{
		var a = $(this);
		a.parent().hover(function()
		{
			a.addClass('selected');
			if( a.hasClass('first') )
			{
				$('#subnav div.left').addClass('darkleft');
			}
			if( a.hasClass('last') )
			{
				$('#subnav div.right').addClass('darkright');
			}

			$(this).addClass('dark');
			$('#' + a.attr('rel')).css('margin-left',  ($('#content').offset().left - a.offset().left) + 'px').show();
			var settings = {
				      tl: { radius: 27 },
				      tr: { radius: 27 },
				      bl: { radius: 27 },
				      br: { radius: 27 },
				      antiAlias: true
				    }
			curvyCorners(settings, '#' + a.attr('rel'));

		}, function()
		{
			a.removeClass('selected');
			if( a.hasClass('first') )
			{
				$('#subnav div.left').removeClass('darkleft');
			}
			if( a.hasClass('last') )
			{
				$('#subnav div.right').removeClass('darkright');
			}

			$(this).removeClass('dark');
			$('#' + a.attr('rel')).hide();
		});
	});

	// Contact us corners.
	var settings = {
		tl: { radius: 27 },
		tr: { radius: 27 },
		antiAlias: true
	}
	curvyCorners(settings, '#contact_us_corners');

	// Job page sub nav, if the content in the first box is too large then we change its height to accomodate the sidebar.
	if( $('#jobcats').length > 0 )
	{
		var jobs = $('#content div.job');
		if( jobs.length > 0 )
		{
			var job = $(jobs[0]);
			if( job.height() < $('#jobcats').outerHeight() )
			{
				job.height($('#jobcats').outerHeight());
			}
		}
	}

	// Corners on images in posts

	var count = 0;
	$('#content .post .text img, #content .page p img').each(function()
	{
		$(this).replaceWith('<div id="post_image_' + count + '" class="alignleft" style="width: ' + $(this).width() + 'px; height: ' + $(this).height() + 'px; background-image: url(' + $(this).attr('src') + ');"></div>');
		var settings = {
				tl: { radius: 27 },
				antiAlias: true
			};
		curvyCorners(settings, '#post_image_' + count);
		count++;
	});
	
    // Add this functionality
    $('.addthis_toolbox img.button').mouseenter(function()
    {
    	var button = $(this);
    	var hover = $('.hover_menu', button.parent());
    	
    	hover.fadeIn('fast');
    	button.data('in', true);
    	
    	hover.mouseenter(function()
		{
    		hover.data('in', true);
		});
    	hover.mouseleave(function()
		{
    		hover.data('in', false);
    		
    		setTimeout(function()
			{
    			if( button.data('in') != true )
    			{
    				hover.fadeOut('fast');
    			}
			});
		});
    }).mouseleave(function()
    {
    	var button = $(this); 
    	button.data('in', false);
    	var hover = $('.hover_menu', button.parent());
    	
        setTimeout(function()
		{
        	if( hover.data('in') != true )
    		{
        		hover.fadeOut('fast');
    		}
		}, 200);
    });    
});
