window.addEvent('domready', function() {
	Application.initialize();
});

var Application = {
	initialize : function() {

		var browserWarningContainer = $$('.browser-warning-container');
		if (browserWarningContainer.length > 0) {
			var closeWarning = browserWarningContainer[0].removeClass(
					'display-none').getElement('.close');
			if (closeWarning) {
				closeWarning.addEvent('click', function(e) {
					e.stop();
					browserWarningContainer.destroy();

					// Ignore the response. We are just setting a session
						// attribute.
						new Request( {
							method : 'get',
							url : '/index.html'
						}).send('hbw=1');
					});
			}
		}

		// IE6 support
		if (IE6) {
			supersleight.limitTo( [ $('menu_bar_divider'),
					$('header_logo_container') ]);
			supersleight.run();
		}

		if ($('course_mapper_include'))
			new CourseMapper.CourseMapper( {});
		else if ($('course_query_results_include'))
			new Courses.Query( {});
		else if ($('course_detail_include'))
			new Courses.Detail( {});
		else if ($('hole_detail_include'))
			new Courses.HoleDetail( {});
		else if ($('my_account_login_include'))
			new MyAccount.Login( {});
		else if ($('profile_include'))
			new Profile.Profile( {});
		else if ($('contact_include'))
			new Support.Contact( {});
		else if ($('support_include'))
			new Support.Support( {});
		else if ($('home_include'))
			new Home.Home( {});
		else if ($('login_include'))
			new Login.Login( {});
		else if ($('sign_up_include'))
			new SignUp.SignUp( {});
		else if ($('forgot_password_include'))
			new Login.ForgotPassword( {});
	}
}

var Home = {}

var SignUp = {}

var Profile = {}

var Courses = {
	openDirectionsWindow : function(streetAddress, city, stateOrProvince) {
		var fromElement = $('reference_location_input');
		var from = fromElement ? fromElement.value : '';
		if (from == '') {
			fromElement = $('user_location_string');
			from = fromElement ? escape(fromElement.value) : '';
		}

		var to = escape(streetAddress + ", " + city + ", " + stateOrProvince);
		var url = 'http://maps.google.com?z=9&q=to:' + to;
		if (from != '')
			url += '+from:' + from;
		window.open(url, 'scoreout_directions');
	}
}

var CourseMapper = {}

var MyAccount = {}

var Support = {}

var Login = {}

Login.Login = new Class( {
	Implements : [ Options ],
	options : {},
	initialize : function(options) {
		$$('.forgot-password a').addEvent(
				'click',
				function(e) {
					e.stop();
					window.location.href = e.getTarget().get('href') + '?e='
							+ $('loginId').get('value');
				});

		if (IE6) {
			supersleight.limitTo( [ $('login_button') ]);
			supersleight.run();
		}
	}
});

Login.ForgotPassword = new Class( {
	Implements : [ Options ],
	options : {},
	initialize : function(options) {
		if (IE6) {
			supersleight.limitTo( [ $('send_password_button') ]);
			supersleight.run();
		}
	}
});

