/// <reference path="jquery-vsdoc.js" />
//*************************************************************************************
// File     : thiswin_functions.js
// Requires : jquery.js (version 1.4.0+), braingnat.js (version 0.4.0)
// Author   : Kyle Weems (ksw)
// Origin   : mindfly.com
// Created  : Feb 12, 2010
// Modified : Jun 21, 2010
//*************************************************************************************

$(document).ready(function() {
    navShutter();
    evenThingsOut();
    hideEmptySplashText();
    // homeSlideshow();
    BrainGnat.slideshow.panelSlide("#panels li", "#controls li", 606, 0);
    arrangeMenuZ();
    governmentButtons();
    // $(document).bind("contextmenu",function(e){return false;});
});

function navShutter() {
    $('.shutter .open.slide + ul').slideDown('1000');
    $('.shutter .open.already + ul').css({ display: 'block' });
    /* $('.shutter > li > a').click(function() {
        if ($('.shutter .pending').length < 1) {
            $(this).addClass('pending');

            $('.shutter .open + ul').slideUp('1000', function() {
                $('.shutter .open').removeClass('open');
                $('.shutter .pending').addClass('open');
                $('.shutter .pending').removeClass('pending');
                $('.shutter .open + ul').slideDown('1000');
            });
        }
        return false;
    }); */
}

// This function ensures that the content is tall enough to put footer at bottom of browser window,
// and that the columns inside the content are even.
function evenThingsOut() {
    // #1 ensure content is proper height
    var difference = $(window).height() - ($('#header').height() + $('#footer').outerHeight() + 50);
    if ($('#content').height() < difference) {
        $('#content').css('min-height', difference + 'px');
    }
    // #2 ensure columns are even and fit content
    var colHeight = $('#content').height() - ($('#splash').outerHeight() + 20);
    $('#primary').css('min-height', colHeight + 'px');
    $('#secondary').css('min-height', colHeight + 'px');
    $('#main').css('min-height', colHeight + 'px');
    $('#primary .aside').css('min-height', colHeight + 'px');
}

// Hides the splash textbox if it's empty (mostly for IE's sake)
function hideEmptySplashText() {
    if ($('.section.text').html() == "" || $('.section.text').html() == " ") {
        $('.section.text').css('display', 'none');
    }
}

function homeSlideshow() {
    BrainGnat.slideshow.ajaxLoadCrossfade("/Controls/imageList/imageList.aspx?dir=/Uploads/images/imagerotator/", "#wrapper", "img", 5000, 1000, false);
}

function arrangeMenuZ() {
    for (i = $('#header .nav.main > li').length - 1; i > -1; i--) {
        $('#header .nav.main > li:eq(' + i + ')').css('z-index', ($('#header .nav.main > li').length - i));
    }
}

function governmentButtons() {
    $('.govtAgree').click(function() { eval($(this).children('a').attr('href').split("javascript:")[1]); });
    $('.govtDisagree').click(function() { $('.disagree').slideDown(); });
    $('.disagree button').click(function() { $('.disagree').slideUp(); });
    $('.notice button').click(function() { $('.notice').slideUp(); });
    $('.notice .readTerms').click(function() { $('.notice').slideUp(); return false; });
    
}

