
/**** jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
* jQUERY ROBERT PENNER EASING EQUATIONS
* Open source under the BSD License. Copyright © 2001 Robert Penner, All rights reserved. 
* t: current time, b: begInnIng value, c: change In value, d: duration
***/
jQuery.easing['jswing'] = jQuery.easing['swing'];
jQuery.extend(jQuery.easing, {
    def: 'easeOutQuad',
    swing: function(x, t, b, c, d) { return jQuery.easing[jQuery.easing.def](x, t, b, c, d); },
    easeInQuad: function(x, t, b, c, d) { return c * (t /= d) * t + b; },
    easeOutQuad: function(x, t, b, c, d) { return -c * (t /= d) * (t - 2) + b; },
    easeInOutQuad: function(x, t, b, c, d) { if ((t /= d / 2) < 1) return c / 2 * t * t + b; return -c / 2 * ((--t) * (t - 2) - 1) + b; },
    easeInCubic: function(x, t, b, c, d) { return c * (t /= d) * t * t + b; },
    easeOutCubic: function(x, t, b, c, d) { return c * ((t = t / d - 1) * t * t + 1) + b; },
    easeInOutCubic: function(x, t, b, c, d) { if ((t /= d / 2) < 1) return c / 2 * t * t * t + b; return c / 2 * ((t -= 2) * t * t + 2) + b; },
    easeInQuart: function(x, t, b, c, d) { return c * (t /= d) * t * t * t + b; },
    easeOutQuart: function(x, t, b, c, d) { return -c * ((t = t / d - 1) * t * t * t - 1) + b; },
    easeInOutQuart: function(x, t, b, c, d) { if ((t /= d / 2) < 1) return c / 2 * t * t * t * t + b; return -c / 2 * ((t -= 2) * t * t * t - 2) + b; },
    easeInQuint: function(x, t, b, c, d) { return c * (t /= d) * t * t * t * t + b; },
    easeOutQuint: function(x, t, b, c, d) { return c * ((t = t / d - 1) * t * t * t * t + 1) + b; },
    easeInOutQuint: function(x, t, b, c, d) { if ((t /= d / 2) < 1) return c / 2 * t * t * t * t * t + b; return c / 2 * ((t -= 2) * t * t * t * t + 2) + b; },
    easeInSine: function(x, t, b, c, d) { return -c * Math.cos(t / d * (Math.PI / 2)) + c + b; },
    easeOutSine: function(x, t, b, c, d) { return c * Math.sin(t / d * (Math.PI / 2)) + b; },
    easeInOutSine: function(x, t, b, c, d) { return -c / 2 * (Math.cos(Math.PI * t / d) - 1) + b; },
    easeInExpo: function(x, t, b, c, d) { return (t == 0) ? b : c * Math.pow(2, 10 * (t / d - 1)) + b; },
    easeOutExpo: function(x, t, b, c, d) { return (t == d) ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b; },
    easeInOutExpo: function(x, t, b, c, d) { if (t == 0) return b; if (t == d) return b + c; if ((t /= d / 2) < 1) return c / 2 * Math.pow(2, 10 * (t - 1)) + b; return c / 2 * (-Math.pow(2, -10 * --t) + 2) + b; },
    easeInCirc: function(x, t, b, c, d) { return -c * (Math.sqrt(1 - (t /= d) * t) - 1) + b; },
    easeOutCirc: function(x, t, b, c, d) { return c * Math.sqrt(1 - (t = t / d - 1) * t) + b; },
    easeInOutCirc: function(x, t, b, c, d) { if ((t /= d / 2) < 1) return -c / 2 * (Math.sqrt(1 - t * t) - 1) + b; return c / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1) + b; },
    easeInElastic: function(x, t, b, c, d) { var s = 1.70158; var p = 0; var a = c; if (t == 0) return b; if ((t /= d) == 1) return b + c; if (!p) p = d * .3; if (a < Math.abs(c)) { a = c; var s = p / 4; } else var s = p / (2 * Math.PI) * Math.asin(c / a); return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b; },
    easeOutElastic: function(x, t, b, c, d) { var s = 1.70158; var p = 0; var a = c; if (t == 0) return b; if ((t /= d) == 1) return b + c; if (!p) p = d * .3; if (a < Math.abs(c)) { a = c; var s = p / 4; } else var s = p / (2 * Math.PI) * Math.asin(c / a); return a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b; },
    easeInOutElastic: function(x, t, b, c, d) { var s = 1.70158; var p = 0; var a = c; if (t == 0) return b; if ((t /= d / 2) == 2) return b + c; if (!p) p = d * (.3 * 1.5); if (a < Math.abs(c)) { a = c; var s = p / 4; } else var s = p / (2 * Math.PI) * Math.asin(c / a); if (t < 1) return -.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b; return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p) * .5 + c + b; },
    easeInBack: function(x, t, b, c, d, s) { if (s == undefined) s = 1.70158; return c * (t /= d) * t * ((s + 1) * t - s) + b; },
    easeOutBack: function(x, t, b, c, d, s) { if (s == undefined) s = 1.70158; return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b; },
    easeInOutBack: function(x, t, b, c, d, s) { if (s == undefined) s = 1.70158; if ((t /= d / 2) < 1) return c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b; return c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b; },
    easeInBounce: function(x, t, b, c, d) { return c - jQuery.easing.easeOutBounce(x, d - t, 0, c, d) + b; },
    easeOutBounce: function(x, t, b, c, d) { if ((t /= d) < (1 / 2.75)) { return c * (7.5625 * t * t) + b; } else if (t < (2 / 2.75)) { return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b; } else if (t < (2.5 / 2.75)) { return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b; } else { return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b; } },
    easeInOutBounce: function(x, t, b, c, d) { if (t < d / 2) return jQuery.easing.easeInBounce(x, t * 2, 0, c, d) * .5 + b; return jQuery.easing.easeOutBounce(x, t * 2 - d, 0, c, d) * .5 + c * .5 + b; }
});

