
if(!blizDev) var blizDev = {};

blizDev.ads = function()
{
	return {
		createRotatingAd: function(containerID, redirectUrl)
		{
			if(!redirectUrl)
				redirectUrl = "/ad-redirect.aspx?url=";

			var Ads = new Array({ description: "Web Design", imageUrl: "http://www.downtownblueridgemountains.com/images/ads/web-design1.png", linkUrl: "http://www.blizzarddigital.com/get-web-design.aspx" }, { description: "AdWords Campaign Optimization", imageUrl: "http://www.downtownblueridgemountains.com/images/ads/AdWords-Optimization2.png", linkUrl: "http://www.blizzarddigital.com/pay-per-click/adwords-optimization.aspx" }, { description: "Professional Business Website-SEO Package for $850", imageUrl: "http://www.downtownblueridgemountains.com/images/ads/business-website-package.png", linkUrl: "http://www.blizzarddigital.com/business-website.aspx" });

			// Sort out ad index stuff
			var AdIndex = -1;

			if(blizDev.ads.areCookiesEnabled())
			{
				// Get the last used index
				var CookieParts = document.cookie.split(";");
				var CookieRegExp = RegExp("^\\s*(.+?)\\s*=\\s*(.+)");

				for(var i = 0; i != CookieParts.length; ++i)
				{
					var Results = CookieRegExp.exec(CookieParts[i]);

					if(Results && Results.length > 0 && Results[1] == "LastAd")
					{
						AdIndex = parseInt(Results[2]);
						break;
					}
				}

				// Get new index
				++AdIndex;

				if(AdIndex >= Ads.length)
					AdIndex = 0;

				// Save new index
				var CookieExpDate = new Date();

				CookieExpDate.setFullYear(CookieExpDate.getFullYear() + 1);

				var CookieStr = "LastAd=" + AdIndex + "; expires=" + CookieExpDate.toUTCString() + "; path=/";

				document.cookie = CookieStr;
			}
			else
				AdIndex = Math.floor(Math.random() * (Ads.length * 10) * 0.1);

			// Render ad
			var AdContainer = document.getElementById(containerID);
			
			if(!AdContainer)
			{
				alert("No banner container found with ID '" + containerID + "'.");
				return;
			}
			
			var AdA = document.createElement("a");
			var AdImg = document.createElement("img");

			AdA.setAttribute("href", redirectUrl + Ads[AdIndex].linkUrl);
			AdImg.setAttribute("src", Ads[AdIndex].imageUrl);
			AdImg.setAttribute("alt", Ads[AdIndex].description);

			AdContainer.appendChild(AdA);
			AdA.appendChild(AdImg);
		},

		areCookiesEnabled: function()
		{
			document.cookie = "CookieEnabled=true; path=/";

			if(document.cookie == "")
				return false;
			else
			{
				// Erase the test value
				var D = new Date();

				D.setTime(D.getTime() - (24 * 60 * 60 * 1000));
				document.cookie = "CookieEnabled=; expires=" + D.toUTCString() + "; path=/";

				return true;
			}
		}
	};
} ();
