
var mapType = '';
var hw_MSIE = false;
if(navigator.userAgent.indexOf('MSIE')>=0)hw_MSIE=true;



		var Cookie = {
		  set: function(name, value, daysToExpire) {
		    var expire = '';
		    if (daysToExpire != undefined) {
		      var d = new Date();
		      d.setTime(d.getTime() + (86400000 * parseFloat(daysToExpire)));
		      expire = '; expires=' + d.toGMTString();
		    }
		    return (document.cookie = escape(name) + '=' + escape(value || '') + expire + '; path=/');
		  },
		  get: function(name) {
		    var cookie = document.cookie.match(new RegExp('(^|;)\\s*' + escape(name) + '=([^;\\s]*)'));
		    return (cookie ? unescape(cookie[2]) : null);
		  },
		  erase: function(name) {
		    var cookie = Cookie.get(name) || true;
		    Cookie.set(name, '', -1);
		    return cookie;
		  },
		  accept: function() {
		    if (typeof navigator.cookieEnabled == 'boolean') {
		      return navigator.cookieEnabled;
		    }
		    Cookie.set('_test', '1');
		    return (Cookie.erase('_test') === '1');
		  }
		};


	function toggleCities() {
		var cityLink = $('citiesLink');

			if (cityLink.innerHTML == 'Show cities') {
				Element.show('cities');
				cityLink.innerHTML = 'Hide cities';
				var result = Cookie.set('showCities', 0, 30);
			}
			else {
				Element.hide('cities');
				cityLink.innerHTML = 'Show cities';

				var result = Cookie.set('showCities', 1, 30);
			}

	}




function updateMap(useType, sNeedle,sReplace) {

	if (useType == '') useType = 'gradient';

	var img  = $('contourMap');
	if (img == undefined || !img) return;

	var imgSrc = img.src.toString();

	if ((typeof noBlock != 'undefined')) {
		if (noBlock && useType == 'block') return '';
	}



	if (sNeedle && sReplace) imgSrc = imgSrc.replace(sNeedle, sReplace);
	else if (useType == 'block') imgSrc = imgSrc.replace("_i1", "_i5");
	else if (useType == 'gradient') 	imgSrc = imgSrc.replace("_i5", "_i1");



	if (imgSrc != img.src.toString()) img.src = imgSrc;

	if (useType == 'gradient' && $('gradientLink')) 	{
		$('gradientLink').className = 'highlite';
		$('blockLink').className = '';

		var result = Cookie.set('useType', 'gradient', 30);

	}
	else if (useType == 'block' && $('gradientLink')) {
		$('gradientLink').className = '';
		$('blockLink').className = 'highlite';

		var result = Cookie.set('useType', 'block', 30);
	}

	mapType = useType;

}

	function initDisplay(bCitiesOnly) {

		if (typeof bCitiesOnly == 'undefined') bCitiesOnly = false;

		var showCities = Cookie.get('showCities');
		var cityLink = $('citiesLink');
		if ($('cities')) {
			if (showCities == 1) {
				Element.hide('cities');
				cityLink.innerHTML = 'Show cities';
			}
			else {
				Element.show('cities');
				cityLink.innerHTML = 'Hide cities';
			}
		}

		if (!bCitiesOnly) {
			var mapType = Cookie.get('useType');
			if (!mapType) mapType = 'gradient';
			updateMap(mapType);
		}



	}