/* IMAGE RESIZE
* ------------------------
* Keith Parent - [c] 2010
* [ keithparent@me.com
* [ http://www.keithparent.com
*
* USAGE [ w/OPTIONS
* -----------------------
* [1] Page Inline Style Must Be Set: <style type="text/css">img.resize { display:none }</style>
* [2] Call jQuery Function:
* $(document).ready(function(){ $('img.resize').aparentResize({setWidth:350, setHeight:200}); });
* OR
* $(document).ready(function(){ $('img.resize').aparentResize(); });
*/
(function($) {
    $.fn.imgResize = function(options) {
        var defaults = { setWidth: 160, setHeight: 100 };
        var options = $.extend(defaults, options);
        // scaleIt function(args { actualSize == img.width() || img.height(),  scaleBy == xScale (actualSize/options.setWidth) || yScale (actualSize/options.setHeight)}){returns newSize} 
        function scaleIt(actualSize, scaleBy) { if (actualSize && scaleBy) return reSized = Math.ceil(actualSize * (1 / scaleBy)) }
        return this.each(function() {
            // Init local ref to img obj
            img = $(this);
            // Init vars
            var w = img.width(), xScale, xResized;
            var h = img.height(), yScale, yResized;
            // Set xScale && yScale
            if (!options.setHeight && w > options.setWidth) { xScale = w / options.setWidth; }
            else if (!options.setWidth && h > options.setHeight) { yScale = h / options.setHeight; }
            else { xScale = w / options.setWidth; yScale = h / options.setHeight; }
            // Set new dimensions
            if (xScale) xResized = scaleIt(w, xScale); img.css("width", xResized);
            if (yScale) yResized = scaleIt(h, yScale); img.css("height", yResized);
            // Apply new dimensions to img (scaled by option arg but applied to shortest side)
            /*if (xResized < yResized) { img.css("height", yResized).css("width", xResized); }
            else { img.css("height", xResized).css("width", yResized); }*/
            // Set opacity to zero first, then show it (set display from none), then animate the opacity fading in
            img.animate({ 'opacity': 'hide' }).show("fast").animate({ 'opacity': 'show' }, 1200, 'easeInOutCirc');
        });
    };
})(jQuery);

