// http://www.chalcedony.com/javascript/ modified by BJB 20000728 to display random first image
// BJB20030109 Modded to display ads in specific rotation

//----------------------//
// SUPPORTING FUNCTIONS	//
//----------------------//

// include ad array .js before this .js

	
	function rotateAd() {

		if (document.images) {		

			if (straryadTmp == straryadTmpDflt && GetCookieAd("LastAd") != null && varWriteBannerAdCnt == 0) { // DEFAULT AD ARRAY AND WE HAVE LASTAD COOKIE VALUE
				thisAd = Math.abs(GetCookieAd("LastAd")) // SET thisAd VAL TO STORED VAL
			}

			thisAd++ // INCREMENT AD
			if (thisAd >= imgCt) { // IF AD TO BE DISPLAYED IS OUT OF BOUNDS RETURN TO AD NUMBER ONE
				thisAd = 1
			}

			if (straryadTmp == straryadTmpDflt) {SetCookieAd("LastAd",thisAd)} // DEFAULT AD ARRAY, STORE AD NUMBER IN COOKIE FOR LATER REFERENCE

			document.adBanner.src = ProtCol + "//www.gordonsart.com/ads/" + adImages[thisAd] // DISPLAY AD IMG

			AdURL = adURLs[thisAd] // SET AD URL

			varWriteBannerAdCnt++ // INCREMENT COUNTER

		  	setTimeout("rotateAd()", adRotSec * 1000)

		}
	}

function SetCookieAd(name, value, expires, path, domain, secure) { // BJB20050513
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  if ((name + "=" + escape(value)).length <= 4000)
   document.cookie = curCookie
  else
   if (confirm("Your cookie file exceeds the 4KB limit - older selections will be forgotten if you proceed"))
  document.cookie = curCookie;
}

function GetCookieAd(name) { // BJB20050513
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

//----------------------//
// MAIN			//
//----------------------//

if (straryadTmp == straryadTmpDflt && GetCookieAd("LastAd") != null) { // DEFAULT AD ARRAY AND WE HAVE LASTAD COOKIE VALUE
	if (Math.abs(GetCookieAd("LastAd")) >= imgCt) { // LAST AD SHOWN IS OUT OF BOUNDS
		fncWriteBannerAd(ProtCol + "//www.gordonsart.com/ads/" + adImages[1]) // SHOW FIRST AD
	} else {
		fncWriteBannerAd(ProtCol + "//www.gordonsart.com/ads/" + adImages[Math.abs(GetCookieAd("LastAd"))]) // SHOW LAST AD
	}
} else {
	fncWriteBannerAd(ProtCol + "//www.gordonsart.com/ads/" + adImages[1]) // SHOW FIRST AD
}
setTimeout("rotateAd()", 2 * 1000); // START AD ROTATION
varWriteBannerAdCnt = 0 // PAGE-LEVEL ROTATION COUNTER

