﻿/// <reference path="jquery-vsdoc.js" />
//*************************************************************************************
// File     : rwvi_functions.js
// Requires : jquery.js (version 1.3.2+), braingnat.js (version 0.4.0+)
// Author   : Kyle Weems (ksw)
// Origin   : mindfly.com
// Created  : November 11, 2009
// Modified : December 06, 2010
//*************************************************************************************

$(document).ready(function() {
    galleryThumbs();
    footerPush();
});

function galleryThumbs() {
    // Set the big image to be the first image in the thumbnail gallery.
    if ($("#bigImage").html() != null) {
        $('#bigImage').attr('src', $('.gallery img:eq(0)').attr('src')).attr('alt', $('.gallery img:eq(0)').attr('alt'));
        $('#imageText').html($('.gallery img:eq(0)').attr('alt'));
    }
    // Bind the click event of the thumbnails to show that image as the big image.
    $('.gallery a').bind('click', function() {
        $('.gallery .selected').removeClass('selected');
        $(this).addClass('selected');
        $('#bigImage').attr('src', $(this).attr('href'));
        $('#bigImage').attr('alt', $(this).attr('title'));
        $('#imageText').html($(this).attr('title'));
        return false;
    });
}

function footerPush() {
    // 1 Get window height
    var h = $(window).height();
    var b = $('body');
    var m = $('#menu');
    var hd = $('#header');
    var c = $('#content');
    var p = $('#primary');
    var s = $('#secondary');
    var t = $('#tertiary');
    var f = $('#footer');
    // 2 subtract body vertical padding
    h -= (b.css('padding-top').substring(0, b.css('padding-top').length - 2) * 1);
    h -= (b.css('padding-bottom').substring(0, b.css('padding-bottom').length - 2) * 1);
    h -= (b.css('margin-top').substring(0, b.css('margin-top').length - 2) * 1);
    h -= (b.css('margin-bottom').substring(0, b.css('margin-bottom').length - 2) * 1);
    // 3 subtract menu height
    h -= m.height();
    h -= (m.css('padding-top').substring(0,m.css('padding-top').length - 2) * 1);
    h -= (m.css('padding-bottom').substring(0, m.css('padding-bottom').length - 2) * 1);
    h -= (m.css('margin-top').substring(0, m.css('margin-top').length - 2) * 1);
    h -= (m.css('margin-bottom').substring(0, m.css('margin-bottom').length - 2) * 1);
    // 4 subtract header height
    h -= hd.height();
    h -= (hd.css('padding-top').substring(0, hd.css('padding-top').length - 2) * 1);
    h -= (hd.css('padding-bottom').substring(0, hd.css('padding-bottom').length - 2) * 1);
    h -= (hd.css('margin-top').substring(0, hd.css('margin-top').length - 2) * 1);
    h -= (hd.css('margin-bottom').substring(0, hd.css('margin-bottom').length - 2) * 1);
    // 5 set content height
    if (c.height() < h) {
        c.css("height", h + "px");
        // 6 fix margin-top for footer
        var ph = p.height();
        ph += (p.css('padding-top').substring(0, p.css('padding-top').length - 2) * 1);
        ph += (p.css('padding-bottom').substring(0, p.css('padding-bottom').length - 2) * 1);
        ph += (p.css('margin-top').substring(0, p.css('margin-top').length - 2) * 1);
        ph += (p.css('margin-bottom').substring(0, p.css('margin-bottom').length - 2) * 1);
        var d = ph;
        if (b.hasClass("twoCol") || b.hasClass("home")) {
            var sh = s.height();
            sh += (s.css('padding-top').substring(0, s.css('padding-top').length - 2) * 1);
            sh += (s.css('padding-bottom').substring(0, s.css('padding-bottom').length - 2) * 1);
            sh += (s.css('margin-top').substring(0, s.css('margin-top').length - 2) * 1);
            sh += (s.css('margin-bottom').substring(0, s.css('margin-bottom').length - 2) * 1);
            if (sh > d) {
                d = sh;
            }
        }
        if (b.hasClass("home")) {
            var th = t.height();
            th += (t.css('padding-top').substring(0, t.css('padding-top').length - 2) * 1);
            th += (t.css('padding-bottom').substring(0, t.css('padding-bottom').length - 2) * 1);
            th += (t.css('margin-top').substring(0, t.css('margin-top').length - 2) * 1);
            th += (t.css('margin-bottom').substring(0, t.css('margin-bottom').length - 2) * 1);
            d += th;
        }
        d += f.height();
        d += (f.css('margin-bottom').substring(0, f.css('margin-top').length - 2) * 1);
        if (d < c.height()) {
            f.css('margin-top', (c.height() - d) + 'px');
        }
        
    }
}
