/* Accordion menus */

function initMenus() {
	$('#subnav ul.accordionmenu ul').hide();
	$.each($('#subnav ul.accordionmenu'), function(){
		$('#' + this.id + ' ul.open').show();
	});
	$('#subnav ul.accordionmenu li a').click(
		function() {
			try {
				var checkElement = $(this).next();
				var parent = this.parentNode.parentNode.id;
	
				if(checkElement && $('#subnav #' + parent).hasClass('noaccordion')) {
					$(this).next().slideToggle('normal');
					return false;
				}
		
				if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
					if($('#subnav #' + parent).hasClass('collapsible')) {
						$('#subnav #' + parent + ' ul:visible').slideUp('normal');
					}
					return false;
				}
				
				else if((checkElement.is('ul')) && (checkElement.not(':visible'))) {
					$('#subnav #' + parent + ' ul').slideUp('normal');
					checkElement.slideDown('normal');
					return false;
				}
			}
		catch(e)
		{
		/* Addressing problem with clicking on non-accordion-menu nav links in IE */
			return true;
		}

		}
	);


}


function rotateImages(position) {
var image_count;
var old_image = 0;
var current_image = 0;

var frame_width = 611; /* horizontal width */
if(position == "vertical") {frame_width = "407";}
var neg_frame_width = 0 - frame_width;

/* Make sure container is proper height */
var mydiv = document.getElementById("portimagewrap");
var mydivholder = mydiv.getElementsByTagName("img");

var maxHeight = 0;
var i = 0;

while(i < mydivholder.length)
{
if(maxHeight < mydivholder[i].offsetHeight) {
	maxHeight = mydivholder[i].offsetHeight;
}

i++;
}

document.getElementById("portimagewrap").style.height = maxHeight + "px";



  image_count = $("div#portimagewrap div").size();


  $("div.portimage:eq("+current_image+")").css('left','0');
  
  $('#portnav a.rightarrow').click(function() {
    image_rotate();
    return false;
  });
  $('#portnav a.leftarrow').click(function() {
    image_rotate_back();
    return false;
  });



function image_rotate() {
  current_image = (old_image + 1) % image_count; //remainder will always equal old_image until it reaches image_count - at which point it becomes zero.
  $("div.portimage:eq(" + old_image + ")").animate({left: neg_frame_width},"slow", function() {
    $(this).css('left','-9999em');
    });
  $("div.portimage:eq(" + current_image + ")").show().animate({right: 0},"slow", function() {
    $(this).css('left','0');
    });  
  old_image = current_image;
}

function image_rotate_back() {

	current_image = (old_image - 1) % image_count; //remainder will always equal old_image until it reaches image_count - at which point it becomes zero.

	if(current_image < 0) {current_image = (image_count - 1);} /* loop */

  $("div.portimage:eq(" + old_image + ")").animate({left: frame_width},"slow", function() {
    $(this).css('left','-9999em');
    });
  $("div.portimage:eq(" + current_image + ")").show().animate({left: 0},"slow", function() {
    $(this).css('left','0');
    });  
  old_image = current_image;
}



}




function rotateHomepageImages() {
var image_count;
var list_count;
var old_image = 0;
var current_image = 0;
var old_desc = 0;
var current_desc = 0;

var frame_width = 815; /* horizontal width */
var neg_frame_width = 0 - frame_width;

/* Make sure container is proper height */
var mydiv = document.getElementById("featurewrap");
var mydivholder = mydiv.getElementsByTagName("img");

var maxHeight = 0;
var i = 0;

while(i < mydivholder.length)
{
if(maxHeight < mydivholder[i].offsetHeight) {
	maxHeight = mydivholder[i].offsetHeight;
}

i++;
}

document.getElementById("featurewrap").style.height = maxHeight + "px";



  image_count = $("div#featurewrap div.feature").size();


  $("div#featurewrap div.feature:eq("+current_image+")").css('left','0');
  $("div#descriptionwrap div.description:eq("+current_image+")").css('left','0');
  
  
  list_count = $("ul#controls li").size();
  
  list_count = list_count + 1;
  
 

  
$('#controls li a').click(function() {
	var parentId = $(this).parent().get(0).id;
	var parentIdNum = parentId.substr(4);
	
	  var i = 1;
	  while(i < list_count) {
	  $("ul#controls li#item"+i).removeClass('current');
	  i++;
	  }
	
	$("#controls li#"+parentId).addClass('current');
	
	image_rotate(parentIdNum);
	description_rotate(parentIdNum);
	
	return false;

});
  


function image_rotate(new_image) {
new_image = new_image - 1;

  $("div.feature:eq(" + old_image + ")").animate({left: neg_frame_width},"slow", function() {
    $(this).css('left','-9999em');
    });
  $("div.feature:eq(" + new_image + ")").show().animate({right: 0},"slow", function() {
    $(this).css('left','0');
    });  
 old_image = new_image;
}

function description_rotate(new_desc) {
new_desc = new_desc - 1;

  $("div#descriptionwrap div.description:eq(" + old_desc + ")").animate({left: -194},"slow", function() {
    $(this).css('left','-9999em');
    });
  $("div#descriptionwrap div.description:eq(" + new_desc + ")").show().animate({right: 0},"slow", function() {
    $(this).css('left','0');
    });  
 old_desc = new_desc;
}




} /* end rotateHomepageImages() */




function runH() {
$("div#animation").css('display','block');

} /* end runH() */




/* Homepage items */

function showMe(arg) {
	document.getElementById(arg).style.display = "block";
	document.getElementById(arg).style.visibility = "visible";
}

function hideMe(arg) {
	document.getElementById(arg).style.display = "none";
	document.getElementById(arg).style.visibility = "hidden";
}



