/**
 *
 */
package com.tootsville.tootsbook.client.pages;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.FocusPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.tootsville.tootsbook.client.BookServiceAsync;
import com.tootsville.tootsbook.client.TootsBook;
import com.tootsville.tootsbook.client.exception.NotFoundException;
import com.tootsville.tootsbook.client.panel.AvatarBox;
import com.tootsville.tootsbook.client.panel.Box;
import com.tootsville.tootsbook.client.panel.ErrorMessage;
import com.tootsville.tootsbook.client.util.Advertisement;
import com.tootsville.tootsbook.client.util.AvailableItems;
import com.tootsville.tootsbook.client.util.DisplayText;
import com.tootsville.tootsbook.client.util.ShadowUser;
import com.tootsville.tootsbook.client.util.ThemeItem;
import com.tootsville.tootsbook.client.util.UserProfile;
import com.tootsville.tootsbook.client.util.ThemeItem.ThemeItemType;

/**
 * WRITEME: Document this type. twheys@gmail.com Jan 19, 2010
 * 
 * @author <a href="mailto:twheys@gmail.com">Tim Heys</a>
 */
public final class SettingsPage extends HorizontalPanel {
	/**
	 * WRITEME: Document this type. twheys@gmail.com Dec 17, 2009
	 * 
	 * @author <a href="mailto:twheys@gmail.com">Tim Heys</a>
	 */
	private class OptionLabel extends Label {
		/**
		 *
		 */
		private ThemeItem item;
		/**
		 *
		 */
		private final ThemeItemType type;
		
		/**
		 * <pre>
		 * twheys@gmail.com Dec 17, 2009
		 * </pre>
		 * 
		 * A OptionLabel WRITEME...
		 * 
		 * @param themeType WRITEME twheys@gmail.com
		 */
		OptionLabel (final ThemeItemType themeType) {
			super ("");
			type = themeType;
			item = getActiveItem ();
			update ();
		}

		/**
		 * <pre>
		 * twheys@gmail.com Feb 5, 2010
		 * </pre>
		 * 
		 * TO getActiveItems WRITEME...
		 * 
		 * @return WRITEME twheys@gmail.com
		 */
		private ThemeItem getActiveItem () {
			switch (type) {
				case avatarBG:
					return getItems().getActiveAvatarBackground ();
				case boxStyle:
					return getItems().getActiveBoxStyle ();
				case icon:
					return getItems().getActiveIcon ();
				case pageBG:
					return getItems().getActivePageBackground ();
				case titleBG:
					return getItems().getActiveTitleBackground ();
			}
			return null;
		}

		/**
		 * <pre>
		 * twheys@gmail.com Dec 18, 2009
		 * </pre>
		 * 
		 * TO loadPreviewStyleSheet WRITEME...
		 */
		private void loadPreviewStyleSheet () {
			final UserProfile user = TootsBook.getUser ();
			switch (type) {
				case avatarBG:
					changeAvatarBG (String.valueOf (item.getId ()));
					break;
				case boxStyle:
					TootsBook.loadBoxStylesStyleSheet (ShadowUser
							.getBoxStyleURLForItemID (String
									.valueOf (item.getId ())));
					break;
				case icon:
					changeIcon (ShadowUser.getIconForUserWithItemID (user,
							String.valueOf (item.getId ())));
					break;
				case pageBG:
					TootsBook.loadPageBGStyleSheet (ShadowUser
							.getPageStyleURLForItemID (String
									.valueOf (item.getId ())));
					break;
				case titleBG:
					TootsBook.loadTitleBGStyleSheet (ShadowUser
							.getTitleStyleURLForItemID (String
									.valueOf (item.getId ())));
					break;
			default:
                // AppiusClaudiusCaecus.reportBug ("default hit");
				break;
			}
		}

