﻿//Compass Jobs Fair Jquery


$(document).ready(function () {

    //Profile Scroller Carousel
    function mycarousel_initCallback(carousel) {
        // Disable autoscrolling if the user clicks the prev or next button.
        carousel.buttonNext.bind('click', function () {
            carousel.startAuto(0);
        });

        carousel.buttonPrev.bind('click', function () {
            carousel.startAuto(0);
        });

        // Pause autoscrolling if the user moves with the cursor over the clip.
        carousel.clip.hover(function () {
            carousel.stopAuto();
        }, function () {
            carousel.startAuto();
        });
    };

    if ($('#mycarousel').exists()) {
        var highnum = $('#mycarousel li').length;
        var randomnumber = $.randomBetween(1, highnum);
        $('#mycarousel').jcarousel({
            auto: 4,
            scroll: 3,
            wrap: 'circular',
            initCallback: mycarousel_initCallback,
            start: randomnumber
        });
    }

  

    //Vertically Align items in the Profile Scroller
    (function ($) {
        // VERTICALLY ALIGN FUNCTION
        $.fn.vAlign = function () {
            return this.each(function (i) {
                var ah = $(this).height();
                var ph = $(this).parent().height();
                var mh = (ph - ah) / 2;
                $(this).css('padding-top', mh);
            });
        };
    })(jQuery);

    $('#profileScroller a').vAlign();

    //   **********************************************************************  //

    // Make Footer Links same height
    var a = $("#footerLinks"), b = $("#column3c");
    a.height() < b.height() ? a.height(b.height()) : b.height(a.height());

    //   **********************************************************************  //

    //Accordion boxes in Seminars
    $(".clickArea").click(function (event) {

        //Search for all visible accordion box contents then slide them up and on callback add the box closed class
        $('.accordion .contentSurround:visible').slideUp('fast', function () { $(this).parent("div.boxed").toggleClass("boxclosed"); });

        if ($(this).parent("div.boxed").hasClass("boxclosed")) {
            $(this).parent("div.boxed").toggleClass("boxclosed");
            $(this).next().slideDown('fast');
            return false;
        };

    });

    //   **********************************************************************  //

    //jQuery hover menu
    //call the jQuery Hover Over and Out
    $('.hover').hover(over, out);
    //Tell the browser to change the background when hovered over
    function over(event) {
        $('#hovermenu', this).css("display", "block");
    }
    //tell the browser to change the background to nothing when 
    //going outside the object area
    function out(event) {
        $('#hovermenu', this).css("display", "none");
    }

    //   **********************************************************************  //

    /* IF TABBED MODULE - Set listeners*/
    if ($(".TabbedModule").exists()) {
        $(".tabMenu a").click(function (brrap) {
            brrap.preventDefault();
            clickHref = $(this).attr('href');
            actionId = clickHref.substring(1);
            activateTabbedContent($(this).parents(".TabbedModule"), actionId);
        });
    }

});

function activateTabbedContent(tabbedModule, actionId) {
    tabbedModule.each(function () {
        // Do the Tabs
        $(this).find('.tabMenu a').each(function () {
            // resetTabs
            $(this).removeClass('active');
            // set tab
            if ($(this).attr('href') == ('#' + actionId)) {
                $(this).addClass('active');
            }
        });

        // DO the Content
        $(this).find('.informationContainer .information').each(function () {
            // resetContent
            $(this).removeClass('active');
            // set tab
            if ($(this).attr('id') == actionId) {
                $(this).addClass('active');
            }
        });

        // If taller than one line make current last in list
//        if ($(this).find('.tabMenu').css('height') > $(this).find('.tabMenu li').css('height')) {
//            activeTab = $(this).find('.tabMenu a.active').parent('li');
//            $(this).find('.tabMenu a.active').parent('li').remove();
//            $(this).find('.tabMenu').append(activeTab);
//            $(this).find('.tabMenu div.terminus').remove();
//            $(this).find('.tabMenu').append('<div class="terminus"> </div>');
//        }


    });
}

//   **********************************************************************  //

// Product tab functionality - Home Page
function productTabs(clicked) {

    // Product Tabs 
    var currentSection = clicked + 'Content';
    var currentTab = clicked + 'Tab';

    // Hide all content divs and reset Tab styling
    $(".contentOpen").each(function () {
        $(this).attr('class', 'contentClose');
    });
    $(".tabCurrent").each(function () {
        $(this).attr('class', 'tab');
    });

    // Change current Tab and Show current Tab content
    $("#" + currentSection).attr('class', 'contentOpen');
    $("#" + currentTab).attr('class', 'tabCurrent');


    //   **********************************************************************  //

    // Adjust Columns
    $("#" + currentSection + " .cols2").each(function () {
        matchHeightCol($(this).find(".listItem"), '2');
    });
    $("#" + currentSection + " .cols3").each(function () {
        matchHeightCol($(this).find(".listItem"), '3');
    });

}

//   **********************************************************************  //


// Random number generator for Carousel
    jQuery.extend({
        random: function (X) {
            return Math.floor(X * (Math.random() % 1));
        },
        randomBetween: function (MinV, MaxV) {
            return MinV + jQuery.random(MaxV - MinV + 1);
        }
    });

    //   **********************************************************************  //