Home.Home = new Class(
		{
			Implements : [ Options ],
			options : {},
			initialize : function(options) {
				if (IE6) {
					supersleight.limitTo( [ $('android_phone'),
							$('iphone_store') ]);
					supersleight.run();
				}

				this.blackberryPhone = $('blackberry_phone');
				this.androidPhone = $('android_phone');
				this.iphonePhone = $('iphone_phone');
				this.phoneCarat = $('phone_nav_carat');
				this.blackberryOption = $('blackberry_option');
				this.androidOption = $('android_option');
				this.iphoneOption = $('iphone_option');

				var _this = this;
				if (this.blackberryOption)
					this.blackberryOption
							.addEvent(
									'click',
									function(e) {
										e.stop();
										if (_this.blackberryPhone
												.hasClass('display-none')) {
											$$('.phone-container div.phone')
													.addClass('display-none');
											_this.blackberryPhone
													.removeClass('display-none');
											$$(
													'.phone-nav-container .phone-nav-left-selected')
													.removeClass(
															'phone-nav-left-selected')
													.addClass('phone-nav-left');
											$$(
													'.phone-nav-container .phone-nav-right-selected')
													.removeClass(
															'phone-nav-right-selected')
													.addClass('phone-nav-right');
											$$(
													'.phone-nav-container .phone-nav-middle')
													.removeClass(
															'phone-nav-middle')
													.addClass(
															'phone-nav-middle-selected');
											_this.phoneCarat.inject(
													_this.blackberryOption,
													'bottom');

											if (_this.imageTransitionPeriodical)
												$clear(_this.imageTransitionPeriodical);

											_this.hookupBlackberryScreenShots();
										}
									});

				if (this.androidOption)
					this.androidOption
							.addEvent(
									'click',
									function(e) {
										e.stop();
										if (_this.androidPhone
												.hasClass('display-none')) {
											$$('.phone-container div.phone')
													.addClass('display-none');
											_this.androidPhone
													.removeClass('display-none');
											$$(
													'.phone-nav-container .phone-nav-middle-selected')
													.removeClass(
															'phone-nav-middle-selected')
													.addClass(
															'phone-nav-middle');
											$$(
													'.phone-nav-container .phone-nav-right-selected')
													.removeClass(
															'phone-nav-right-selected')
													.addClass('phone-nav-right');
											$$(
													'.phone-nav-container .phone-nav-left')
													.removeClass(
															'phone-nav-left')
													.addClass(
															'phone-nav-left-selected');
											_this.phoneCarat.inject(
													_this.androidOption,
													'bottom');

											if (_this.imageTransitionPeriodical)
												$clear(_this.imageTransitionPeriodical);

											// TODO: Hookup screenshots
										}
									});

				if (this.iphoneOption)
					this.iphoneOption
							.addEvent(
									'click',
									function(e) {
										e.stop();
										if (_this.iphonePhone
												.hasClass('display-none')) {
											$$('.phone-container div.phone')
													.addClass('display-none');
											_this.iphonePhone
													.removeClass('display-none');
											$$(
													'.phone-nav-container .phone-nav-middle-selected')
													.removeClass(
															'phone-nav-middle-selected')
													.addClass(
															'phone-nav-middle');
											$$(
													'.phone-nav-container .phone-nav-left-selected')
													.removeClass(
															'phone-nav-left-selected')
													.addClass('phone-nav-left');
											$$(
													'.phone-nav-container .phone-nav-right')
													.removeClass(
															'phone-nav-right')
													.addClass(
															'phone-nav-right-selected');
											_this.phoneCarat.inject(
													_this.iphoneOption,
													'bottom');

											if (_this.imageTransitionPeriodical)
												$clear(_this.imageTransitionPeriodical);

											// TODO: Hookup screenshots
										}
									});

				// if (IE6)
				this.hookupBlackberryScreenShots();
				// this.hookupAndroidScreenShots();
			},
			hookupBlackberryScreenShots : function() {
				var screenShots = [
						REQUEST_CONTEXT + '/images/bb-screenshots/Harding-18-Tee.png',
						REQUEST_CONTEXT + '/images/bb-screenshots/Harding-18-Tee-YA.png',
						REQUEST_CONTEXT + '/images/bb-screenshots/Harding-18-Fairway.png',
						REQUEST_CONTEXT + '/images/bb-screenshots/Harding-18-Approach.png',
						REQUEST_CONTEXT + '/images/bb-screenshots/Harding-18-Approach-YA.png',
						REQUEST_CONTEXT + '/images/bb-screenshots/Harding-Scorecard.png' ];

				var _this = this;
				this.screenShotElements = new Array();
				screenShots.each(function(screenShot, index) {
					this.screenShotElements[index] = new Element('div', {
						'class' : index == 0 ? 'screenshot-container'
								: 'display-none screenshot-container'
					}).inject(_this.blackberryPhone
							.getElement('.screenshot-container-outer'));
					new Element('img', {
						src : screenShots[index]
					}).inject(this.screenShotElements[index]);
				}, this);

				this.activeImageIndex = 0;

				this.imageTransitionPeriodical = this.transitionImages
						.periodical(4000, this);

			},
			hookupAndroidScreenShots : function() {
				// TODO:
			},
			transitionImages : function() {
				var newIndex = this.activeImageIndex + 1;
				if (newIndex >= this.screenShotElements.length)
					newIndex = 0;

				this.transitionImage(
						this.screenShotElements[this.activeImageIndex],
						this.screenShotElements[newIndex])
				this.activeImageIndex = newIndex;
			},
			transitionImage : function(oldImage, newImage) {
				var fadeOut = function() {
					oldImage.setStyle('opacity', 1);
					var tween = new Fx.Tween(oldImage, {
						duration : 700
					}).start('opacity', 1, 0);
					fadeIn();
				};

				var fadeIn = function() {
					newImage.setStyle('opacity', 0);
					newImage.removeClass('display-none');
					new Fx.Tween(newImage, {
						duration : 700
					}).start('opacity', 0, 1);
				};

				fadeOut();
			}
		});