		/**
		 * <pre>
		 * twheys@gmail.com Dec 17, 2009
		 * </pre>
		 * 
		 * TO next WRITEME...
		 * 
		 * @param moveForward true: get the next item, false: get the
		 *            previous item.
		 * @return the next or previous item in the list.
		 */
		private ThemeItem nextItem (final boolean moveForward) {
			try {
				switch (type) {
					case avatarBG:
						return getItems()
								.getNextAvatarBackground (moveForward);
					case boxStyle:
						return getItems().getNextBoxStyle (moveForward);
					case icon:
						return getItems().getNextIcon (moveForward);
					case pageBG:
						return getItems()
								.getNextPageBackground (moveForward);
					case titleBG:
						return getItems()
								.getNextTitleBackground (moveForward);
				}
			} catch (final NotFoundException e) {
				TootsBook.showPopup (new ErrorMessage (
						DisplayText.NO_MORE_ITEMS));
			}
			return null;
		}

		/**
		 * <pre>
		 * twheys@gmail.com Dec 17, 2009
		 * </pre>
		 * 
		 * TO nextOption WRITEME...
		 */
		void nextOption () {
			item = nextItem (true);
			update ();
		}

		/**
		 * <pre>
		 * twheys@gmail.com Dec 17, 2009
		 * </pre>
		 * 
		 * TO previousOption WRITEME...
		 */
		void previousOption () {
			item = nextItem (false);
			update ();
		}

		/**
		 * <pre>
		 * twheys@gmail.com Dec 17, 2009
		 * </pre>
		 * 
		 * TO update WRITEME...
		 */
		private void update () {
			setText (item.getName ());
			setTitle (item.getDescription ());
			loadPreviewStyleSheet ();
		}
	}

	/**
	 * WRITEME
	 */
	private static final Label AVATAR_BACKGROUND_LABEL = new Label (
			DisplayText.AVATAR_BACKGROUND_TEXT);

	/**
	 * WRITEME
	 */
	private static final Label BOX_STYLE_LABEL = new Label (
			DisplayText.BOX_STYLE_TEXT);

	/**
	 * WRITEME
	 */
	private static final Label ICON_LABEL = new Label (
			DisplayText.ICON_TEXT);

	/**
	 * WRITEME
	 */
	private static final int LEFT1_ARROW = 0;

	/**
	 * WRITEME
	 */
	private static final Label PAGE_BACKGROUND_LABEL = new Label (
			DisplayText.PAGE_BACKGROUND_TEXT);

	/**
	 * WRITEME
	 */
	private static final int RIGHT_ARROW = 1;

	/**
	 * WRITEME
	 */
	private static final Label TITLE_BACKGROUND_LABEL = new Label (
			DisplayText.TITLE_BACKGROUND_TEXT);

	/**
	 * WRITEME
	 */
	static {
		SettingsPage.BOX_STYLE_LABEL
				.setStyleName ("primary-text settings-labels");
		SettingsPage.PAGE_BACKGROUND_LABEL
				.setStyleName ("primary-text settings-labels");
		SettingsPage.ICON_LABEL
				.setStyleName ("primary-text settings-labels");
		SettingsPage.AVATAR_BACKGROUND_LABEL
				.setStyleName ("primary-text settings-labels");
		SettingsPage.TITLE_BACKGROUND_LABEL
				.setStyleName ("primary-text settings-labels");
	}

	/**
	 * WRITEME
	 */
	private Box adBox;

	/**
	 * WRITEME
	 */
	OptionLabel avatarBGOptionLabel;

	/**
	 * WRITEME
	 */
	private Box avatarBox;

	/**
	 * WRITEME
	 */
	private final Image avatarPanelIE = new Image (TootsBook.getUser ()
			.getAvatarBgURL ());

	/**
	 * WRITEME
	 */
	private final OptionLabel boxStyleOptionLabel;

	/**
	 * WRITEME
	 */
	private Box iconBox;

	/**
	 * WRITEME
	 */
	private final OptionLabel iconOptionLabel;

	/**
	 * WRITEME
	 */
	private HorizontalPanel iconPanel;

	/**
	 * WRITEME
	 */
	private final AvailableItems items;

