//
// $Id: site.js 587 2007-04-16 22:25:52Z dtlrjt $
//
//

// Browser gestalt
Browser = {
 id		: function() {return navigator.userAgent.toLowerCase();},
 ver	: function() {
	var x = 0;
 	if (this.isIE()) {
		x = this.id().indexOf("msie ");
		ver = parseFloat(this.id().substring(x + 5));
	} else {
	  x = this.id().length - 1;
	  while (x >= 0 && this.id().charAt(x) != ' ' && this.id().charAt(x) != '/')
		  x--;
	  if (x >= 0)
		  ver = parseFloat(this.id().substring(x + 1));
	  else
		  ver = parseFloat(navigator.appVersion);
	}
  	return ver;
 },

 mozVer			: function() {return parseFloat(navigator.appVersion);},
 isAdvanced		: function() {return Boolean(this.hasDOM() && this.hasCreateElement());},

 isWindows		: function() {return this.id().indexOf("win")!=-1;},
 isMac			: function() {return this.id().indexOf("mac")!=-1;},

 isIE			: function() {return this.id().indexOf("msie")!=-1 && !this.isOpera();},
 isFirefox		: function() {return this.id().indexOf("firefox")!=-1;},
 isGecko		: function() {return this.id().indexOf("gecko")!=-1;},
 isOpera		: function() {return this.id().indexOf("opera")!=-1;},
 isSafari		: function() {return this.id().indexOf("safari")!=-1;},
 isOmniWeb		: function() {return this.id().indexOf("omniweb")!=-1;},
 isKonqueror	: function() {return this.id().indexOf("konqueror")!=-1;},
 isWebTV		: function() {return this.id().indexOf("webtv")!=-1;},
 isNetscape		: function() {return !this.isGecko() && this.id().indexOf("compatible")<0;},
 isMozilla		: function() {return this.isGecko() && !this.isFirefox() && !this.isSafari() && !this.isNetscape();},

 hasLayers		: function() {return Boolean(document.layers);},
 hasAll			: function() {return Boolean(document.all);},
 hasImages		: function() {return Boolean(document.images);},
 hasForms		: function() {return Boolean(document.forms);},
 hasCreateElement	: function() {return Boolean(document.createElement);},
 hasCreateDoc	: function() {return Boolean(document.implementation && document.implementation.createDocument);},
 hasRegExp		: function() {return Boolean(window.RegExp);},
 hasDOM			: function() {return Boolean(document.getElementById);},
 hasGEBI		: function() {return this.hasDOM();},
 hasGEBTN		: function() {return Boolean(document.getElementsByTagName);},
 hasActiveX		: function() {return Boolean(window.ActiveXObject);},
 WindowOnload	: function(f) {
	var prev = window.onload;
	window.onload = function() { if (prev) prev(); f(); }
 },

 // Browser-independent return of DOM element by ID attribute (most modern browsers)
 getElementById : function(id) {
    if (document.getElementById)
        return document.getElementById(id);
    else if (document.all)
        return document.all[id];

    alert('Browser not supported');
    return null;
 },

 // Get a style object for item by id
 getStyleObj : function(id) {
  var obj = this.findObj(id);
  if (obj) {
   if ((this.hasDOM() || this.hasAll()))
    return obj.style;
   else if (this.hasLayers())
    return obj;
  }
  alert("JavaScript error: could not find style object for '" + id + "'");
  return null;
 },

 // Set opacity (%) on an object by id or obj
 setOpacity : function(pct, id, obj) {
  if (id != '')
  	obj = this.findObj(id);
  if (obj.filters)
   obj.filters("alpha").opacity = pct;
  else if (obj.style) {
   var amt = pct / 100;
   if (amt > .99999)
   	amt = .99999;
   obj.style.MozOpacity = amt;
   obj.style.khtmlOpacity = amt;
   obj.style.opacity = amt;
  }
 },

 // get opacity (%) on an object by id or obj
 getOpacity : function(id, obj) {
  if (id != '')
  	obj = this.findObj(id);
  if (obj.filters)
   return obj.filters("alpha").opacity;
  else if (obj.style) {
  	var amt = obj.style.MozOpacity ||
			  obj.style.khtmlOpacity ||
   			  obj.style.opacity;

	return Math.round(amt * 100);
  }

 },

 // xGetElementsByTagName r4, Copyright 2002-2007 Michael Foster (Cross-Browser.com)
 // Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL

 xGetElementsByTagName : function(t,p) {
   var list = null;
   t = t || '*';
   p = p || document;
   if (typeof p.getElementsByTagName != 'undefined') { // DOM1
	 list = p.getElementsByTagName(t);
	 if (t=='*' && (!list || !list.length)) list = p.all; // IE5 '*' bug
   }
   else { // IE4 object model
	 if (t=='*') list = p.all;
	 else if (p.all && p.all.tags) list = p.all.tags(t);
   }
   return list || new Array();
 },

 // xGetElementsByClassName r5, Copyright 2002-2007 Michael Foster (Cross-Browser.com)
 // Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL

 xGetElementsByClassName : function(c,p,t,f) {
  var r = new Array();
  var re = new RegExp("(^|\\s)"+c+"(\\s|$)");
//  var e = p.getElementsByTagName(t);
  var e = this.xGetElementsByTagName(t,p); // See xml comments.
  for (var i = 0; i < e.length; ++i) {
    if (re.test(e[i].className)) {
      r[r.length] = e[i];
      if (f) f(e[i]);
    }
  }
  return r;
}


}; // class Browser