/*
 * Client class for the course pages including query, detail and hole detail
 */
Courses.Query = new Class(
		{
			Implements : [ Options ],
			options : {},
			initialize : function(options) {

				this.courseNameHiddenInput = $('course_name_input_hidden').set(
						'autocomplete', 'off');
				this.courseNameInput = $('course_name_input').set('value',
						$('course_name_input_default_text').get('value'));

				if (Browser.Platform.win && Browser.Engine.gecko)
					this.courseNameInput.setStyle('padding-top', '5px');

				this.form = $('course_query_results_form');
				this.loading = $('adjust_course_loading');
				this.radiusSelect = $('radius_options');
				this.referenceLocationInput = $('reference_location_input');
				this.doGUnload();
				this.waitingToFilter = false;
				this.filtering = false;
				this.hookupFormFields();

				if (IE6) {
					supersleight.limitTo( [ $('search_icon'), $('query_carat'),
							$('legend'), $('course_list_container') ]);
					supersleight.run();
				}

				this.hookupRows();

				// The google map is rendered by the page since it needs to pull
				// a lot
				// of information from the backing bean.
				this.constructGoogleMap();
			},
			hookupRows : function() {
				var _this = this;
				$$('.course-map-button')
						.addEvent(
								'click',
								function(e) {
									e.stop();
									if (_this.map) {
										var parent = e.getTarget().getParent(
												'li');
										_this.map.setCenter(new GLatLng(parent
												.getElement('.course-latitude')
												.get('value'),
												parent.getElement(
														'.course-longitude')
														.get('value')), 13);
									}
								});
			},
			/**
			 * Surround with try catch for IE issue See
			 * http://groups.google.com/group/Google-Maps-API/browse_thread/thread/d6a4d6069607b37e/
			 */
			doGUnload : function() {
				try {
					GUnload();
				} catch (e) {
				}
			},
			/**
			 * Clear the timer that submits the form
			 */
			clearSearchTimer : function() {
				if (this.timer) {
					$clear(this.timer);
					this.timer = null;
				}
			},
			constructGoogleMap : function() {
				var mapDiv = $('googlemap');
				if ((mapDiv) && (GBrowserIsCompatible())) {
					this.map = new GMap2(mapDiv);

					var container = $('map_points');
					this.map.addControl(new GLargeMapControl());
					this.map.addControl(new GMapTypeControl());
					var bounds = new GLatLngBounds;
					var centerLat = container.getElement('#map_center_lat')
							.get('value').toFloat();
					var centerLong = container.getElement('#map_center_long')
							.get('value').toFloat();
					var radiusElement = container.getElement('#map_radius');

					if (radiusElement) {
						var radius = radiusElement.get('value').toFloat();
						bounds.extend(new GLatLng(centerLat - radius,
								centerLong - radius));
						bounds.extend(new GLatLng(centerLat + radius,
								centerLong + radius));
						this.map.setCenter(new GLatLng(centerLat, centerLong),
								this.map.getBoundsZoomLevel(bounds));
					} else {
						this.map.setCenter(new GLatLng(centerLat, centerLong),
								container.getElement('#map_zoom').get('value')
										.toInt());
					}

					// Create markers for each course
					var courses = [];
					var icons = [];
					container
							.getElements('.map-course-id')
							.each(function(courseIdElement, index) {
								var courseId = courseIdElement.get('value');

								// Create the golf flag icon
									icons.push(new GIcon());
									icons[index].iconSize = new GSize(16, 16);
									icons[index].iconAnchor = new GPoint(0, 22);
									icons[index].infoWindowAnchor = new GPoint(
											3, 8);
									icons[index].image = container.getElement(
											'#course_' + courseId + '_icon')
											.get('value');

									var courseLat = container.getElement(
											'#course_' + courseId + '_lat')
											.get('value').toFloat();
									var courseLong = container.getElement(
											'#course_' + courseId + '_long')
											.get('value').toFloat();

									courses.push(new GMarker(new GPoint(
											courseLong, courseLat), {
										icon : icons[index]
									}));
									GEvent
											.addListener(
													courses[index],
													'click',
													function() {
														courses[index]
																.openInfoWindowHtml(container
																		.getElement(
																				'#course_' + courseId + '_bubble')
																		.get(
																				'html'));
													});
								});

					// Put all the courses in a marker manager
					var mgr = new MarkerManager(this.map);
					mgr.addMarkers(courses, 0);
					mgr.refresh();
				}
			},
			doSubmitAdjustCourseForm : function() {
				var _this = this;

				if (this.filtering) {
					this.waitingToFilter = true;
					return;
				}
				this.filtering = true;
				new Request( {
					url : this.form.get('action'),
					onSuccess : function(response) {
						_this.filtering = false;
						if (_this.waitingToFilter) {
							_this.doSubmitAdjustCourseForm();
							_this.waitingToFilter = false;
						}
						$('course_query_results_update').set('html', response);
						_this.hookupRows();
						_this.constructGoogleMap();
						_this.loading.addClass('display-none');

						if (IE6) {
							supersleight.limitTo( [ $('legend'),
									$('query_buttons'),
									$('course_list_container') ]);
							supersleight.run();
						}
					}
				}).send(this.form.toQueryString());
			},
			submitAdjustCourseForm : function() {
				if (!this.courseNameInput.hasClass('not-focused-search'))
					this.courseNameHiddenInput.set('value',
							this.courseNameInput.value);
				if (this.referenceLocationInput.get('value') == '')
					this.radiusSelect.set('value', '-1');
				this.loading.removeClass('display-none');
				this.doSubmitAdjustCourseForm();
			},
			onAddressFocus : function(addressInput) {
				if (addressInput.value != '') {
					if (this.radiusSelect.selectedIndex == this.radiusSelect.options.length - 1) {
						this.radiusSelect.options[this.radiusSelect.options.length - 1].selected = false;
						this.radiusSelect.options[0].selected = true;
					}
				}
			},
			hookupFormFields : function() {
				var _this = this;
				this.courseNameInput.addEvent(
						'focus',
						function(e) {
							if (_this.courseNameInput
									.hasClass('not-focused-search'))
								_this.courseNameInput.removeClass(
										'not-focused-search').set('value', '');
						}).addEvent(
						'keyup',
						function(e) {
							_this.loading.removeClass('display-none');
							_this.clearSearchTimer();

							// Throttle as you type search
							_this.timer = _this.submitAdjustCourseForm.delay(
									500, _this);
						});

				$$('#course_options input[type=checkbox]').addEvent(
						'click',
						function(e) {
							if (e.getTarget().get('value') == 'PUBLIC') {
								$('semi_private_checkbox').set('checked',
										e.getTarget().get('checked'));
								$('resort_checkbox').set('checked',
										e.getTarget().get('checked'));
								$('military_checkbox').set('checked',
										e.getTarget().get('checked'));
							}
							_this.submitAdjustCourseForm();
						});

				this.radiusSelect.addEvent('change', function(e) {
					if ($('reference_location_input').get('value').length > 0)
						_this.submitAdjustCourseForm();
				});

				this.referenceLocationInput.addEvent('keydown', function(e) {
					_this.onAddressFocus(e.getTarget());
				});

				$('find_course_button').addEvent('click', function(e) {
					e.stop();
					_this.submitAdjustCourseForm();
				});

				$$('input[type=text]').addEvent('keydown', function(e) {
					if (e.code == 13) {
						e.stop();
						_this.submitAdjustCourseForm();
					}
				});

				// Hookup reset button
				$('reset_search_button').addEvent('click', function(e) {
					e.stop();
					window.location.reload();
				});
			}
		});