	/**
	 * WRITEME
	 */
	private Box optionsBox;

	/**
	 * WRITEME
	 */
	private VerticalPanel optionsPanel;

	/**
	 * WRITEME
	 */
	private final OptionLabel pageBGOptionLabel;

	/**
	 * WRITEME
	 */
	private Box storeAdBox;

	/**
	 * WRITEME
	 */
	private final OptionLabel titleBGOptionLabel;

	/**
	 * WRITEME
	 */
	private Box titleBox;

	/**
	 * WRITEME
	 */
	FocusPanel userIcon;

	/**
	 * <pre>
	 * twheys@gmail.com Dec 17, 2009
	 * </pre>
	 * 
	 * A Settings WRITEME...
	 * 
	 * @param availableItems WRITEME twheys@gmail.com
	 */
	public SettingsPage (final AvailableItems availableItems) {
		Window.setTitle ("Settings - TootsBook® www.Tootsville.com");
		items = availableItems;
		avatarBGOptionLabel = new OptionLabel (ThemeItemType.avatarBG);
		boxStyleOptionLabel = new OptionLabel (ThemeItemType.boxStyle);
		iconOptionLabel = new OptionLabel (ThemeItemType.icon);
		pageBGOptionLabel = new OptionLabel (ThemeItemType.pageBG);
		titleBGOptionLabel = new OptionLabel (ThemeItemType.titleBG);
		setHorizontalAlignment (HasHorizontalAlignment.ALIGN_CENTER);
		add (getLeftContent ());
		add (getCenterContent ());
		add (getRightContent ());
		loadDefaultStyleSheets ();
		resetAvatarBG ();
		resetIcon ();
		TootsBook.hideLoadingBar ();
	}

	/**
	 * <pre>
	 * twheys@gmail.com Dec 31, 2009
	 * </pre>
	 * 
	 * TO applyItems WRITEME...
	 * 
	 * @param service WRITEME twheys@gmail.com
	 * @param callback WRITEME twheys@gmail.com
	 */
	private void applyItems (final BookServiceAsync service,
			final AsyncCallback <Void> callback) {
		final int pageBGSlotNum = getItems()
				.getCurrentlySelectedPageBackground ().getSlot ();
		final int boxStylesSlotNum = getItems()
				.getCurrentlySelectedBoxStyle ().getSlot ();
		final int iconSlotNum = getItems().getCurrentlySelectedIcon ()
				.getSlot ();
		final int titleBGSlotNum = getItems()
				.getCurrentlySelectedTitleBackground ().getSlot ();
		final int avatarBGSlotNum = getItems()
				.getCurrentlySelectedAvatarBackground ().getSlot ();
		service.applyItems (pageBGSlotNum, boxStylesSlotNum,
				iconSlotNum, titleBGSlotNum, avatarBGSlotNum, callback);
	}

	/**
	 * <pre>
	 * twheys@gmail.com Jan 4, 2010
	 * </pre>
	 * 
	 * TO applyItemsToCurrentUser WRITEME...
	 */
	void applyItemsToCurrentUser () {
		final int avatarBGItemID = getItems()
				.getCurrentlySelectedAvatarBackground ().getId ();
		final int boxStylesItemID = getItems()
				.getCurrentlySelectedBoxStyle ().getId ();
		final int iconItemID = getItems().getCurrentlySelectedIcon ()
				.getId ();
		final int pageBGItemID = getItems()
				.getCurrentlySelectedPageBackground ().getId ();
		final int titleBGItemID = getItems()
				.getCurrentlySelectedTitleBackground ().getId ();
		final UserProfile user = TootsBook.getUser ();
		user.setAvatarResource (String.valueOf (avatarBGItemID));
		user.setBoxColorResource (String.valueOf (boxStylesItemID));
		user.setIcon (String.valueOf (iconItemID));
		user.setPageResource (String.valueOf (pageBGItemID));
		user.setTitleResource (String.valueOf (titleBGItemID));
	}

