/**
 * Equal Heights Plugin
 * Equalize the heights of elements. Great for columns or any elements
 * that need to be the same size (floats, etc).
 *
 * Version 1.0
 * Updated 12/10/2008
 *
 * Copyright (c) 2008 Rob Glazebrook (cssnewbie.com)
 *
 * Usage: $(object).equalHeights([minHeight], [maxHeight]);
 *
 * Example 1: $(".cols").equalHeights(); Sets all columns to the same height.
 * Example 2: $(".cols").equalHeights(400); Sets all cols to at least 400px tall.
 * Example 3: $(".cols").equalHeights(100,300); Cols are at least 100 but no more
 * than 300 pixels tall. Elements with too much content will gain a scrollbar.
 *
 */

(function($) {
	$.fn.equalHeights = function(minHeight, maxHeight) {
		tallest = (minHeight) ? minHeight : 0;
		this.each(function() {
			if($(this).height() > tallest) {
				tallest = $(this).height();
			}
		});
		if((maxHeight) && tallest > maxHeight) tallest = maxHeight;
		return this.each(function() {
			$(this).height(tallest).css("overflow","visible");
		});
	}
})(jQuery);


// Slide Show
function ssSlide() {
    var $active = $('#ssSlide img.active');

    if ( $active.length == 0 ) $active = $('#ssSlide img:last');

    var $next =  $active.next().length ? $active.next()
        : $('#ssSlide img:first');


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
            if ($('#ssSlide img.active').attr("alt") == "") {$("#ssCaption").html("&nbsp;");$("#ssCaption").slideUp("slow")}
            else {$("#ssCaption").text($('#ssSlide img.active').attr("alt"));$("#ssCaption").slideDown("slow")}
        });
}

// Start Slide Show
$(function() {
  if ($("#ssCaption").is(":hidden")) {
    $("#ssCaption").text($('#ssSlide img.active').attr("alt"))
    if ($('#ssSlide img.active').attr("alt") != "") {$("#ssCaption").slideDown("slow");}
  }
    setInterval( "ssSlide()", 5000 );
});

// Alternate background colors // set equal coumn heights // hide / reveal items.
$(document).ready(function(){
  $(".alternate:odd").addClass("alternate-odd");
  $(".alternate:even").addClass("alternate-even");
  $(".revealTarget").addClass("hide");
//########### REMOVE IF USING RESIZING COLUMNS ##########
  $(".column").equalHeights();
//########### REMOVE IF USING RESIZING COLUMNS ##########

  // Show / Hide gallery items.
  $("a.revealLink").click(function(){
    var $myTarget = $(this).attr("href");

    $($myTarget).children(".galleryBox").children("a").children(".replaceThumb").each(function(){
      $(this).attr("src",$(this).attr("title"));
    });

    if ($($myTarget).hasClass("hide")){$($myTarget).removeClass("hide");}
    else {$($myTarget).addClass("hide");}
//########### REMOVE IF USING RESIZING COLUMNS ##########
    $(".column").equalHeights();
//########### REMOVE IF USING RESIZING COLUMNS ##########
  });

  // Show all / Used in the FAQ page.
  $("a.revealer").click(function(){
    var $count = 0;
    $(".hide").each(function(){
      $count = ($count + 1);
    });
    if ($count > 0){
      $("a.revealer").text("Colapse All");
      $(".hide").removeClass("hide");
    }
    else {
      $("a.revealer").text("Expand All");
      $(".revealTarget").addClass("hide");
    }
//########### REMOVE IF USING RESIZING COLUMNS ##########
    $(".column").equalHeights();
//########### REMOVE IF USING RESIZING COLUMNS ##########
  });
});