/*
 * Client class for the course detail page
 */
Courses.Detail = new Class( {
	Implements : [ Options, Utils.HasCourseMapperButton ],
	options : {},
	initialize : function(options) {
		this.setOptions(options);
		this.mapCourseButton = $('map_course_button');
		this.hookupCourseMapperButton();

		if (IE6) {
			supersleight.limitTo( [ $('course_actions') ]);
			supersleight.run();
		}

		// Center the score card
	var scorecard = $('course_scorecard');
	if (scorecard)
		scorecard.setStyle('width',
				scorecard.getElement('table').getSize().x + 4).setStyle(
				'margin', '0 auto');

	$('course_directions').addEvent(
			'click',
			function(e) {
				e.stop();
				Courses.openDirectionsWindow($('course_address').get('value'),
						$('course_city').get('value'), $('course_state').get(
								'value'));
			});

	$$('td.tee-name div.tee-name-name').each(function(element) {
		var width = element.getSize().x;
		element.getParent('div').setStyle('width', width + 26);
	});
}
});

Courses.HoleDetail = new Class( {
	Implements : [ Options ],
	options : {},
	initialize : function(options) {
		this.setOptions(options);

		this.attempt = 0;

		// Center the hole image
	this.holeImage = $('hole_image');
	if (this.holeImage)
		this.centerHoleImagePeriodical = this.centerHoleImage.periodical(100,
				this);

	if (IE6) {
		supersleight.limitTo( [ $('hole_actions'), $('hole_navigation') ]);
		supersleight.run();
	}

	$$('td.tee-name div.tee-name-name').each(function(element) {
		var width = element.getSize().x;
		element.getParent('div').setStyle('width', width + 26);
	});
},
centerHoleImage : function() {
	// Make sure the image is loaded
	if (this.holeImage.getSize().x > 0) {
		this.holeImage.getParent('.course-thumbnail').setStyle('width',
				this.holeImage.getSize().x);
		$clear(this.centerHoleImagePeriodical);
	}

	this.attempt++;
	if (this.attempt > 10)
		$clear(this.centerHoleImagePeriodical);
}
});