	/**
	 * <pre>
	 * twheys@gmail.com Dec 31, 2009
	 * </pre>
	 * 
	 * TO applySelectedThemeItems WRITEME...
	 */
	void applySelectedThemeItems () {
		final BookServiceAsync service = TootsBook.initService ();

		final AsyncCallback <Void> callback = new AsyncCallback <Void> () {

			@Override
			public void onFailure (final Throwable caught) {
				TootsBook.hideLoadingBar ();
				TootsBook.showError (caught);
			}

			@Override
			public void onSuccess (final Void result) {
				applyItemsToCurrentUser ();
				setAvatarBox (null);
				History.newItem ("home");
			}
		};
		applyItems (service, callback);
	}

	/**
	 * <pre>
	 * twheys@gmail.com Dec 31, 2009
	 * </pre>
	 * 
	 * TO buildAdPanel WRITEME...
	 */
	private void buildAdPanel () {
		final Advertisement adPanel = new Advertisement ();
		adBox = new Box (adPanel, "Advertisment", "<br />", "");
		adBox.pack ();
	}

	/**
	 * <pre>
	 * twheys@gmail.com Feb 1, 2010
	 * </pre>
	 * 
	 * TO buildAvatarForIE WRITEME...
	 */
	private void buildAvatarForIE () {
		avatarPanelIE.setSize ("200px", "215px");
		avatarPanelIE.setStyleName ("avatar-portrait");

		// put this panel in the UI container
		setAvatarBox (new Box (avatarPanelIE, "Player Card", "", ""));

		// build the container.
		getAvatarBox ().pack ();
	}

	/**
	 * <pre>
	 * twheys@gmail.com Dec 17, 2009
	 * </pre>
	 * 
	 * TO buildAvatarPanel WRITEME...
	 */
	private void buildAvatarPanel () {
		if (TootsBook.ifIE ()) {
			buildAvatarForIE ();
			return;
		}
		final AvatarBox avatarPanel = new AvatarBox (
				String.valueOf (TootsBook.getUser ().getUserID ()),
				TootsBook.getUser ().getAvatarBgURL ());
		avatarPanel.setStyleName ("avatar-portrait");

		// put this panel in the UI container
		setAvatarBox (new Box (avatarPanel, "Player Card", "", ""));

		// build the container.
		getAvatarBox ().pack ();
	}

	/**
	 * <pre>
	 * twheys@gmail.com Dec 17, 2009
	 * </pre>
	 * 
	 * TO buildIconBox WRITEME...
	 */
	private void buildIconBox () {
		iconPanel = new HorizontalPanel ();
		iconPanel.setStyleName ("buddy-icon-pane");

		// put this panel in the UI container
		iconBox = new Box (iconPanel, "Buddy Icon");
		iconPanel
				.setHorizontalAlignment (HasHorizontalAlignment.ALIGN_CENTER);
		iconPanel
				.setVerticalAlignment (HasVerticalAlignment.ALIGN_MIDDLE);
		userIcon = TootsBook.getUser ().getIcon ();
		iconPanel.add (new Label ("Preview: "));
		iconPanel.add (userIcon);

		// iconPanel.setBorderWidth (1);

		// build the container.
		iconBox.pack ();
	}

	/**
	 * <pre>
	 * twheys@gmail.com Dec 17, 2009
	 * </pre>
	 * 
	 * TO buildOptions WRITEME...
	 * 
	 * @return WRITEME twheys@gmail.com
	 */
	private VerticalPanel buildOptions () {
		final VerticalPanel options = new VerticalPanel ();
		options.setWidth ("100%");
		options.setHorizontalAlignment (HasHorizontalAlignment.ALIGN_CENTER);
		options.setVerticalAlignment (HasVerticalAlignment.ALIGN_MIDDLE);
		// options.setBorderWidth (1);
		options.add (SettingsPage.PAGE_BACKGROUND_LABEL);
		options.add (getNewOptionPanel (pageBGOptionLabel));
		options.add (SettingsPage.BOX_STYLE_LABEL);
		options.add (getNewOptionPanel (boxStyleOptionLabel));
		options.add (SettingsPage.ICON_LABEL);
		options.add (getNewOptionPanel (iconOptionLabel));
		options.add (SettingsPage.TITLE_BACKGROUND_LABEL);
		options.add (getNewOptionPanel (titleBGOptionLabel));
		options.add (SettingsPage.AVATAR_BACKGROUND_LABEL);
		options.add (getNewOptionPanel (avatarBGOptionLabel));
		options.add (getButtons ());
		return options;
	}

