// This functionality is common across most/all SmartyPig pages.
// It relies heavily on jQuery, so be sure to load the jQuery library before calling this file. 

$(function() {
	// Adds border-radius testing to the $.support object. False if border-radius doesn't work in the user's browser. 
	$.support.borderRadius = false;
	$.each(['borderRadius','BorderRadius','MozBorderRadius','WebkitBorderRadius','OBorderRadius','KhtmlBorderRadius'], function() {
		if(document.body.style[this] !== undefined) $.support.borderRadius = true;
		return (!$.support.borderRadius);
	});
	
	// Add a 'hover' class to buttons on mouseover/removes on mouseout. Identical to :hover, but works on non-anchors in IE.
	$('.button').mouseover(function() { $(this).addClass('hover'); }).mouseout(function() { $(this).removeClass('hover'); });
	
	// Creates faux rounded corners on our buttons if border-radius isn't supported (older Operas, IE8 and older). 
	if(!$.support.borderRadius) {
		$('.button').each(function() {
			// Wrap, prepend, and append divs that'll serve as our corners.
			$(this).wrap('<div class="buttonwrap"></div>');
			$(this).parent()
			.prepend('<div class="tl corner"></div><div class="tr corner"></div>')
			.append('<div class="bl corner"></div><div class="br corner"></div>');
		});
	}	   
		   
	// Add arrows to the sidebar items that contain submenus. 
	$('.sidebarLeft li:has(ul)').each(function() {
		$(this).children('a').append('<div class="arrow"></div>');
	});
	
	// Animate the 'sign out' button. 
	$('.signout a:eq(0)').hoverIntent({timeout: 250, over: showMenu, out: hideMenu});
	function showMenu() { $(this).children('div').slideDown(); }
	function hideMenu() { $(this).children('div').slideUp(); }
	
	// Global Switcher stuff.
	countryClass = $('.globalSwitch h3').attr('class');
	$('.globalSwitch ul li a.'+countryClass).remove();
	$('.globalSwitch h3 a').click(function() {
		$(this).parents('.globalSwitch').toggleClass('open');
		$('.globalSwitch ul').slideToggle();
		return false;
	});
	
});