/*
 * Client class for the course mapper page
 */
CourseMapper.CourseMapper = new Class( {
	Implements : [ Options, Utils.HasCourseMapperButton ],
	options : {},
	initialize : function(options) {
		this.setOptions(options);
		this.mapCourseButton = $('map_new_course');
		this.hookupCourseMapperButton();
	}
});

MyAccount.Login = new Class(
		{
			Implements : [ Options ],
			options : {},
			initialize : function(options) {
				this.setOptions(options);

				$('submit_button').addEvent('click', function(e) {
					e.stop();
					$('my_account_login_form').submit();
				});

				this.loadingContainer = $('state_or_province_loading_container');
				this.unselectedStateContainer = $('state_or_province_not_selected_container');
				this.selectStateContainer = $('state_or_province_select_container');

				this.populatesStatesForCountry();

				if (IE6) {
					supersleight.limitTo( [ $('login_title_img'),
							$('profile_title_img') ]);
					supersleight.run();
				}
			},
			populatesStatesForCountry : function(selectedCountry) {
				this.loadingContainer.removeClass('display-none');
				this.unselectedStateContainer.addClass('display-none');
				this.selectStateContainer.addClass('display-none');

				var select = document.forms['my_account_login_form']['country'];
				var country = '';
				if (!selectedCountry || typeof selectedCountry == 'undefined')
					country = select.selectedIndex && select.selectedIndex >= 0 ? select.options[select.selectedIndex].value
							: '';
				else
					country = selectedCountry;

				if (country == '' || country == 'US') {
					$('postal_code_label').addClass('display-none');
					$('zip_code_label').removeClass('display-none');
					$('province_label').addClass('display-none');
					$('state_label').removeClass('display-none');
				} else {
					$('postal_code_label').removeClass('display-none');
					$('zip_code_label').addClass('display-none');
					$('province_label').removeClass('display-none');
					$('state_label').addClass('display-none');
				}

				var _this = this;
				$('country')
						.addEvent(
								'change',
								function(e) {
									_this
											.populatesStatesForCountry(e
													.getTarget().selectedIndex
													&& e.getTarget().selectedIndex >= 0 ? e
													.getTarget().options[e
													.getTarget().selectedIndex].value
													: '');
								});

				new Request( {
					method : 'get',
					url : 'json/states',
					onSuccess : function(response) {
						_this.refreshStateList(response);
					}
				}).send('c=' + country);
			},
			refreshStateList : function(data) {
				var select = document.forms['my_account_login_form']['state_or_province'];
				select.options.length = 0;
				select.options[0] = new Option('', '');

				var selectedState = $('selected_state').value;
				var statesArray = eval('(' + data + ')');
				var index = 1;
				if (statesArray.length > 0) {
					for (x in statesArray) {
						for (state in statesArray[x]) {
							if (typeof statesArray[x][state] == 'string') {
								select.options[index] = new Option(
										statesArray[x][state], state);
								if (state == selectedState)
									select.options[index].selected = true;
								index++;
							}
						}
					}
				} else if (statesArray.length == 0
						&& ($('country').get('value') != '')) {
					// No states for the selected country so set index to 2 to
					// hide loading
					index = 2;
				}

				if (index <= 1) {
					this.loadingContainer.addClass('display-none');
					this.unselectedStateContainer.removeClass('display-none');
					this.selectStateContainer.addClass('display-none');
				} else {
					this.loadingContainer.addClass('display-none');
					this.unselectedStateContainer.addClass('display-none');
					this.selectStateContainer.removeClass('display-none');
				}
			}
		});