	/**
	 * <pre>
	 * twheys@gmail.com Dec 17, 2009
	 * </pre>
	 * 
	 * TO buildContentPanel WRITEME...
	 */
	private void buildOptionsPanel () {
		optionsPanel = buildOptions ();
		optionsPanel.setHeight ("500px");
		optionsBox = new Box (optionsPanel, "Settings for "
				+ TootsBook.getUser ().getUserName (), "<br />", "");
		// build the container.
		optionsBox.pack ();
	}

	/**
	 * <pre>
	 * twheys@gmail.com Feb 25, 2010
	 * </pre>
	 * 
	 * TO buildStoreAdPanel WRITEME...
	 */
	private void buildStoreAdPanel () {
		final Button storeAdButton = new Button ("",
				new ClickHandler () {
					@Override
					public void onClick (final ClickEvent event) {
						History.newItem ("store");
					}
				});
		storeAdButton.addStyleName ("store-ad-button");
		storeAdButton.getElement ().setId ("click-here");

		final AbsolutePanel storeAd = new AbsolutePanel ();
		storeAd.setStyleName ("store-ad-panel store-ad-background");
		storeAd.add (storeAdButton, 45, 130);

		storeAdBox = new Box (storeAd);
		storeAdBox.getElement ().setAttribute ("style",
				"overflow: hide;");
		// build the container.
		storeAdBox.pack ();
	}

	/**
	 * <pre>
	 * twheys@gmail.com Dec 17, 2009
	 * </pre>
	 * 
	 * TO buildTitlePanel WRITEME...
	 */
	private void buildTitlePanel () {
		final UserProfile user = TootsBook.getUser ();
		final HTML titlePanel = new HTML (
				"<div class=\"header-text-container\">"
						+ "<div class=\"header-box\">"
						+ "<span class=\"header-name\">"
						+ user.getUserName ()
						+ " </span><span class=\"header-text\">"
						+ user.getStatus () + "</span></div></div>");
		titlePanel.setStyleName ("title-panel");
		titleBox = new Box (titlePanel, "Name Tag");
		titleBox.useBackground ();
		titleBox.pack ();
	}

	/**
	 * @param itemID WRITEME twheys@gmail.com
	 */
	void changeAvatarBG (final String itemID) {
		if (TootsBook.ifIE ()) {
			avatarPanelIE
					.setUrl (ShadowUser.getAvatarBgURLForItemID (itemID));
		} else {
			AvatarBox.updateAvatarBackground (ShadowUser
					.getAvatarBgURLForItemID (itemID));
		}
	}

	/**
	 * <pre>
	 * twheys@gmail.com Dec 18, 2009
	 * </pre>
	 * 
	 * TO changeIcon WRITEME...
	 * 
	 * @param newIcon WRITEME twheys@gmail.com
	 */
	void changeIcon (final FocusPanel newIcon) {
		if (null != userIcon) {
			userIcon.removeFromParent ();
			userIcon = newIcon;
			iconPanel.add (userIcon);
		}
	}

	/**
	 * <pre>
	 * twheys@gmail.com Dec 17, 2009
	 * </pre>
	 * 
	 * TO getConfirmButton WRITEME...
	 * 
	 * @return WRITEME twheys@gmail.com
	 */
	private Button getApplyButton () {
		final Button submitButton = new Button ("");
		submitButton.setStyleName ("confirm-button");
		submitButton.getElement ().setId ("submit-button");
		submitButton.addClickHandler (new ClickHandler () {
			@Override
			public void onClick (final ClickEvent event) {
				TootsBook.displayLoadingBar ();
				applySelectedThemeItems ();
			}
		});
		return submitButton;
	}

