//Resizes ContentBoxes.  Just add "ResizeContent" as another class on to all of the boxes that should be the same height.
function fResizeContent() {
   var intHeight = 0;
  
  //Loop through each element to figure out which is the tallest
   $(".ResizeContent").each(function(i) {
      if (intHeight < $(this).height())
         intHeight = $(this).height();
   });
   
   //Set height to each element
   $(".ResizeContent").height(intHeight);
}


//Formats content divs to show/hide nested content
//<div class='ExpandContent'>
//<div>[TITLE]</div>
//<div>[CONTENT]</div>
//</div>
//Add the class of ExpandOpen to default to the div being opened on load
function fExpandContent() {
   //Add classes to the child divs
   $(".ExpandContent div:nth-child(1)").addClass("ExpandTitle");
   $(".ExpandContent div:nth-child(2)").addClass("ExpandBody");
   
   //Hide the body content
   $(".ExpandBody").hide();
   
   //Create Show/Hide buttons on title bar
   $(".ExpandTitle").each(function() {
      $(this).html("<div class='Left'></div>" + $(this).html() + "<div class='Right'></div>");
   });
   
   //Add click events for showing and hiding content
   $(".ExpandTitle").toggle(function() {
      $(this).parent().find(".ExpandBody").animate({ opacity: 'toggle', height: 'toggle' }, "slow");
      $(this).parent().find(".ExpandTitle div").css("backgroundPosition", "top");
   }, function() {
      $(this).parent().find(".ExpandBody").animate({ opacity: 'toggle', height: 'toggle' }, "fast");
      $(this).parent().find(".ExpandTitle div").css("backgroundPosition", "bottom");
   });
   
   //Open any neccessary divs by default
   $(".ExpandOpen").find(".ExpandTitle").click();
   
   //Show expanded content areas
   $(".ExpandContent").show();
}


//Sets up the neccessary logic for the slideshow
//Must declare some variables outside function call
//   var curButton, curTimer, numItems;
//And create a div containing the images
//   <div id='slider'>
//   <a href='[LINK]'><img src='[IMG]' /></a>
//   </div>
function sCreateSlideshow() {
   //Set default values
   curButton = 1;
   numItems = 0;
   
   //Add id for each slide
   $("#Slider").find("img").each(function() {
      numItems++;
      $(this).attr("id","SliderLink" + numItems);
   });
   
   //Create slide navigation
   $("#Slider").append("<div id='SliderNav'></div>");
   for(i=1;i<=numItems;i++) {
      $("#SliderNav").append("<div id='SliderButton" + i + "' class='SliderButton'>" + i + "</div>");
   }
   $("#SliderNav").css("marginLeft", ($("#Slider").width() - $("#SliderNav").width()) / 2); //Center Nav
   $(".SliderButton").click(function() {
      ChangeSlide($(this).html());
   });
   
   //Start the slideshow
   ChangeSlide(1);
}

//Helper function for sCreateSlideshow
function ChangeSlide(iButton) {
   //Get correct button to be processed
   iButton = parseInt(iButton) ? parseInt(iButton) : 0;
   curButton = iButton < numItems ? iButton : 0;
   
   //Fade out all slides to make sure none are showing, then fade in the current one
   $("#Slider").find("img").each(function() {
      $(this).fadeOut(200);
   });
   $('#SliderLink' + iButton).fadeIn(1000);
   
   //Change navigation to show currently selected slide.
   $(".SliderButton").removeClass("SliderButtonOn");
   $("#SliderButton" + iButton).addClass("SliderButtonOn");
   
   //Start timer to show next slide
   clearTimeout(curTimer);
   curTimer = setTimeout("ChangeSlide(" + (curButton + 1) + ");", 5000);
}

