/*  functions useable by the pages */

/*  we can pass in a jquery object to take action on otherwise 
	it will use this*/
function faq_expand(selectedElement){
	var self = selectedElement;	
	var child = jQuery(self).parent().parent().children('div');
	var other = jQuery('div.faq div');
	var mainheight = jQuery('#maincol').height();
	var newheight = mainheight + jQuery(child).height() + 20;
	var closeheight = mainheight - jQuery(child).height() - 20;
	if (jQuery(child).css('display') == 'none') {
		jQuery(other).slideUp('fast');
		jQuery(child).slideDown('fast');
		jQuery('#maincol').css('height',newheight);
		jQuery('#rightcol').css('height',newheight+80);
	} else {
		jQuery(child).slideUp('fast');
		jQuery('#maincol').css('height',closeheight);
		jQuery('#rightcol').css('height',closeheight+80);
	}
	return false;
}

function dumpProps(obj, parent) {
   // Go through all the properties of the passed-in object
   for (var i in obj) {
      // if a parent (2nd parameter) was passed in, then use that to
      // build the message. Message includes i (the object's property name)
      // then the object's property value on a new line
      if (parent) { var msg = parent + "." + i + "\n" + obj[i]; } else { var msg = i + "\n" + obj[i]; }
      // Display the message. If the user clicks "OK", then continue. If they
      // click "CANCEL" then quit this level of recursion
      if (!confirm(msg)) { return; }
      // If this property (i) is an object, then recursively process the object
      if (typeof obj[i] == "object") {
         if (parent) { dumpProps(obj[i], parent + "." + i); } else { dumpProps(obj[i], i); }
      }
   }
}

jQuery(document).ready(function() {
	var main = jQuery('#maincol').height();
	var right = jQuery('#rightcol').height();
	if (main > right) { jQuery('#rightcol').css('height',main+100); }
	if (right > main) { jQuery('#maincol').css('height',right-60); }
	
	jQuery(function() {
		var zIndexNumber = 1000;
		jQuery('*').each(function() {
			if (jQuery(this).is('div')){
				jQuery(this).css('zIndex', zIndexNumber);
			} else if (jQuery(this).is('ul')){
				jQuery(this).css('zIndex', zIndexNumber);
			} else if (jQuery(this).is('li')){
				jQuery(this).css('zIndex', zIndexNumber);
			}
			zIndexNumber -= 10;
		});
	});
//	jQuery('#topmenu > li:first').css('zIndex',0);
	jQuery('#topmenu').children().not('.submenu').css('zIndex',0);
var t; //for timeouts

	jQuery('#topmenu li a').mouseover(function() {
			var self = this;
			var dropdown = jQuery(self).next();
			jQuery(dropdown).fadeIn('fast');
	}).mouseout(function() {
			var self = this;
			var dropdown = jQuery(self).next();
			t=setTimeout(function() { unHover(dropdown); },100);
	});
	jQuery('#topmenu li ul').mouseover(function() {
			clearTimeout(t);
	}).mouseout(function() {
			var self = this;
			t=setTimeout(function() { unHover(self); },100);
	});
	function unHover(h) {
	  	jQuery(h).fadeOut('fast');
	}
	
	jQuery('div.faq h3 a').click(function(){
		var self = this;
		faq_expand(self);
	});
	
	jQuery('p.question a').click(function() {
		var self = this;
		var answer = jQuery(this).parent().next();
		var newheight = jQuery('#maincol').height() + jQuery(answer).height();
		var oldheight = jQuery('#maincol').height() - jQuery(answer).height();
		var oldright = jQuery('#rightcol').height() - jQuery(answer).height();
		if (jQuery(answer).css('display') == 'none') {
			jQuery(answer).slideDown('fast');
			jQuery('#maincol').css('height',newheight);
			jQuery('#rightcol').css('height',newheight+80);
		} else {
			jQuery(answer).slideUp('fast');
			jQuery('#maincol').css('height',oldheight);
			jQuery('#rightcol').css('height',oldright);
		}
		return false;
	});
});

