/* custom functions */

function hide(id) {
  document.getElementById(id).style.display = 'none';
}

function show(id) {
  document.getElementById(id).style.display = 'block';
}

function toggleDisplay(sId){
  var me=document.getElementById(sId);
  if (me.style.display=="none" || me.style.display==""){
     me.style.display="block";
  }
  else {
     me.style.display="none";
  }
}

function showOnlyOne(id, number, thechosenone) {
  for (i=1; i<=number; i++) { 
    if (i == thechosenone && document.getElementById(id+i).style.display != 'block') {
      document.getElementById(id+i).style.display = 'block';
    }
    else {
      document.getElementById(id+i).style.display = 'none';
    }
  }
}

function slideshow(id, number, time) {
  for (i=1; i<=number; i++) {
    document.getElementById(id+i).style.display = "none";
  }  
  k++;
  if (k > number) { k = 1; }
  document.getElementById(id+k).style.display = "block";
}

/* custom functions end */

/* Simple JQuery menu.

1: each menu MUST have an ID set. It doesn't matter what this ID is as long as it's there.
2: each menu MUST have a class 'menu' set. If the menu doesn't have this, the JS won't make it dynamic

Optional extra classnames:

noaccordion : no accordion functionality
collapsible : menu works like an accordion but can be fully collapsed
expand      : any ul with this class will be expanded at page load

<ul id="menu1" class="menu [optional class] [optional class]">
<li><a href="#">Sub menu heading</a>
<ul>
<li><a href="http://site.com/">Link</a></li>
<li><a href="http://site.com/">Link</a></li>
<li><a href="http://site.com/">Link</a></li>
...
...
</ul>
<li><a href="#">Sub menu heading</a>
<ul>
<li><a href="http://site.com/">Link</a></li>
<li><a href="http://site.com/">Link</a></li>
<li><a href="http://site.com/">Link</a></li>
...
...
</ul>
...
...
</ul>

*/

function initMenus() {
	$('ul.menu ul').hide();
  $.each($('ul.menu'), function(){
    $('ul.expand').show();
	});
	$('ul.menu li a').click(
		function() {
			var checkElement = $(this).next();
			var parent = this.parentNode.parentNode.id;

			if($('#' + parent).hasClass('noaccordion')) {
				$(this).next().slideToggle('normal');				
			}
			if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
				if($('#' + parent).hasClass('collapsible')) {
					$('#' + parent + ' ul:visible').slideUp('normal');
				}
				return false;
			}
			if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
				$('#' + parent + ' ul:visible').slideUp('normal');
				checkElement.slideDown('normal');
				return false;
			}
		}
	);
}
$(document).ready(function() {initMenus();});

/* simple jQuery Accordion Menu end */