MyAccount.Profile = new Class( {
	Implements : [ Options ],
	options : {},
	initialize : function(options) {
		this.setOptions(options);
	}
});

Support.Contact = new Class( {
	Implements : [ Options ],
	options : {},
	initialize : function(options) {
		this.setOptions(options);

		var select = $('feedback_type_select');
		var requestCourseText = $('course_request_help_text');
		if (select.get('value') == 'REQUEST_COURSE')
			requestCourseText.removeClass('display-none');

		select.addEvent('change', function(e) {
			if (e.getTarget().get('value') == 'REQUEST_COURSE')
				requestCourseText.removeClass('display-none');
			else
				requestCourseText.addClass('display-none');
		});

		$('submit_button').addEvent('click', function(e) {
			e.stop();
			$('feedback_form').submit();
		});
	}
});

Support.Support = new Class( {
	Implements : [ Options ],
	options : {},
	initialize : function(options) {
		this.setOptions(options);

		$('forum_button').addEvent('click', function(e) {
			e.stop();
			window.open("http://getsatisfaction.com/score_out");
		});

		$('contact_button').addEvent('click', function(e) {
			e.stop();
			window.location.href = "/contact.html";
		});

		if (IE6) {
			supersleight.limitTo( [ $('faq_icon_container'),
					$('forum_icon_container'), $('contact_icon_container') ]);
			supersleight.run();
		}
	}
});

