﻿//*************************************************************************************
// File     : braingnat.js
// Version  : 0.0.4
// Requires : jquery.js (version 1.2.6+)
// Author   : Kyle Weems (ksw)
// Origin   : mindfly.com
// Created  : July 29, 2008
// Modified : August 8, 2008
// Purpose  : BrainGnat - A collection of handy solutions and functions for problems and 
//            desired functionality for client websites by Mindfly.
//*************************************************************************************


// setContentHeight
// Called by the page load or resize. If the document is too short to fill the window, it resizes the content to
// ensure that it is tall enough.
function setContentHeight(verticalOffset) {
    if(!verticalOffset) {
        verticalOffset = 0;
    }
	var minContentHeight = $(window).height() - ($('#branding').height() + $('#site_info').height() + verticalOffset);
	if($('#content').height() < minContentHeight) {
		$('#content').height(minContentHeight);
	}
}



// imageCrossfade(elem as string, imageList as Array, optional fadeDuration as Integer, optional fadeSpeed as Integer, optional current as Integer)
//
// This function does a loop of images that fade from one to another. The imageloop goes to a
// wrapper "elem" (usually a div) and an image in the wrapper (these should have the same dimensions
// and overlap one another. The fade loops through all the urls listed in the array ImageList.
function imageCrossfade(elem, imageList, fadeDuration, fadeSpeed, current) {
    var listSize = imageList.length;
    if (!current || current >= listSize) current = 0;
    if (!fadeDuration) fadeDuration = 5000;
    if (!fadeSpeed) fadeSpeed = 1000;
    $(elem + " img").attr("src", imageList[current]);
    if (current == (listSize - 1)) {
        $(elem).css("background", "transparent url(" + imageList[0] + ") no-repeat");
    } else {
        $(elem).css("background", "transparent url(" + imageList[current + 1] + ") no-repeat");
    }
    $(elem + " img").animate({ opacity: "1" }, fadeDuration).animate({ opacity: "0.01" }, fadeSpeed, function() { $(this).css("opacity", "1"); imageCrossfade(elem, imageList, fadeDuration, fadeSpeed, current + 1) });
} // end of function crossfade()


// ajaxLoadCrossfade(file as String, wrapper as String, optional fadeDuration as Integer, optional fadeSpeed as Integer)
//
// Does an ajax call to the file, and then loads the results to the crossfade function in the element 'wrapper'.
function ajaxLoadCrossfade(file, wrapper, fadeDuration, fadeSpeed) {
    if (!fadeDuration) fadeDuration = 5000;
    if (!fadeSpeed) fadeSpeed = 1000;
    $.get(file, function(data) { imageCrossfade(wrapper, data.split(" "), fadeDuration, fadeSpeed); });
}