/*** CONTENT SLIDER ***/
/*[ by Keith Parent, (c) 2010
* [ http://www.keithparent.com
* [ keithparent@me.com
* Adapted & Modified from:
anythingSlider v1.1 by Chris Coyier: http://css-tricks.com
with major improvements by Doug Neiner: http://pixelgraphics.us/
based on work by Remy Sharp: http://jqueryfordesigners.com/
To use the navigationFormatter function, you must have a function that
accepts two (2) paramaters, and returns a string of HTML text.
index = integer index (1 based);
slide = jQuery wrapped LI item this tab references
@return = Must return a string of HTML/Text
// The following has each tab w/text 'slide*' where '*' = array[index]
navigationFormatter: function(index, slide){ return "slide" + index; }
* Modifications (by Keith):
* [1] Included the jQuery Penner Easing Methods 1.3 (also, included w/jQuery UI Core Effects as of v.1.8)
* [2] Uses thumbnail images for the navigation in place of text numbers,
* [3] Set-up variables for the thumbnail images to allow easy customization:
*     thImgDir      =   site directory path to the thumbnail images' location
*     thImgName     =   base name of thumbnail image (is prepended with array[index])
*     thImgExt      =   thumbnail images' file format extension
*     thImgAlt      =   alternate thumbnail images' name (prepends to the base name + array[index])
*     thImgOnClass  =   class added to the thumbnail ($('#thumbNav a')) when it is the current slide.
*/
(function($) {

    $.contentSlider = function(el, options) {
    
        /*** INIT VARS => THUMBNAIL CONFIGURATION (Edit vars to reflect site directory, CSS class names, and image names) ***/
        var thImgDir = "imgs/contentslider/thumbs/",
            thImgName = "th",
            thImgExt = "jpg",
            thImgAppend = "_o",
            thImgOnClass = "on";
        /*** NO NEED TO EDIT ANY FURTHER ***/

        // To avoid scope issues, use 'base' instead of 'this' to reference this class from internal events and functions.
        var base = this;
        // Access to jQuery and DOM versions of element
        base.$el = $(el);
        base.el = el;
        // Set up defaults
        base.currentPage = 1;
        base.timer = null;
        base.playing = false;
        // Add reverse reference to DOM obj
        base.$el.data("ContentSlider", base);
        base.init = function() {
            base.options = $.extend({}, $.contentSlider.defaults, options);
            // Cache existing DOM elements for later 
            base.$wrapper = base.$el.find('> div').css('overflow', 'hidden');
            base.$slider = base.$wrapper.find('> ul');
            base.$items = base.$slider.find('> li');
            base.$single = base.$items.filter(':first');
            // Build nav if needed
            if (base.options.buildNavigation) base.buildNavigation();
            // Get details
            base.singleWidth = base.$single.outerWidth();
            base.pages = base.$items.length;
            // Top and tail the list with 'visible' number of items, top has the last section, and tail has the first. This supports the "infinite" scrolling.
            base.$items.filter(':first').before(base.$items.filter(':last').clone().addClass('cloned'));
            base.$items.filter(':last').after(base.$items.filter(':first').clone().addClass('cloned'));
            // We just added two items, so re-cache the list
            base.$items = base.$slider.find('> li'); // reselect
            // Setup our forward/backward navigation
            base.buildNextBackButtons();
            // If autoPlay functionality is included, then init settings
            if (base.options.autoPlay) {
                base.playing = !base.options.startStopped; // Sets the playing var to false if startStopped is true
                base.buildAutoPlay();
            };
            // If pauseOnHover then add hover effects
            if (base.options.pauseOnHover) base.$el.hover(function() { base.clearTimer(); }, function() { base.startStop(base.playing); });
            // If a hash can't be used to trigger plugin, then go to slide 1
            if ((base.options.hashTags == true && !base.gotoHash()) || base.options.hashTags == false) base.setCurrentPage(1);
            //PR - select a random start slide
            var randomnumber = Math.floor(Math.random()*4);
            base.gotoPage(randomnumber);
        };
        base.gotoPage = function(page, autoplay) {
            // When autoplay isn't passed, stop the timer
            if (autoplay !== true) autoplay = false;
            if (!autoplay) base.startStop(false);
            if (typeof (page) == "undefined" || page == null) {
                page = 1;
                base.setCurrentPage(1);
            };
            // Just check for bounds
            if (page > base.pages + 1) page = base.pages;
            if (page < 0) page = 1;
            var dir = page < base.currentPage ? -1 : 1,
                n = Math.abs(base.currentPage - page),
                left = base.singleWidth * dir * n;
            base.$wrapper.filter(':not(:animated)').animate({
                scrollLeft: '+=' + left
            }, base.options.animationTime, base.options.easing, function() {
                if (page == 0) {
                    base.$wrapper.scrollLeft(base.singleWidth * base.pages);
                    page = base.pages;
                } else if (page > base.pages) {
                    base.$wrapper.scrollLeft(base.singleWidth);
                    page = 1; // reset
                };
                base.setCurrentPage(page);
            });
        };
        base.setCurrentPage = function(page, move) {
            // Set visual
            if (base.options.buildNavigation) {
                base.$nav.find("a").removeClass(thImgOnClass).find(".current").stop().fadeTo('fast', 0, 'easeOutExpo'); // reset thumbnail grfx
                /*if ($prevPanel.find("img").attr("src") != null) $prevPanel.find("img").attr("src", $prevPanel.find("img").attr("src").split("-on.").join("."));*/
                // set thumbnail grfx
                $(base.$navLinks[page - 1]).addClass(thImgOnClass).find(".current").stop().fadeTo('slow', 1, 'easeInExpo');
                //var $nextPanel = base.$nav;
                //var nextImg = $nextPanel.find("img");
                //$(nextImg).attr("src", $(nextImg).attr("src").split(".").join("-alt."));
                //$nextPanel.find("img").attr("src", $nextPanel.find("img").attr("src").split(".").join("-alt."));
            };
            // Only change left if move != false
            if (move !== false) base.$wrapper.scrollLeft(base.singleWidth * page);
            base.currentPage = page; // Update local var
        };
        base.goForward = function(autoplay) {
            if (autoplay !== true) autoplay = false;
            base.gotoPage(base.currentPage + 1, autoplay);
        };
        base.goBack = function() { base.gotoPage(base.currentPage - 1); };
        // This method tries to find hash that matches 'slide*'
        // If found, it tries to find a matching item
        // If that is found as well, then that item starts visible
        base.gotoHash = function() {
            if (/^#?slide\d+$/.test(window.location.hash)) {
                var index = parseInt(window.location.hash.substr(7));
                var $item = base.$items.filter(':eq(' + index + ')');
                if ($item.length != 0) base.setCurrentPage(index);
                return true;
            };
            return false; // item not found
        };
        // Creates nav links
        base.buildNavigation = function() {
            base.$nav = $('<div id="thumbNav"></div>').appendTo(base.$el);
            base.$items.each(function(i, el) {
                var index = i + 1;  // Sets array index numbering to base 1 )
                $a = $('<a href="#" id="' + thImgName + index + '"><span class="thumbui"><img class="current" src="imgs/contentslider/thumbs/arrow-on.png" width="30" height="15" alt="" /><p class="caption">' + $('.contentSlider h2:eq(' + i + ')').text() + '</p></span><img class="thumb" src="' + thImgDir + thImgName + index + "." + thImgExt + '" runat="Server" border="0" alt="" /></a>');
                /* If formatter function is present, use it
                if( typeof(base.options.navigationFormatter) == "function"){
                $a.html(base.options.navigationFormatter(index, $(this)));
                } else { $a.html('<a href="#"><img src="' + thImgDir + thImgName + index + '.' + thImgExt + " alt="">' + index + '</a>'); //$a.text(index);
                }

                $a.hover(function() {
                    if ($(this).attr("src") != null) $(this).attr("src", $(this).attr("src").split(".").join("_o."));
                }, function() {
                    if ($(this).attr("src") != null) $(this).attr("src", $(this).attr("src").split("_o.").join("."));
                });*/

                $a.click(function(e) {
                    base.gotoPage(index);
                    if (base.options.hashTags) base.setHash('slide' + index);
                    e.preventDefault();
                });
                base.$nav.append($a);
            });
            base.$navLinks = base.$nav.find('> a');
        };
        // Creates the Forward/Backward buttons
        base.buildNextBackButtons = function() {
            var $forward = $('<a class="arrow next"><strong>&raquo;</strong></a>'), $back = $('<a class="arrow prev"><strong>&laquo;</strong></a>');
            // Bind to forward & back buttons
            $back.click(function(e) { base.goBack(); e.preventDefault(); });
            $forward.click(function(e) { base.goForward(); e.preventDefault(); });
            base.$wrapper.after($back).after($forward); // Append elements to page
        };
        // Creates the Start/Stop button
        base.buildAutoPlay = function() {
            base.$startStop = $("<a href='#' id='start-stop'></a>").html(base.playing ? base.options.stopText : base.options.startText);
            base.$el.append(base.$startStop);
            base.$startStop.click(function(e) { base.startStop(!base.playing); e.preventDefault(); });
            base.startStop(base.playing); // Use the same setting, but trigger the start;
        };
        // Handles stopping and playing the slideshow: Pass startStop(false) to stop & startStop(true) to play
        base.startStop = function(playing) {
            if (playing !== true) playing = false; // Default if not supplied is false
            base.playing = playing; // Update var
            // Toggle playing & text
            if (base.$startStop) base.$startStop.toggleClass("playing", playing).html(playing ? base.options.stopText : base.options.startText);
            if (playing) {
                base.clearTimer(); // Just in case this was triggered twice in a row
                base.timer = window.setInterval(function() { base.goForward(true); }, base.options.delay);
            } else { base.clearTimer(); };
        };
        base.clearTimer = function() { if (base.timer) window.clearInterval(base.timer); }; // Clear timer if set
        // From AJAXY jquery.history Plugin
        base.setHash = function(hash) {
            if (typeof window.location.hash !== 'undefined') { // Write hash
                if (window.location.hash !== hash) window.location.hash = hash;
            } else if (location.hash !== hash) { location.hash = hash; };
            return hash;
        };// <-- End AJAXY code
        base.init();    // Instantiation
    };
    $.contentSlider.defaults = {
        easing: "linear",                // Anything other than "linear" or "swing" requires the easing plugin
        autoPlay: false,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not
        startStopped: false,            // If autoPlay is on, this can force it to start stopped
        delay: 4000,                    // How long between slide transitions in AutoPlay mode
        animationTime: 'slow',             // How long the slide transition takes
        hashTags: false,                 // Should links change the hashtag in the URL?
        buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
        pauseOnHover: false,             // If true, and autoPlay is enabled, the show will pause on hover
        startText: "Start",             // Start text
        stopText: "Stop",               // Stop text
        navigationFormatter: null       // Details at the top of the file on this use (advanced use)
    };
    $.fn.contentSlider = function(options) {
        if (typeof (options) == "object") {
            return this.each(function(i) {
                (new $.contentSlider(this, options));
                options.hashTags = false;
            });
        } else if (typeof (options) == "number") {
            return this.each(function(i) {
                var contentSlide = $(this).data('ContentSlider');
                if (contentSlide) contentSlide.gotoPage(options);
            });
        }
    };
})(jQuery);


