browserName = navigator.appName;
browserVer = parseInt(navigator.appVersion);
var msie4 = (browserName == "Microsoft Internet Explorer" && browserVer >= 4);
if ((browserName == "Netscape" && browserVer >= 3) || msie4 || browserName=="Konqueror") {version = "n3";} else {version = "n2";}
// Blurring links:
function blurLink(theObject)	{	//
	if (msie4)	{theObject.blur();}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
	window.open(theURL,winName,features);
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

		
var AskTheExperts = {
	vertical: function(){
		var question = $$('#AskTheExperts .question');
		var headings = $$('#AskTheExperts .toggle');
		var list = $$('#AskTheExperts .wrapper');
		var collapsibles = new Array();
		
		headings.each( function(heading, i) {

			var collapsible = new Fx.Slide(list[i], { 
				duration: 500, 
				transition:Fx.Transitions.Circ.easeInOut,
				onComplete: function(request){ 
					var open = request.getStyle('margin-top').toInt();
					if(open >= 0){
						new Fx.Scroll(window).toElement(question[i]);
						// ===== Activate Stats Metrics =====
						// insert metrics code here to track question usage
						var hashId = question[i].getParent().getAttribute('id');
						window.location.hash = hashId;
					}
				}
			});
			
			collapsibles[i] = collapsible;
			
			heading.addEvent('click',function(){
				this.setHTML((this.getText().contains('get')? 'hide ':'get ')+'the answer');
				collapsible.toggle();
				return false;
			});
			
			collapsible.hide();
		});
	}
};

// ===== Countdown To Event ===============================================================================
window.addEvent('load',function(){
	if($('countdown')){
		var Event = {
			Total : 1,
			Count : 1,
			TimeZone : "ET",
			Date1 : {
				StartDate	: new Date("02/05/2009 00:00"),
				EndDate		: new Date("02/05/2009 23:59"),
				OnNowMsg 	: "GIS is here!",
				OnFinish	: ""
			}
		}
		var Clock = new CountdownClock($$('#countdown div.clock'),Event);
	}
});
var CountdownClock = new Class({
    initialize: function(el,options){
        this.options = options;
		this.today = new Date();
		this.date = this.options["Date"+this.options.Count].StartDate;
		this.type = "onClock";
		this.el = el;
		this.text = "";
		this.step = 1;
		this.periodical;
		this.nZone = -6;
		/*
		switch(this.options.TimeZone.toUpperCase()){
			case "ET": this.nZone = -5; break;
			case "CT": this.nZone = -6; break;
			case "MT": this.nZone = -7; break;
			case "PT": this.nZone = -8; break;
		}
		*/
		this.countdown();
		this.display();
	},
	display: function(){
		switch(this.step++){
			case 1:
				this.date = this.options["Date"+this.options.Count].StartDate;
				this.type = "onClock";
				this.text = "";
				break;
			case 2:
				this.date = this.options["Date"+this.options.Count].EndDate;
				this.type = "onNow";
				this.text = this.options["Date"+this.options.Count].OnNowMsg;
				break;
			case 3:
				this.type = "onFinish"
				this.text = this.options["Date"+this.options.Count].OnFinish;
				if(this.options.Count < this.options.Total){
					this.options.Count++;
					this.step = 1;
					this.display();
				}
				break;
		}
		this.periodical = this.countdown.periodical(1000,this);
	},
	countdown: function(){
		this.today = new Date();
		// ===== Reset Timezone ============================
		//var utc = this.today.getTime() + (this.today.getTimezoneOffset() * (60*1000));
		var utc = this.today.getTime() + (300 * (60*1000));
		var now = new Date(utc+((60*60*1000)*this.offset()));
		// ===== Format Date ===============================           
		//Find the difference, and convert that into seconds.                  
		var nTime = Math.round((this.date.getTime() - now.getTime()) / 1000);
		if(nTime > -1) { // still counting
			if(this.type == "onClock"){
				var days = this.addZeros(Math.floor(nTime / (60 * 60 * 24)));
				nTime %= (60 * 60 * 24);
				var hours = this.addZeros(Math.floor(nTime / (60 * 60)));
				nTime %= (60 * 60);
				var minutes = this.addZeros(Math.floor(nTime / 60));
				nTime %= 60;
				var seconds = this.addZeros(nTime);
				//this.el.setHTML(days+'<em>days</em> '+hours+'<em>hrs</em> '+minutes+'<em>mins</em>');
				// set each item
				this.el.getElement('#ccDays').setText(days);
				this.el.getElement('#ccHours').setText(hours);
				this.el.getElement('#ccMins').setText(':'+minutes+':');
				this.el.getElement('#ccSecs').setText(seconds);
				if(days == 1) this.el.getElement('#ccDays').removeClass('days').addClass('day');
			} else if(this.type == "onNow"){
				this.el.empty().setHTML(this.text);
			};
		} else {
			$clear(this.periodical);
			if(this.type != "onFinish"){
				this.display();
			} else {
				if(this.text != ""){
					this.el.setHTML('<em>'+this.text+'<em>');
				}
			}
		}
	},
	offset: function(){
		var thisYear = this.today.getFullYear();
		var MarchDate = 14 - (Math.floor (1 + thisYear * 5 / 4) % 7);
		var NovemberDate = 7 - (Math.floor (1 + thisYear * 5 / 4) % 7);
		var startDate = new Date(thisYear,2,MarchDate);
		var endDate = new Date(thisYear,10,NovemberDate);
		return (this.today.getTime() > startDate.getTime() && this.today.getTime() < endDate.getTime())? this.nZone+1 : this.nZone;
	},
	addZeros: function(digits){
		return (Number(digits) < 10) ? "0"+digits : digits;
	}
});
