/*
	Attach toggle events for the Spry header menu
*/
$(document).ready( function() {
	
	/*
		Menu effects
	*/
	$('#menu_main li').each( function() {
		var thisID = $(this).attr('id');
		if ( thisID ) {
			if ( $('#' + thisID + ' ul.submenu').length ) {
				// Attach submenu + mouseover effects
				$('#' + thisID).hover(
					function() {
						$('#' + thisID + '_link').addClass('lit');
						$('#' + thisID + ' ul.submenu').css('display','block');
					},
					function() {
						$('#' + thisID + '_link').removeClass('lit');
						$('#' + thisID + ' ul.submenu').css('display','none');
					}
				);
				// Attach linked list click facilitator
				$('#' + thisID + ' ul.submenu a').each( function () {
					var targetDestination = $(this).attr('href');
					$(this).parent().bind(
						'click',
						function(eventObject) {
							window.location = targetDestination;
							return false;
						}
					);
					$(this).parent().hover(
						function() {
							$(this).addClass('lit');
						},
						function() {
							$(this).removeClass('lit')
						}
					);
				});
			}
			
		}
	});
	
	/*
		Hosting plan table effects
	*/
	if ( $('#hostingPlans').length ) {
		
		/*
			Attach hosting plan table links for cross-domain reporting
		*/
		$('#hostingPlans #planSignup a').each( function() {
			// var newHrefFunction = 'pageTracker._link("' + $(this).attr('href') + '");';
			$(this).click( function() {
				pageTracker._link( $(this).attr('href') );
				return false;
			} );
		});
		
		/*
			Attach hosting plan table selection criteria if applicable
		*/
		$('#hostingPlans td.pCell').each( function() {
			var thisID = $(this).attr('id');
			var planID = thisID.replace(/[a-zA-Z_]/g, '');
			if (
				( thisID ) &&
				( planID ) &&
				( $('td[id$="' + planID + '"]').length )
			) {
				$('td[id$="' + planID + '"]').hover(
					function() {
						$('td[id$="' + planID + '"]').addClass('selected');
					},
					function() {
						$('td[id$="' + planID + '"]').removeClass('selected');
					}
				);
			}
		});
	}
	
});