function sprintf( ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Ash Searle (http://hexmen.com/blog/)
    // *     example 1: sprintf("%01.2f", 123.1);
    // *     returns 1: 123.10

    function pad(str, len, chr, leftJustify) {
        var padding = (str.length >= len) ? '' : Array(1 + len - str.length >>> 0).join(chr);
        return leftJustify ? str + padding : padding + str;
    }

    function justify(value, prefix, leftJustify, minWidth, zeroPad) {
        var diff = minWidth - value.length;
        if (diff > 0) {
            if (leftJustify || !zeroPad) {
            value = pad(value, minWidth, ' ', leftJustify);
            } else {
            value = value.slice(0, prefix.length) + pad('', diff, '0', true) + value.slice(prefix.length);
            }
        }
        return value;
    }

    function formatBaseX(value, base, prefix, leftJustify, minWidth, precision, zeroPad) {
        // Note: casts negative numbers to positive ones
        var number = value >>> 0;
        prefix = prefix && number && {'2': '0b', '8': '0', '16': '0x'}[base] || '';
        value = prefix + pad(number.toString(base), precision || 0, '0', false);
        return justify(value, prefix, leftJustify, minWidth, zeroPad);
    }

    function formatString(value, leftJustify, minWidth, precision, zeroPad) {
        if (precision != null) {
            value = value.slice(0, precision);
        }
        return justify(value, '', leftJustify, minWidth, zeroPad);
    }

    var regex = /%%|%(\d+\$)?([-+#0 ]*)(\*\d+\$|\*|\d+)?(\.(\*\d+\$|\*|\d+))?([scboxXuidfegEG])/g;
    var a = arguments, i = 0, format = a[i++];

    return format.replace(regex, function(substring, valueIndex, flags, minWidth, _, precision, type) {
        if (substring == '%%') return '%';

        // parse flags
        var leftJustify = false, positivePrefix = '', zeroPad = false, prefixBaseX = false;
        for (var j = 0; flags && j < flags.length; j++) switch (flags.charAt(j)) {
            case ' ': positivePrefix = ' '; break;
            case '+': positivePrefix = '+'; break;
            case '-': leftJustify = true; break;
            case '0': zeroPad = true; break;
            case '#': prefixBaseX = true; break;
        }

        // parameters may be null, undefined, empty-string or real valued
        // we want to ignore null, undefined and empty-string values
        if (!minWidth) {
            minWidth = 0;
        } else if (minWidth == '*') {
            minWidth = +a[i++];
        } else if (minWidth.charAt(0) == '*') {
            minWidth = +a[minWidth.slice(1, -1)];
        } else {
            minWidth = +minWidth;
        }

        // Note: undocumented perl feature:
        if (minWidth < 0) {
            minWidth = -minWidth;
            leftJustify = true;
        }

        if (!isFinite(minWidth)) {
            throw new Error('sprintf: (minimum-)width must be finite');
        }

        if (!precision) {
            precision = 'fFeE'.indexOf(type) > -1 ? 6 : (type == 'd') ? 0 : void(0);
        } else if (precision == '*') {
            precision = +a[i++];
        } else if (precision.charAt(0) == '*') {
            precision = +a[precision.slice(1, -1)];
        } else {
            precision = +precision;
        }

        // grab value using valueIndex if required?
        var value = valueIndex ? a[valueIndex.slice(0, -1)] : a[i++];

        switch (type) {
            case 's': return formatString(String(value), leftJustify, minWidth, precision, zeroPad);
            case 'c': return formatString(String.fromCharCode(+value), leftJustify, minWidth, precision, zeroPad);
            case 'b': return formatBaseX(value, 2, prefixBaseX, leftJustify, minWidth, precision, zeroPad);
            case 'o': return formatBaseX(value, 8, prefixBaseX, leftJustify, minWidth, precision, zeroPad);
            case 'x': return formatBaseX(value, 16, prefixBaseX, leftJustify, minWidth, precision, zeroPad);
            case 'X': return formatBaseX(value, 16, prefixBaseX, leftJustify, minWidth, precision, zeroPad).toUpperCase();
            case 'u': return formatBaseX(value, 10, prefixBaseX, leftJustify, minWidth, precision, zeroPad);
            case 'i':
            case 'd': {
                      var number = parseInt(+value);
                      var prefix = number < 0 ? '-' : positivePrefix;
                      value = prefix + pad(String(Math.abs(number)), precision, '0', false);
                      return justify(value, prefix, leftJustify, minWidth, zeroPad);
                  }
            case 'e':
            case 'E':
            case 'f':
            case 'F':
            case 'g':
            case 'G':
                      {
                      var number = +value;
                      var prefix = number < 0 ? '-' : positivePrefix;
                      var method = ['toExponential', 'toFixed', 'toPrecision']['efg'.indexOf(type.toLowerCase())];
                      var textTransform = ['toString', 'toUpperCase']['eEfFgG'.indexOf(type) % 2];
                      value = prefix + Math.abs(number)[method](precision);
                      return justify(value, prefix, leftJustify, minWidth, zeroPad)[textTransform]();
                  }
            default: return substring;
        }
    });
}



function ImagePreloader(timages, callBack, statusDiv)

{
  // store the call-back
   this.callBack = callBack;
   this.statusDiv = statusDiv;
   // initialize internal state.

   this.nLoaded = 0;
   this.nProcessed = 0;
   this.aImages = new Array;

   // record the number of images.
   this.nImages = timages.length;

   // for each image, call preload()
	if (this.statusDiv) $(this.statusDiv).innerHTML = '<div style="position: relative; top: 5px;">Loading 1 of ' + this.nImages + '</div>';
   for ( var i = 0; i < timages.length; i++ )
      this.preload(timages[i]);
}

ImagePreloader.prototype.preload = function(image)

{
   // create new Image object and add to array
   var oImage = new Image;
   this.aImages.push(oImage);

   // set up event handlers for the Image object
   oImage.onload = ImagePreloader.prototype.onload;
   oImage.onerror = ImagePreloader.prototype.onerror;
   oImage.onabort = ImagePreloader.prototype.onabort;

   // assign pointer back to this.
   oImage.oImagePreloader = this;
   oImage.bLoaded = false;

   // assign the .src property of the Image object
   oImage.src = image;

}



ImagePreloader.prototype.onComplete = function()

{
   this.nProcessed++;
   if (this.statusDiv) $(this.statusDiv).innerHTML = '<div style="position: relative; top: 5px;">Loading ' + this.nProcessed + ' of ' + this.nImages +'</div>';
   if ( this.nProcessed == this.nImages )
   {
      this.callBack(this.aImages, this.nLoaded);
   }

}

ImagePreloader.prototype.onload = function()
{
   this.bLoaded = true;
   this.oImagePreloader.nLoaded++;
   this.oImagePreloader.onComplete();

}

ImagePreloader.prototype.onerror = function()
{
   this.bError = true;
   this.oImagePreloader.onComplete();

}

ImagePreloader.prototype.onabort = function()
{
   this.bAbort = true;
   this.oImagePreloader.onComplete();

}



var pe = false;
var aImages = new Array();
var aIPs = new Array();
var animInterval = .15;
var animEndInterval = 1;
var animUseInterval = animInterval;

	function toggleAnimation(mapLoadingStatus) {

		if (pe) {
			stopAnimation();
		}
		else {
			$('anim_link' ).innerHTML = 'Stop';
			$('mapLoadingStatus').innerHTML = '';
			$('anim_link' ).className = 'highlite';

			if (aIPs[mapLoadingStatus]) {
				startAnimation(aIPs[mapLoadingStatus].aImages, aIPs[mapLoadingStatus].nLoaded);
			}
			else {
				Element.show('mapLoadingStatus');
				aIPs[mapLoadingStatus] = new ImagePreloader(aImages[mapLoadingStatus], startAnimation,'mapLoadingStatus');
			}
		}
	}
	function  stopAnimation() {
		if (pe) {
			Element.hide('mapLoadingStatus');
			pe.stop();
			pe = false;


			$('anim_link' ).innerHTML = 'Start';
			$('anim_link' ).className = '';
		}
	}


	function startAnimation(aImages, nLoaded) {
		Element.hide('mapLoadingStatus');
		$('anim_link' ).innerHTML = 'Stop';


		pe = new  PeriodicalExecuter(
		function(tpe) {
			mapHour--;
			if (mapHour < 0) mapHour = nLoaded-1;

			$('contourMap').src =  aImages[nLoaded - mapHour -1 ].src;
			updateMapHighlight();


		}, animInterval);

	}



function HWhint(hintID,hintObject,hintText, hintTitle) {
	if (hintID == undefined || hintID == null || hintID=='') hintID = 'HWhint';
	if (hintObject == undefined || hintObject == null) hintObject = '';
	if (hintText == undefined || hintText == null) hintText = '';

	if (hintTitle == undefined || hintTitle == null) hintTitle = 'Helpful Hint';


	this.id = hintID;
	this.forObject = hintObject;
	this.title = hintTitle;
	this.content = hintText;
	this.isURL = false;
	this.noWrapper = false; // if using html a wrapper is added unless this is set to true

	this.wide = false;

	this.autoCloseTime = 10; // timein second
	this.maxDisplays = 20;  // max time to display
	this.timeBetweenDisplays = 15; // time in minutes
}

HWhint.prototype.automatic = function () {
	var myHintID = 'HWhint_' + this.id;
	var myHintCount = 'HWhintC_' + this.id;

	var bDisplay = true;

	var showHint  = Cookie.get(myHintID);

	if (!showHint) {
		var hintCount  = Cookie.get(myHintCount);
		if (this.maxDisplays == 0 || !hintCount || !hintCount < this.maxDisplays) {

			this.display();


			if (!hintCount) hintCount = 1;
			else hintCount++;
			Cookie.set(myHintCount, hintCount, 7);

			if (this.timeBetweenDisplays >= 0) {
				var tExpires = (this.timeBetweenDisplays > 0) ? this.timeBetweenDisplays/60/24 : 0;
				Cookie.set(myHintID, 1, tExpires);
			}
			else {
				Cookie.erase(myHintID);
			}
		}
	}

}

HWhint.prototype.display = function() {

	ajax_hideTooltip();
	if (this.isURL) {
		ajax_showTooltip(this.content,$(this.forObject),this.wide);
	}
	else if (this.noWrapper) {
		html_showTooltip($(this.forObject), this.wide, this.content);
	}
	else {
		var tContent = '<div id=\'HWhint\'><div id=\'wrapper\'><div class=\'title\'>' + this.title + '</div><div class=\'content\'>' + this.content + '</div></div><div id=\'closer\'><a href=\'#\' onCLick=\'ajax_hideTooltip(); return false;\' title=\'close\'>X</a></div></div>';

		html_showTooltip($(this.forObject), this.wide, tContent);
	}

	if (this.autoCloseTime > 0) hideToolTipTimer(this.autoCloseTime * 1000);


}

var myHint = null;
function autoHint() {
	if (myHint) myHint.automatic();

}



/* HWTabs */

	function HWTabs() {
		this.sTabs = new Object();
		this.sTabContentURL = new Object();
		this.sTabContentComplete = new Object();
		this.contentCached = new Object();

		this.cacheContent = true;
	}

	HWTabs.prototype.add = function (tabID, tabContentID, contentURL, contentComplete) {
		if (tabID != undefined && tabID != '') {
			if (tabID != null) {
				this.sTabs[tabID] = tabContentID;
				this.sTabContentURL[tabID] = contentURL;
				this.sTabContentComplete[tabID] = contentComplete;
			}
		}

	}

	HWTabs.prototype.showTab = function (sTab) {
		if (sTab) {

			for ( s in this.sTabs  ) {
				if (s == sTab) {
					$(this.sTabs[s]).show();
					$(s).className= 'selected';
					if (this.sTabContentURL[sTab]) {
						if (this.cacheContent == false  || !this.contentCached[sTab]) {
							ajax_loadContent(this.sTabs[sTab], this.sTabContentURL[sTab],
												'<img src="/images/ajax-loader.gif" width="24" height="24" style="width:24px; height:24px; padding:15px;" />', this.sTabContentComplete[sTab]);

							this.contentCached[sTab] = true;

							;
						}
					}

				}
				else {
					$(this.sTabs[s]).hide();
					$(s).className= '';
				}
			}


		}
	}