	/**
	 * @return the avatarBox
	 */
	public Box getAvatarBox () {
		return avatarBox;
	}

	/**
	 * <pre>
	 * twheys@gmail.com Dec 17, 2009
	 * </pre>
	 *
	 * TO getButtons WRITEME...
	 *
	 * @return WRITEME twheys@gmail.com
	 */
	private SimplePanel getButtons () {
		final SimplePanel buttonPanel = new SimplePanel ();
		final HorizontalPanel buttonTable = new HorizontalPanel ();
		buttonPanel.setWidget (buttonTable);
		buttonTable.setSpacing (15);
		buttonTable
				.setHorizontalAlignment (HasHorizontalAlignment.ALIGN_CENTER);
		buttonTable
				.setVerticalAlignment (HasVerticalAlignment.ALIGN_MIDDLE);
		buttonTable.add (getCancelButton ());
		buttonTable.add (getApplyButton ());
		return buttonPanel;

	}

	/**
	 * <pre>
	 * twheys@gmail.com Dec 17, 2009
	 * </pre>
	 *
	 * TO getCancelButton WRITEME...
	 *
	 * @return WRITEME twheys@gmail.com
	 */
	private Button getCancelButton () {
		final Button cancelButton = new Button ("");
		cancelButton.setStyleName ("confirm-button");
		cancelButton.getElement ().setId ("cancel-button");
		cancelButton.addClickHandler (new ClickHandler () {
			@Override
			public void onClick (final ClickEvent event) {
				loadDefaultStyleSheets ();
				resetAvatarBG ();
				resetIcon ();
			}
		});
		return cancelButton;
	}

	/**
	 * <pre>
	 * twheys@gmail.com Jan 14, 2010
	 * </pre>
	 *
	 * TO getRightContent WRITEME...
	 *
	 * @return WRITEME twheys@gmail.com
	 */
	private Widget getCenterContent () {
		buildTitlePanel ();
		buildOptionsPanel ();
		titleBox.addStyleName ("center-panel");
		optionsBox.addStyleName ("center-panel");
		final VerticalPanel centerContent = new VerticalPanel ();
		centerContent
				.setHorizontalAlignment (HasHorizontalAlignment.ALIGN_CENTER);
		centerContent.add (titleBox);
		centerContent.add (optionsBox);
		return centerContent;
	}

	/**
	 * @return the items
	 */
	public AvailableItems getItems () {
		return items;
	}

	/**
	 * <pre>
	 * twheys@gmail.com Jan 14, 2010
	 * </pre>
	 *
	 * TO getLeftContent WRITEME...
	 *
	 * @return WRITEME
	 */
	private Widget getLeftContent () {
		buildAvatarPanel ();
		buildIconBox ();
		buildStoreAdPanel ();
		getAvatarBox().addStyleName ("left-panel");
		iconBox.addStyleName ("left-panel");
		storeAdBox.addStyleName ("left-panel");
		final VerticalPanel leftContent = new VerticalPanel ();
		leftContent
				.setHorizontalAlignment (HasHorizontalAlignment.ALIGN_CENTER);
		leftContent.add (getAvatarBox());
		leftContent.add (iconBox);
		leftContent.add (storeAdBox);
		return leftContent;
	}