/*** DUCK PUNCHING SOME I.T. BY DESIGN AWESOMENESS ***/
jQuery(document).ready(function($) {

    // FADE IN ENTIRE PAGE
    //$("body").hide().fadeTo('normal', 1, 'easeInExpo');

    // CONTENT SLIDER w/Thumbnail Image Resizing
    $(".contentSlider").contentSlider({ easing: 'easeInOutExpo', autoPlay: false, animationTime: 1200 }).find('#thumbNav img.thumb').imgResize();

    // FORCE VERTICAL BOTTOM ALIGNMENT
    $(".txt").each(function() {
        var innerObjHeight = $(this).height();
        var outerObjHeight = $(this).parent().height();
        var borderOffset = 2;
        var innerObjMarginTop = (outerObjHeight - innerObjHeight) - borderOffset;
        $(this).css('top', innerObjMarginTop);
    });

    // FADE HOVER
    $(".fade").hover(function() {
        this.check = this.check || 1;
        $(this).stop().fadeTo('slow', this.check++ % 2 == 0 ? 1 : 0.5, 'easeInOutExpo');
    });

    // ROLLOVER IMAGE SWAP
    $(".over").find("img").hover(function() { $(this).attr('src', $(this).attr('src').split('.').join('_o.'));
    }, function() { $(this).attr('src', $(this).attr('src').split('_o.').join('.')); });

    // ROLLOVER SPRITE IMAGE FADE
    $(".sprite").append('<span class="hover" />').each(function() {
        var $span = $('> span.hover', this).css('opacity', 0);
        $(this).hover(function() {
            $span.stop().fadeTo('fast', 1, 'easeInExpo');
        }, function() { $span.stop().fadeTo(1200, 0, 'easeOutExpo'); });
    });
});

/*** BACKGROUND SCROLL ***/
(function($) {
    var bgH = 317; // bgimg.height();
    var bgW = 678;
    var now = new Date();
    var hour = now.getHours();
    var minute = now.getMinutes();
    var hourPercent = hour / 24 * 100;
    var minutePercent = minute / 60 / 24 * 100;
    var dayPercent = Math.round(hourPercent + minutePercent);
    var offset = bgW / 100 * dayPercent;
    var offset = offset - (bgW / 4);
    function scrollbackground() {
        // offset - 1 || if < 1 then + (bg.height() - 1)
        offset = (offset < 1) ? offset + (bgW - 1) : offset - 1;
        $(".itbdlogo").css("background-position", offset + "px 100%");
        setTimeout(function() { scrollbackground(); }, bgW/2);
    }
    scrollbackground();
})(jQuery);

// EOF