﻿; 
RegisterNamespace("VP.ArticleList");

VP.ArticleList = function(moduleId, element) {
	this._moduleId = moduleId;
	this._element = "#" + element;
	var that = this;

	$("#lnkShowAllCategories", this._element).addClass("hidden");
	$("#lnkShowAllVendors", this._element).addClass("hidden");
	$("div.categoryLinkList", this._element).hide();
	$("div.vendorLinkList", this._element).hide();

	$("#lnkShowAllCategories", this._element).click(function() {
		if ($("#lnkShowAllCategories.hidden", that._element).length > 0) {
			$("#lnkShowAllCategories", that._element).removeClass("hidden");
			$("div.categoryLinkList", that._element).show("slow");
			$("#lnkShowAllCategories", that._element).text("Hide All");
		}
		else {
			$("#lnkShowAllCategories", that._element).addClass("hidden");
			$("div.categoryLinkList", that._element).hide("slow");
			$("#lnkShowAllCategories", that._element).text("Show All");
		}
	});

	$("#lnkShowAllVendors", this._element).click(function() {
		if ($("#lnkShowAllVendors.hidden", that._element).length > 0) {
			$("#lnkShowAllVendors", that._element).removeClass("hidden");
			$("div.vendorLinkList", that._element).show("slow");
			$("#lnkShowAllVendors", that._element).text("Hide All");
		}
		else {
			$("#lnkShowAllVendors", that._element).addClass("hidden");
			$("div.vendorLinkList", that._element).hide("slow");
			$("#lnkShowAllVendors", that._element).text("Show All");
		}
	});


	$("#btnFilter", this._element).click(function() {
		document.location =
				that.GetFilterUrl(document.location, $(".vendors select", that._element).val(),
				 $(".categories select", that._element).val());
	});
	$("#btnReset", this._element).click(function() {
		document.location = that.GetFilterUrl(document.location, "-1", "-1");
	});
	$("#filterHeader", this._element).click(function() {
		if ($("#filterHeader.hidden", that._element).length > 0) {
			$("#filterHeader", that._element).removeClass("hidden");
			$("#filterBody", that._element).show("slow");
			$("#filterHeader", that._element).text("Hide Filter");
		}
		else {
			$("#filterHeader", that._element).addClass("hidden");
			$("#filterBody", that._element).hide("slow");
			$("#filterHeader", that._element).text("Show Filter");
		}
	});
};

VP.ArticleList.prototype.GetFilterUrl = function(Url, vendorId, categoryId) {
	var ActualUrl = Url.href.split('afcid_' + this._moduleId + '=');
	var currentUrl = ActualUrl[0];
	var temp = currentUrl.split('?');
	if (temp.length == 1) {
		currentUrl = currentUrl + "?";
	}
	else {
		currentUrl = currentUrl + "&";
	}
	return currentUrl = currentUrl + "afcid_" + this._moduleId + "=" + categoryId + "&afvid_" + this._moduleId + "=" + vendorId;
};

