var currentItem = '';
var currentSubItem = '';

var currentHover = '';

var calculateViewport = function(){
    var windowHeight = $(window).height();

    //calculate text body
    var headerHeight = 158;
    var scrollerHeight = 175;
    var padding = 29;
    var footerHeight = 120;
    var copyrightHeight = 25;

    var whitespace = 0;

    var total = headerHeight + scrollerHeight + padding + footerHeight + copyrightHeight + whitespace;
    //var total = 380 + footerHeight + copyrightHeight + whitespace;

    var textHeight = windowHeight - total;

    //if(windowHeight >= 600){
        var txt = $('#text_container');
        
        var map = $('#map_canvas');
        if(map.length > 0){
            textHeight += scrollerHeight;
            txt.height(textHeight)
            map.height(textHeight - 15);
        }
        else{
            txt.height(textHeight);
        }
    //}

    //Calculate height of leftcolumn
    //var docHeight = $(document).height();
    //if(docHeight > windowHeight) { windowHeight = docHeight; }

    var negate = 0;
    if($.browser.mozilla){negate = 2;}
    if($.browser.msie){
        var contentWidth = 1054;
        var windowWidth = $(window).width();

        var left = (windowWidth - contentWidth) / 2;

        $('#leftcolumn').css('left', left);
    }
    $('#leftcolumn').height(windowHeight - negate);
};

$(document).ready(function(){
    //if($.browser.ie){$('#text_container').css('overflow-y:scroll;');}


    $("#contact_form").slideLock({
        labelText: "",
        noteText: "Proves you are human, prevents SPAM",
        lockText: "Locked",
        unlockText: "Unlocked",
        iconURL: baseurl  + "assets/scripts/chrome/arrow_right.png",
        inputID: "sliderInput",
        onCSS: "#333",
        offCSS: "#aaa",
        inputValue: 1,
        saltValue: 9,
        checkValue: 10,
        submitID: ".submit"
    });

    $('.showtip, td.single_session, td.dual_session').qtip({
        position: {
          corner: {
             tooltip: 'bottomMiddle', // Use the corner...
             target: 'topMiddle' // ...and opposite corner
          }
       },
       style: {
           name: 'dark',
           tip: true}
    });

    $('.contentbox').listalign({listselector: 'ul.lists', spacing: 4});

    calculateViewport();

    $(window).resize(function(){
        calculateViewport();
    });

    currentItem = $('a.mm_selected').attr('href');
    currentSubItem = $('a.sm_selected').attr('href');

    //Sub menu mouse actions
    $('a.sm').live('mouseover mouseout', function(event){
        var current = $(this);
        
        if(event.type == 'mouseover'){
            current.addClass('sm_hover');
        }
        else{
            $('.sm_hover').removeClass('sm_hover');
        }
    });


    //Main menu mouse actions
    $('a.mm').live('mouseover mouseout', function(event){
        var mmcurrent = $(this);

        if(event.type == 'mouseover'){
            if(!mmcurrent.hasClass('sm_selected')){
                $('.sm_active').removeClass('sm_active');
                $(mmcurrent.attr('rel')).addClass('sm_active');

                $('.mm_selected').removeClass('mm_selected');
                $('.mm_selected_text').removeClass('mm_selected_text');

                var parents = mmcurrent.parents('.mm');
                var parent_text = mmcurrent.parents('.mm_text');

                parents.addClass('mm_selected');
                parent_text.addClass('mm_selected_text');

                mmcurrent.addClass('mm_selected');
            }
        }
    });

    //Go home
    $('.logo_image').click(function(){document.location.href = $('.logo_image').attr('rel');});

    $('#scroller').slideShow({
        pictures: pics,
        startIndex: 1,
        speed: 'slow'
    });

    $('body').css('visibility', 'visible');
});
