isgecko = (navigator.userAgent.indexOf("Gecko")>=0);
isexplorer = (navigator.userAgent.indexOf("MSIE")>=0);

// MACROMEDIA FUNCTIONS //
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_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_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];}
}

function MM_displayLayers() { //v1.1
	for (var i=0; i<(arguments.length-1); i=i+2) {
		var l=arguments[i];var b=arguments[i+1];var o=MM_findObj(l);
		if (o) o.style.display=(b)?"":"none";
	}
}
// CUSTOM FUNCTIONS //
function shownav(p_key) {
	if (document.current_nav_obj != "") {
		window.clearTimeout(document.nav_timeout_obj);
		hidenav_go(document.current_nav_obj);
		document.current_nav_obj = "";
	}
	document.current_nav_obj = p_key;
	var o = MM_findObj("nav_" + p_key);
	if (o) o.style.visibility = "visible";
}
function hidenav(p_key) {
	document.nav_timeout_obj = window.setTimeout("hidenav_go('"+p_key+"');", 400);
}
function hidenav_go(p_key) {
	var o = MM_findObj("nav_" + p_key);
	if (o) o.style.visibility = "hidden";
}
function submitForm(p_frm) {
	var o = MM_findObj(p_frm);
	if (o) o.submit();
	else alert("Unable to submit form. Please contact the administrator.");
}
function submitformcheck(form) {
	var obj=MM_findObj(form);
	var frmname='_CF_check' + form + '(obj)';
	if (eval(frmname)) {
		obj.submit();
	}
}

function findPos(obj) {
	// =================================================
	// Find object location in pixels as array [x,y]
	// =================================================
	var curleft = 0;
	var curtop = 0;
	var self = true;
	while (obj.offsetParent) {
		curleft += obj.offsetLeft;
		curtop += obj.offsetTop;
		if (isexplorer && !self) {
			// fix for IE - some CSS borders cause offset
			curleft += obj.clientLeft;
			curtop += obj.clientTop;
		}
		obj = obj.offsetParent;
		self = false;
	}
	return [curleft,curtop];
}

/**************************************
		Top Nav functions
**************************************/

function topnav_onshow(o) {
	if (o == null) o = this;
   this.className='nav_link_over';
}
function topnav_onhide(o) {
	if (o == null) o = this;
    this.className='nav_link_off'
}
function topnav_onselected() {
    this.className='nav_link_on'
}


 /* toggles visibility of inner div elements of the parent div with name = div_name */
function toggleCssClass(obj,cl_prefix,is_short) {
	if (is_short) {
		obj.className = (obj.className == cl_prefix)? cl_prefix + "_on" : cl_prefix;
	}
	else {
		obj.className = (obj.className == cl_prefix + "_off")? cl_prefix + "_on" : cl_prefix + "_off";
	}
}

function fue_swap(o, u) {
	if (o && o.childNodes.length) {
		var img=o.childNodes[0];
		// find img tag
		while (img && (typeof(img.tagName) != "string" || img.tagName != "IMG")) {
			img = img.nextSibling;
		}
		if (img) img.src = u;
	}
}

function vidSlideShowOpen(id) {
	var source = document.getElementById("vidslideshow_base_" + id);
	source.style.display = "block";
}
function vidSlideShowClose(id) {
	var source = document.getElementById("vidslideshow_base_" + id);
	source.style.display = "none";
}
function contactUsOpen() {
	var source = document.getElementById("contact_base");
	source.style.display = "block";
}
function contactUsClose() {
	var source = document.getElementById("contact_base");
	source.style.display = "none";
}
function videoShowOpen() {
var source = document.getElementById("vid_base");
source.style.display = "block";
}
function videoShowClose() {
	var source = document.getElementById("vid_base");
	source.style.display = "none";
}

function openVideoPopup(oid) {
	var vidPop = window.open('popup.cfm?oid=' + oid, 'Video', 'scrollbars,status,resizable,width=425,height=600');
	vidPop.focus();
}
/**
* Returns the value of the selected radio button in the radio group, null if
* none are selected, and false if the button group doesn't exist
*
* @param {radio Object} or {radio id} el
* OR
* @param {form Object} or {form id} el
* @param {radio group name} radioGroup
*/ 
function $RF(el, radioGroup) { 
  if($(el).type && $(el).type.toLowerCase() == 'radio') { 
	  var radioGroup = $(el).name; 
	  var el = $(el).form; 
  } else if ($(el).tagName.toLowerCase() != 'form') { 
	  return false; 
  } 

  var checked = $(el).getInputs('radio', radioGroup).find( 
	  function(re) {return re.checked;} 
  ); 
  return (checked) ? $F(checked) : null; 
}