function xfadeset(count) {

	var pause_to_read = 5000;

	var starting = true;
	var set = 0;
	var layer = 0;
	var setObj = new Array();
	var imgs = new Array();
	var pics = [new Array(setObj.length), new Array(count)];

	fadeFX = function(fade, step, speed) {
		done = fade >= 100;
		fade_down = done ? 0 : 100 - fade;
		fade_up = done ? 100 : fade;
		for (n = 0; n < setObj.length; n++) {
			if (!starting)
				Browser.setOpacity(fade_down, '', imgs[n][layer ? 0 : 1]);
			Browser.setOpacity(fade_up, '', imgs[n][layer]);
		}
		if (done) {
			if (count > 1) {
				if (++set >= count)
					set = 0;
				layer = layer ? 0 : 1;
				starting = false;
				for (n = 0; n < setObj.length; n++)
					imgs[n][layer].src = pics[n][set].src;
				setTimeout(function() { startFX(); }, pause_to_read);
			}
		} else
			setTimeout(function() { fadeFX(fade + step, step, speed); }, speed);
	}

	startFX = function() {
		fadeFX(0, 5, 50);
	}

	setObj = Browser.xGetElementsByClassName('xfadeset');
	for (n = 0; n < setObj.length; n++) {
		imgs[n] = setObj[n].getElementsByTagName('img');
		name = imgs[n][0].src;
		pos = name.lastIndexOf("1");
		for (c = 0; c < count; c++) {
			pics[n][c] = new Image();
			pics[n][c].src = name.substr(0, pos) + (c+1) + name.substr(pos + 1);
		}
	}

	startFX();
}



function popup(url, id, w, h, x, y, resize, scrollbar, menubar, status, toolbar) {
  var opt = '';
  var noDef;

  if (Browser.isSafari()) {
   w += 3;		// avoid scroll bars
   h += 3;
  }

  if (w != noDef) {
	opt += 'width=' + w + ',';
	if (x == noDef)
		x = (screen.width - w) / 2;
	opt += 'left=' + x  + ',';
  }

  if (h != noDef) {
	opt += 'height=' + h + ',';
	if (y == noDef)
		y = (screen.height - h) / 2;
	opt += 'top=' + y + ',';
  }

  if (resize != noDef)		opt += 'resizable=no,';
  if (scrollbar != noDef)	opt += 'scrollbars=' + scrollbar + ',';
  if (menubar != noDef)	opt += 'menubar=' + menubar + ',';
  if (status != noDef)		opt += 'status=' + status + ',';
  if (toolbar != noDef)	opt += 'toolbar=' + toolbar + ',';

  var win = window.open(url, id, opt);
  if (win)
	win.focus();
  else
    alert("You appear to have a pop-up blocker that prevents the requested window from opening. Please enable pop-ups for this site and try again. Thank you.");
}

function xfadeset_quote() {
	xfadeset(1);
}

function die_eolas() {
 applet_wrap = document.getElementsByTagName("applet");
 for (var i = 0; i < applet_wrap.length; i++) {
  node = applet_wrap[i];
  if (node.className == 'applet_wrap') {
   if (Browser.isIE() && Browser.ver() > 5) {
  	node.outerHTML = node.innerHTML;
   } else {
    p = node.parentNode;
    real_applet = node.getElementsByTagName("applet");
	p.removeChild(node);
	p.appendChild(real_applet[0]);
   }
  }
 }
}
