/*
Code for collapsable objects on a page. The element that
will be clicked to collapse another should have the class
collapseHead and the collapsible element should have the 
class collapseBody.

Sample link for collapseHead:

<a class="collapseHead" href="javascript:void()">
	Collapse this!</a>
	
href="javascript:void()" attribute makes link clickable
without going anywhere.

Make sure to include the following to lines of HTML in the
page that you want to use this on:

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="collapse.js"></script>

If jquery.js is already included on your page, just link
the collapse.js file.
*/

$(document).ready(function()
{
	var prevElement = null;
	var prevElementIndex = -1;	
	// hide the all of the element with class collapseBody
	$(".collapseBody").hide();
	// toggle the componenet with class collapseBody
	$(".collapseHead").click(function()
	{
		// collapse prev so long as it's not null and not the one just clicked
		if ((prevElementIndex != -1) &&
			(prevElementIndex != $(this).next(".collapseBody").index()))
		{
			prevElement.slideUp(300);
		}
		// reassign prev
		prevElement = $(this).next(".collapseBody");
		prevElementIndex = $(this).next(".collapseBody").index();
		// timing in milliseconds
		// hide all elements then toggle one
		$(this).next(".collapseBody").slideToggle(300);
	});
});

/*
JavaScript for drop down menu effects.
Credit: http://javascript-array.com/scripts/jquery_simple_drop_down_menu/
*/

var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;

function jsddm_open()
{  jsddm_canceltimer();
   jsddm_close();
   ddmenuitem = $(this).find('ul').css('visibility', 'visible');}

function jsddm_close()
{  if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

function jsddm_timer()
{  closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{  if(closetimer)
   {  window.clearTimeout(closetimer);
      closetimer = null;}}

$(document).ready(function()
{  $('#jsddm > li').bind('mouseover', jsddm_open)
   $('#jsddm > li').bind('mouseout',  jsddm_timer)});

document.onclick = jsddm_close;

// Original:  William Humphreys (billy@technical-solutions.co.uk) 

// This script and many more are available free online at 
// The JavaScript Source!! http://javascript.internet.com 

function initCaps(data) {
	var index;
	var tmpStr;
	var tmpChar;
	var preString;
	var postString;
	var strlen;
	tmpStr = data.toLowerCase();
	strLen = tmpStr.length;
	if (strLen > 0)  {
		for (index = 0; index < strLen; index++)  {
			if (index == 0)  {
				tmpChar = tmpStr.substring(0,1).toUpperCase();
				postString = tmpStr.substring(1,strLen);
				tmpStr = tmpChar + postString;
			}
			else {
				tmpChar = tmpStr.substring(index, index+1);
				if (tmpChar == " " && index < (strLen-1))  {
					tmpChar = tmpStr.substring(index+1, index+2).toUpperCase();
					preString = tmpStr.substring(0, index+1);
					postString = tmpStr.substring(index+2,strLen);
					tmpStr = preString + tmpChar + postString;
				}
			}
		}
	}
	return tmpStr;
}