var PageExtend = {
	div: null,
	measure: null,
	footer: null,
	measureHeight: 0,
	chromeHeight: 0, // "chrome" meaning the rest of the web page, excluding the measureHeight (we assume here that the chromeHeight will not change one the page is loaded, but the content height may change due to dynamic content)
	viewHeight: 0,
	init: function() {
		// TODO: check for home page
		Event.observe(window, "load", this.startup.bind(this));
	},
	startup: function() {
		// set document scrollbars to "scroll" in firefox, since otherwise the page width will appear to jump repeatedly when resizing
		if ((/Gecko/).test(navigator.userAgent)) document.body.style.overflowY = "scroll";
		// find important divs
		
		if ($('div_shadowing') != null && $('contact_base') != null) {
			Event.observe(window, "resize", this.positionContact.bind(this));
			this.positionContact(null, true);
		}
		
		this.div = $("div_resizer");
		this.measure = $("div_resize_inner");
		this.footer = $("div_footer");
		if (!(this.div && this.measure && this.footer)) return;
		// reset footer to not have bottom drop shadow
		Element.addClassName(this.footer, "footer-clip");
		// call resize now, and on window resize
		Event.observe(window, "resize", this.resize.bind(this));
		this.resize(null, true);
	},
	resize: function(e, bFirstRun) {
		// measure content height
		var mh = Element.getHeight(this.measure);
		if (this.measureHeight == 0) this.measureHeight = mh; // store if we haven't yet
		// measure footer position and viewport height
		var fb = Element.cumulativeOffset(this.footer).top + Element.getHeight(this.footer);
		if (this.chromeHeight == 0) this.chromeHeight = fb - this.measureHeight;
		// get viewport height
		var vh = document.viewport.getHeight();
		if (this.viewHeight == 0) this.viewHeight = vh;
		// compare current measurements with last one
		if (bFirstRun || vh != this.viewHeight || mh != this.measureHeight) {
			var hNeed = Math.max(0, vh - (mh + this.chromeHeight));
			if (hNeed) this.div.style.height = (mh + hNeed) + "px";
		}
	},
	positionContact: function(e, bFirstRun) {
		// move contact us on resize
		if ($('div_shadowing') != null && $('contact_base') != null) {
			var shadow_pos = Element.cumulativeOffset($('div_shadowing'));
			$('contact_base').style.left = shadow_pos.left + 'px';
		}
	}
};
PageExtend.init();


var SlideShow = {
	objs: {},
	init: function() {
		Event.observe(window, "load", this.startup.bind(this));
	},
	startup: function() {
		for (var a in window) if (a.indexOf("vidss_refr_")==0) {
			var oid = a.substr(11, 10);
			if (!isNaN(oid)) {
				this.objs[oid] = new SlideShowPopup(oid, eval(window[a]));
			}
		}
	}
}
SlideShow.init();

var SlideShowPopup = Class.create();
SlideShowPopup.prototype = {
	oid: 0,
	data: null,
	current: 1,
	initialize: function(oid, data) {
		
		this.oid = oid;
		this.data = data;
		this.setup();
	},
	setup: function() {
		var that = this;
		(9).times(function(i){
			var a = $("vidss_num"+i+"_"+that.oid);
			
			if (!a) return;
			Event.observe(a, "mouseover", that.onMouseOver.bind(that, i));
			Event.observe(a, "mouseout", that.onMouseOut.bind(that, i));
			Event.observe(a, "click", that.onClick.bind(that, i));
		});
	},
	onMouseOver: function(i, event) {
		if (i == this.current) return;
		Event.element(event).className = "vid_on";
	},
	onMouseOut: function(i, event) {
		if (i == this.current) return;
		Event.element(event).className = "vid_off";
	},
	onClick: function(i, event) {
		if (i == this.current) return;
		var prev = $("vidss_num"+this.current+"_"+this.oid);
		if (prev) prev.className = "vid_off";
		Event.element(event).className = "vid_on";
		this.current = i;
		this.showSlide();
	},
	showSlide: function() {
		var i = this.current-1;
		$("vidss_image_"+this.oid).src = this.data[i].image;
		$("vidss_title_"+this.oid).innerHTML = this.data[i].title;
		$("vidss_desc_"+this.oid).innerHTML = this.data[i].description;
	}
};