	/**
	 * <pre>
	 * twheys@gmail.com Dec 17, 2009
	 * </pre>
	 *
	 * TO getNewOptionPanel WRITEME...
	 *
	 * @param optionLabel WRITEME
	 * @return an Option Panel that represents one setting the user can
	 *         scroll through.
	 */
	private SimplePanel getNewOptionPanel (
			final OptionLabel optionLabel) {
		final SimplePanel optionPanel = new SimplePanel ();
		final HorizontalPanel optionTable = new HorizontalPanel ();
		optionPanel.setWidth ("100%");
		optionPanel.setWidget (optionTable);
		optionTable
				.setHorizontalAlignment (HasHorizontalAlignment.ALIGN_CENTER);
		optionTable
				.setVerticalAlignment (HasVerticalAlignment.ALIGN_MIDDLE);
		optionTable.add (getOptionScrollButton (
				SettingsPage.LEFT1_ARROW, optionLabel));
		optionTable.add (optionLabel);
		optionTable.add (getOptionScrollButton (
				SettingsPage.RIGHT_ARROW, optionLabel));
		optionTable.setCellWidth (optionLabel, "750px");
		optionTable.addStyleName ("option head-foot-color box-border");
		return optionPanel;
	}

	/**
	 * <pre>
	 * twheys@gmail.com Dec 17, 2009
	 * </pre>
	 *
	 * TO getOptionScrollButton WRITEME...
	 *
	 * @param directionOfArrowOnButton LEFT_ARROW or RIGHT_ARROW
	 * @param optionLabel The option label to manipulate with this
	 *            button.
	 * @return a button styled
	 */
	private Button getOptionScrollButton (
			final int directionOfArrowOnButton,
			final OptionLabel optionLabel) {
		final Button button = new Button ("");
		button.setStyleName ("arrow-button");
		switch (directionOfArrowOnButton) {
			case LEFT1_ARROW:
				button.setTitle ("Previous");
				button.getElement ().setId ("left-arrow");
				button.addClickHandler (new ClickHandler () {
					@Override
					public void onClick (final ClickEvent event) {
						optionLabel.previousOption ();
					}
				});
				break;
			case RIGHT_ARROW:
				button.setTitle ("Next");
				button.getElement ().setId ("right-arrow");
				button.addClickHandler (new ClickHandler () {
					@Override
					public void onClick (final ClickEvent event) {
						optionLabel.nextOption ();
					}
				});
				break;
		default:
			// no op
			break;
		}
		return button;

	}

	/**
	 * <pre>
	 * twheys@gmail.com Jan 14, 2010
	 * </pre>
	 *
	 * TO getRightContent WRITEME...
	 *
	 * @return WRITEME
	 */
	private Widget getRightContent () {
		buildAdPanel ();
		adBox.addStyleName ("right-panel");
		final VerticalPanel rightContent = new VerticalPanel ();
		rightContent
				.setHorizontalAlignment (HasHorizontalAlignment.ALIGN_CENTER);
		rightContent.add (adBox);
		return rightContent;
	}

	/**
	 * <pre>
	 * twheys@gmail.com Dec 17, 2009
	 * </pre>
	 *
	 * TO loadDefaultStyleSheets WRITEME...
	 */
	void loadDefaultStyleSheets () {
		final UserProfile user = TootsBook.getUser ();
		TootsBook.loadBoxStylesStyleSheet (user.getBoxStyleURL ());
		TootsBook.loadPageBGStyleSheet (user.getPageStyleURL ());
		TootsBook.loadTitleBGStyleSheet (user.getTitleStyleURL ());
	}

	/**
	 *
	 */
	void resetAvatarBG () {
		if (TootsBook.ifIE ()) {
			avatarPanelIE.setUrl (TootsBook.getUser ()
					.getAvatarBgURL ());
		} else {
			AvatarBox.updateAvatarBackground (TootsBook.getUser ()
					.getAvatarBgURL ());
		}
	}
	
	/**
	 * <pre>
	 * twheys@gmail.com Dec 18, 2009
	 * </pre>
	 * 
	 * TO resetIcon WRITEME...
	 */
	void resetIcon () {
		changeIcon (TootsBook.getUser ().getIcon ());
	}

	/**
	 * @param newAvatarBox the avatarBox to set
	 */
	public void setAvatarBox (final Box newAvatarBox) {
		avatarBox = newAvatarBox;
	}
}
