﻿BF.accountLoginPopover = {
	init: function () {
		var self = this;

		// element references
		self.triggerParent = $('li#accountLoginLink');
		self.trigger = $('a#accountPopoverTrigger');
		self.target = $('div#accountLoginPopover');
		self.userNameField = $('div#accountLoginPopover input.accountUserID');
		self.passwordField = $('div#accountLoginPopover input.accountPassword');

		// event handlers
		self.trigger.click(function (e) {
			e.preventDefault();
			e.stopPropagation();
			self.showPopover();
		});

		self.target.click(function (e) { // stop propogation for hide function when clicking on popover area
			e.stopPropagation();
		});

		$('body').click(function () {
			self.hidePopover();
		});

	},

	showPopover: function () {
		var self = this;

		self.target.fadeIn();
		self.triggerParent.addClass('active');
		self.userNameField.focus();
	},

	hidePopover: function () {
		var self = this;

		self.userNameField.val('');
		self.passwordField.val('');
		self.triggerParent.removeClass('active');
		self.target.fadeOut();
	}
}
