/* Master Js */

$(function () {
    $('#auctions').click(function () {
        $('.submenu').slideToggle();
    });
});


/* ----- OPEN / CLOSE ICON FOR NAVBAR ----- */

$(document).ready(function () {
    $('.nav-icon3').click(function () {
        $(this).toggleClass('open');
        $(this).css('z-index', 9999);
    });
});

/* ----- END OPEN / CLOSE ICON FOR NAVBAR ----- */


/*----- HIDE MENU ON SCROLL DOWN / REVEAL ON SCROLL UP ----- */

// Hide Header on on scroll down
var didScroll;
var lastScrollTop = 0;
var delta = 5;
var navbarHeight = $('header').outerHeight();

$(window).scroll(function (event) {
    didScroll = true;
});

setInterval(function () {
    if (didScroll) {
        hasScrolled();
        didScroll = false;
    }
}, 250);



function hasScrolled() {
    var st = $(this).scrollTop();

    // Make sure they scroll more than delta
    if (Math.abs(lastScrollTop - st) <= delta)
        return;

    // If they scrolled down and are past the navbar, add class .nav-up.
    // This is necessary so you never see what is "behind" the navbar.
    if (st > lastScrollTop && st > navbarHeight) {
        // Scroll Down
        $('header').removeClass('nav-down').addClass('nav-up');
    } else {
        // Scroll Up
        if (st < lastScrollTop) {
            $('header').removeClass('nav-up').addClass('nav-down');
        }

        // original if statement removed for navbar logic

        /*
                if(st + $(window).height() < $(document).height()) {
                    $('header').removeClass('nav-up').addClass('nav-down');
                }
        */
    }

    lastScrollTop = st;
}





// BACK TO TOP BUTTON
jQuery(document).ready(function ($) {
    // browser window scroll (in pixels) after which the "back to top" link is shown
    var offset = 300,
		//browser window scroll (in pixels) after which the "back to top" link opacity is reduced
		offset_opacity = 1200,
		//duration of the top scrolling animation (in ms)
		scroll_top_duration = 700,
		//grab the "back to top" link
		$back_to_top = $('.cd-top');

    //hide or show the "back to top" link
    $(window).scroll(function () {
        ($(this).scrollTop() > offset) ? $back_to_top.addClass('cd-is-visible') : $back_to_top.removeClass('cd-is-visible cd-fade-out');
        if ($(this).scrollTop() > offset_opacity) {
            $back_to_top.addClass('cd-fade-out');
        }
    });

    //smooth scroll to top
    $back_to_top.on('click', function (event) {
        event.preventDefault();
        $('body,html').animate({
            scrollTop: 0,
        }, scroll_top_duration
		);
    });

});


// ABOUT AND CASE STUDY PAGES --- Module and Employee Profiles module sizing

$(document).ready(function () {

    // Making sure grid col height is the same as the grid col width on homepage 
    //    $(window).bind( 'resize load change', function(){
    //        var lastCol = $('.col:last-child');
    //        
    //        var colWidth = $('.col').width(); 
    //        var colLastWidth = $(lastCol).width();
    //        $('.col').height(colWidth);
    //        $(lastCol).height(colLastWidth);
    //    });
    // Making sure grid col height is the same as the grid col width on homepage 
    $(window).bind('resize load change', function () {
        var smallTile = $('.col.small-tile');

        var colWidth = $('.col.small-tile').width();
        var colLastWidth = $(smallTile).width();
        $('.col').height(colWidth);
        $(smallTile).height(colLastWidth);
    });

    // Making sure Module height is the same as the module width 
    $(window).bind('resize load change', function () {
        var divWidth = $('.modules-container').width();
        $('.modules-container').height(divWidth);

        if (divWidth > 320) {
            $('.modules-container').css("maxWidth", (320));
        } else {
            $('.modules-container').css("maxWidth", (divWidth));
        }
    });

    // Making sure Module height is the same as the module width
    $(window).bind('resize load change', function () {
        var divWidth2 = $('.profile-container').width();
        $('.profile-container, .profile-container2, .profile-container3').height(divWidth2);
    });

    // Making sure INDEX square height is the same as the its width
    $(window).bind('resize load change', function () {
        var squareWidth = $('.profile-container').width();
        $('.small-grid').height(squareWidth);
    });

    // Adding animate.css to homepage central navigation
    $(".col").hover(
        function () {
            $(this).find(".grid_title").toggleClass("pulse animated");
        }
    );

    //    $(".col").hover(
    //      function () {
    //        $(this).find(".grid_title").addClass("bounceIn animated");
    //      }, 
    //      function () {
    //        $(this).find(".grid_title").removeClass("bounceIn animated");
    //      }
    //    );/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i

});

$(document).ready(function () {
    if (/iPhone|iPad|iPod/.test(navigator.userAgent)) {
        $("figure").addClass("isMobileCasestudy");
        $("figcaption").addClass("isMobileFigcaption");
        $("figure span").addClass("isMobileSpan");
        $("figure span").addClass("isMobileSpanContent");
    }
    else if (/Android|webOS|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
        $("figure").addClass("isMobileCasestudy");
        $("figcaption").addClass("isMobileFigcaption2");
        $("figure span").addClass("isMobileSpan");
        $("figure span").addClass("isMobileSpanContent");
    } else {
        $("figure").removeClass("isMobileCasestudy");
        $("figcaption").removeClass("isMobileFigcaption");
        $("figcaption").removeClass("isMobileFigcaption2");
        $("figure span").removeClass("isMobileSpan");
        $("figure span").removeClass("isMobileSpanContent");
    }
});

// JS for Safari browser detection - flexbox css styling
$(document).ready(function () {

    function css_browser_selector(u) {
        var ua = u.toLowerCase(),
            is = function (t) {
                return ua.indexOf(t) > -1
            },
            g = 'gecko',
            w = 'webkit',
            s = 'safari',
            o = 'opera',
            m = 'mobile',
            h = document.documentElement,
            b = [(!(/opera|webtv/i.test(ua)) && /msie\s(\d)/.test(ua)) ? ('ie ie' + RegExp.$1) : is('firefox/2') ? g + ' ff2' : is('firefox/3.5') ? g + ' ff3 ff3_5' : is('firefox/3.6') ? g + ' ff3 ff3_6' : is('firefox/3') ? g + ' ff3' : is('gecko/') ? g : is('opera') ? o + (/version\/(\d+)/.test(ua) ? ' ' + o + RegExp.$1 : (/opera(\s|\/)(\d+)/.test(ua) ? ' ' + o + RegExp.$2 : '')) : is('konqueror') ? 'konqueror' : is('blackberry') ? m + ' blackberry' : is('android') ? m + ' android' : is('chrome') ? w + ' chrome' : is('iron') ? w + ' iron' : is('applewebkit/') ? w + ' ' + s + (/version\/(\d+)/.test(ua) ? ' ' + s + RegExp.$1 : '') : is('mozilla/') ? g : '', is('j2me') ? m + ' j2me' : is('iphone') ? m + ' iphone' : is('ipod') ? m + ' ipod' : is('ipad') ? m + ' ipad' : is('mac') ? 'mac' : is('darwin') ? 'mac' : is('webtv') ? 'webtv' : is('win') ? 'win' + (is('windows nt 6.0') ? ' vista' : '') : is('freebsd') ? 'freebsd' : (is('x11') || is('linux')) ? 'linux' : '', 'js'];
        c = b.join(' ');
        h.className += ' ' + c;
        return c;
    };

    css_browser_selector(navigator.userAgent);

});