﻿class_ExposureHyperLink = function(){}
class_ExposureHyperLink.prototype =
{
	_exposedCssClass : "EndecaRefinementExposureActive",
	_notExposedCssClass : "EndecaRefinementExposure",
	_exposureCookieName : "exposure",
	
	get_exposedCssClass : function()
	{
		return this._exposedCssClass;
	},
	set_exposedCssClass : function(className)
	{
		this._exposedCssClass = className;
	},
	get_notExposedCssClass : function()
	{
		return this._notExposedCssClass;
	},
	set_notExposedCssClass : function(className)
	{
		this._notExposedCssClass = className;
	},
	get_exposureCookieName : function()
	{
		return this._exposureCookieName;
	},
	set_exposureCookieName : function(cookieName)
	{
		this._exposureCookieName = cookieName;
	},
	set_ExposureCookie : function(dimensionId, isCollapse)
	{
		var expires = new Date();
		expires.setHours(expires.getHours() + 1, expires.getMinutes() + 1, expires.getSeconds(), expires.getMilliseconds());							

		var exposureCookie = Vehix.Presentation.getCookie(this.get_exposureCookieName());
		if (isCollapse)
		{
			if (exposureCookie == null)
			{
				Vehix.Presentation.setCookie(this.get_exposureCookieName(), "", expires);
			}
			else if (exposureCookie == dimensionId)
			{
				Vehix.Presentation.setCookie(this.get_exposureCookieName(), "", expires);
			}
			else if (exposureCookie.substring(0, dimensionId.length + 1) == dimensionId + "+")
			{
				Vehix.Presentation.setCookie(this.get_exposureCookieName(), exposureCookie.replace(dimensionId + "+", ""), expires);
			}
			else if (exposureCookie.substring(exposureCookie.length - dimensionId.length - 1) == "+" + dimensionId)
			{
				Vehix.Presentation.setCookie(this.get_exposureCookieName(), exposureCookie.substring(0, exposureCookie.length - dimensionId.length - 1), expires);
			}
			else if (-1 < exposureCookie.indexOf("+" + dimensionId + "+"))
			{
				Vehix.Presentation.setCookie(this.get_exposureCookieName(), exposureCookie.replace("+" + dimensionId + "+", "+"), expires);
			}
		}
		else
		{
			if (exposureCookie == null || exposureCookie == "")
			{
				Vehix.Presentation.setCookie(this.get_exposureCookieName(), dimensionId, expires);
			}
			else if (exposureCookie != dimensionId
				&& exposureCookie.substring(0, dimensionId.length + 1) != dimensionId + "+"
				&& exposureCookie.substring(exposureCookie.length - dimensionId.length - 1) != "+" + dimensionId
				&& exposureCookie.indexOf("+" + dimensionId + "+") < 0)
			{
				Vehix.Presentation.setCookie(this.get_exposureCookieName(), exposureCookie + "+" + dimensionId, expires);
			}
		}
	},
	
	doClick : function(link, dimensionId)
	{
		link.removeAttribute("href");
		link.style.cursor = "wait";
		window.status = "Done";

		var isCollapse = link.className == this.get_exposedCssClass();

		this.set_ExposureCookie(dimensionId, isCollapse);

		var refinementsDiv = link.nextSibling;
		while (refinementsDiv.nextSibling != null && (refinementsDiv == null || refinementsDiv.tagName != "DIV"))
		{
			refinementsDiv = refinementsDiv.nextSibling;
		}

		var customMoreLink = link.parentNode.nextSibling;
		if (customMoreLink != null && (customMoreLink.tagName != "DIV" || customMoreLink.innerHTML == null || customMoreLink.innerHTML.indexOf("ExposureHyperLink") >= 0))
		{
			customMoreLink = null;
		}

		// modify styles.
		link.className = isCollapse ? this.get_notExposedCssClass() : this.get_exposedCssClass();
		if (refinementsDiv != null)
		{
			refinementsDiv.style.display = isCollapse ? "none" : "";
		}
		if (customMoreLink != null)
		{
			customMoreLink.style.display = isCollapse ? "none" : "";
		}

		link.style.cursor = "";
		
		setTimeout(new Function("refreshAds();"), 1);
	}
}
var ExposureHyperLink = new class_ExposureHyperLink();