SignUp.SignUp = new Class( {
	Implements : [ Options ],
	options : {},
	initialize : function(options) {
		this.setOptions(options);

		$('submit_button').addEvent('click', function(e) {
			e.stop();
			$('sign_up_form').submit();
		});

		if (IE6) {
			supersleight.limitTo( [ $('login_title_image'),
					$('profile_title_image'), $('create_title_image') ]);
			supersleight.run();
		}
	}
});

Profile.Profile = new Class( {
	Implements : [ Options ],
	options : {},
	initialize : function(options) {
		this.setOptions(options);

		this.scoresBody = $('scores_body');
		this.loader = $$('#scores_bar .loader');

		var _this = this;
		$('relative_date').addEvent('change', function(e) {
			e.stop();
			_this.loader.removeClass('hidden');
			_this.getScores(e.getTarget().get('value'));
		});

		this.hookupRows();

		this.connectButton = $('connect_button');
		if (this.connectButton)
			this.connectButton.addEvent('click', function(e) {
				e.stop();
				_this.oobPopup = new Utils.Popup( {
					url : '/my-account-oob.html',
					afterLoad : function() {
						_this.hookupOOBPopup();
					},
					onClose : function() {
						window.location.reload(true);
					}
				}).show();
			});
	},
	hookupOOBPopup : function() {
		var _this = this;

		var saveButton = $('save_button');
		if (saveButton) {

			saveButton.addEvent('click', function(e) {
				e.stop();
				_this.submitOOBForm();
			});

			$$('.overlay-inner .form-input').addEvent('keydown', function(e) {
				if (e.code == 13) {
					e.stop();
					_this.submitOOBForm();
				}
			});
		}

		if (IE6) {
			supersleight.limitTo( [ $('save_button'), $('cancel_button') ]);
			supersleight.run();
		}
	},
	submitOOBForm : function() {
		$('oob_main').addClass('display-none');
		$('oob_loading').removeClass('display-none');

		var _this = this;
		var form = $('oob_form');
		new Request( {
			url : form.get('action'),
			onSuccess : function(response) {
				$$('.overlay-inner')[0].set('html', response);
				_this.hookupOOBPopup();
				_this.oobPopup.hookupCloseButton();
			}
		}).send(form.toQueryString());
	},
	getScores : function(relativeDate) {
		var _this = this;
		new Request( {
			method : 'get',
			url : 'profile-score-list-include.html',
			onSuccess : function(response) {
				_this.scoresBody.empty();
				var newRows = Utils.htmlToTableRows(response);
				newRows.each(function(row) {
					if (!row.getParent('.profile-scorecard'))
						row.inject(_this.scoresBody);
				});
				_this.hookupRows();
				_this.loader.addClass('hidden');
			}
		}).send('rd=' + relativeDate);
	},
	hookupRows : function() {
		$$('#scores_table tr').addEvent(
				'click',
				function(e) {
					var target = e.getTarget();
					if (target.get('tag') != 'a'
							&& !target.hasClass('no-scores-row')
							&& !target.getParent('.no-scores-row')) {
						if (!target.hasClass('collapsed-row')
								&& !target.hasClass('expanded-row')) {
							var newTarget = target.getParent('.expanded-row');
							if (!newTarget)
								target = target.getParent('.collapsed-row')
										.getNext();
							else
								target = newTarget;
						} else if (target.hasClass('collapsed-row'))
							target = target.getNext();
						target.toggleClass('display-none');
					}

				});

		$$('#scores_table tr.collapsed-row').addEvent('mouseover', function(e) {
			var target = e.getTarget();
			if (!target.hasClass('collapsed-row'))
				target = target.getParent('.collapsed-row');

			target.addClass('hovered');
		}).addEvent('mouseout', function(e) {
			var target = e.getTarget();
			if (!target.hasClass('collapsed-row'))
				target = target.getParent('.collapsed-row');

			target.removeClass('hovered');
		});
	}
});
