var expandArray = [];

var HeaderCategories = function (options) {
	this.SetOptions(options);
	this.iButton = $("#" + this.options.iButton);
	this.iContent = $("#" + this.options.iContent);
	this.Initialization();
	this.timer = null;
	this.speed = this.options.speed;
	this.Over();
	this.Out();
	expandArray.push(this);
	// agn
	this.need_to_hide = true;
};

HeaderCategories.prototype = {
	SetOptions: function (options) {
		this.options = options;
		//		this.options = {
		//			iButton: "all",
		//			iContent: "lists",
		//			speed: 300
		//		};
		$.extend(this.options, options || {});
	},
	Initialization: function () {
		this.iHeightButton = this.iButton.height();
		this.iWidthButton = this.iButton.width();
		this.iTopButton = this.iButton.offset().top;
		this.iLeftButton = this.iButton.offset().left;

		this.iContent.css({ top: this.iHeightButton + this.iTopButton - 1, left: this.iLeftButton });
	},
	Over: function () {
		var _this = this;
		this.iButton.bind("mouseenter", function (event) {
			if ($(event.currentTarget).attr("id") == _this.options.iButton) {
				_this.Show();

				for (var i = 0; i < expandArray.length; i++) {
					if (expandArray[i].options.iButton !== _this.options.iButton)
						expandArray[i].Hide();
				}

			} else {
				_this.timer = setTimeout(function () { _this.Show(); }, _this.speed);
			}

		});
		// agn
		this.iContent.bind("mouseenter", function (event) {
			_this.need_to_hide = false;
		});
	},
	Out: function () {
		var _this = this;
		this.iButton.bind("mouseleave", function (event) {
			if ($(event.currentTarget).attr("id") != _this.options.iButton)
				_this.Hide();
			// agn
			else
				_this.timer = setTimeout(function () { if (_this.need_to_hide) _this.Hide(); }, _this.speed);
		});

		this.iContent.bind("mouseleave", function () {
			_this.Hide();
			_this.hidden = true;
			_this.need_to_hide = true;
		});
	},
	Show: function () {
		//this.SetOptions();
		this.iButton = $("#" + this.options.iButton);
		this.iContent = $("#" + this.options.iContent);
		this.Initialization();
		this.iButton.removeClass();
		this.iButton.addClass("all2");
		this.iContent.css({ visibility: "visible" });
	},
	Hide: function () {
		this.iContent.css({ visibility: "hidden" });
		this.iButton.removeClass();
		this.iButton.addClass("all");
	}
};
