// $Id: at.js,v 1.1.2.3 2010/12/01 13:48:24 jmburnz Exp $
(function ($) {
  /**
   * Insert WAI-ARIA Landmark Roles (Roles for Accessible Rich Internet Applications)
   * http://www.w3.org/TR/2006/WD-aria-role-20060926/
   */
  Drupal.behaviors.adaptivetheme = {
    attach: function(context) {

      // Set role="banner" on the header element.
      $("#page > header").attr("role", "banner");

      // Set role="main" on #main-content div.
      $("#main-content").attr("role", "main");

      // Set role="search" on search forms.
      $("#search-theme-form").attr("role", "search");

      // Set role="contentinfo" on the page footer.
      $("footer").attr("role", "contentinfo");

      // Set role=article on nodes.
      $(".article").attr("role", "article");

      // Set role="nav" on navigation-like blocks.
      $("nav, .admin-panel, #breadcrumb").attr("role", "navigation");
      
      // Set role="complementary" on navigation-like blocks.
      $("aside").attr("role", "complementary");

      // Set role="region" on section elements.
      $("section").attr("role", "region");

      // Set role="region" on section elements.
      $("#search-block-form, #search-form").attr("role", "search");

    }
  };

  /**
   * In most instances this will be called using the built in theme settings.
   * However, if you want to use this manually you can call this file
   * in the info file and user the ready function e.g.:
   * 
   * This will set sidebars and the main content column all to equal height:
   *  (function ($) {
   *    Drupal.behaviors.adaptivetheme = {
   *      attach: function(context) {
   *        $('#content-column, .sidebar').equalHeight();
   *      }
   *    };
   *  })(jQuery);
   */
  jQuery.fn.equalHeight = function () {
    var height = 0;
    var maxHeight = 0;

    // Store the tallest element's height
    this.each(function () {
      height = jQuery(this).outerHeight();
      maxHeight = (height > maxHeight) ? height : maxHeight;
    });

    // Set element's min-height to tallest element's height
    return this.each(function () {
      var t = jQuery(this);
      var minHeight = maxHeight - (t.outerHeight() - t.height());
      var property = jQuery.browser.msie && jQuery.browser.version < 7 ? 'height' : 'min-height';

      t.css(property, minHeight + 'px');
   });
  };

})(jQuery);;
function trace(args) {
    if (this.console  && typeof console.log != 'undefined') {
        console.log(args);
    }
}
;
(function ($) {

    function shuffle(list) {
        var i, j, t;
        for (i = 1; i < list.length; i++) {
            j = Math.floor(Math.random()*(1+i)); // choose j in [0..i]
            if (j != i) {
                t = list[i]; // swap list[i] and list[j]
                list[i] = list[j];
                list[j] = t;
            }
        }
    }

    $(function () {

        // Don't do anything in IE 6
        if ($.browser.msie && $.browser.version.substr(0,1) < 7)
            return;

        var buzzwords = $('#block-views-buzzwords-block .buzz');
        if (buzzwords.length == 0)
            return;

        if (buzzwords.length == 1) {
            buzzwords.css('display', 'block');
            return;
        }

        shuffle(buzzwords);

        var fadeTime = 1500;
        var cycleTime = 7000;

        var limit_x = 580;
        var limit_y = 120;

        var current = null;
        function loop() {

            var existed = current != null;
            if (existed)
                current.animate({ opacity: '0' }, fadeTime);

            current = $(buzzwords[0]);
            if (current.hasClass('random')) {
                var w = current.width()
                var h = current.height();
                if (w < 10 || h < 10) {
                    w = 300;
                    h = 30;
                }
                var max_x = Math.max(0, limit_x - w);
                var max_y = Math.max(0, limit_y - h);
                current.css({
                    top: Math.floor(Math.random() * max_y) + 25 + "px",
                    left: Math.floor(Math.random() * max_x) + "px"
                });
            }

            buzzwords = buzzwords.slice(1);
            buzzwords.push(current);

            if (!existed) {
                current.animate({
                    opacity: '1'
                }, fadeTime);
            } else {
                setTimeout(function () {
                    current.animate({
                        opacity: '1'
                    }, fadeTime);
                }, fadeTime);
            }
        }

        setInterval(loop, cycleTime);
        loop();

    });

})(jQuery);
;
(function ($) {

    $.fn.orzSlider = function (options) {

        var $slider = this;

        var defaults = {
            prevSelector: '#prevBtn',
            nextSelector: '#nextBtn',
            speed: 800,
            width: 'auto',
            height: 'auto',
            easing: 'swing',
            selectSelector: null,
            afterMoveFunction: function () {}
        };

        var options = $.extend(defaults, options);

        var totalElements = $('li', this).length;
        if (totalElements == 0)
            return this;

        var kids = [];
        this.find('li').each(function (i, e) {
            var $this = $(e);
            $this.css({
                position: 'absolute',
                display: 'none',
                opacity: 0
            });
            kids.push($this);
        });

        var currentIndex = 0;
        var currentKid = kids[currentIndex];

        var height = options.height == 'auto' ? kids[0].height() + 'px' : options.height;
        var width = options.width == 'auto' ? kids[0].width() + 'px' : options.width;
        this.css({
            overflow: 'hidden',
            height: height,
            width: width
        });

        // Prevent too fast clicking.
        var enableClick = true;

        var animSettings = {
            duration: options.speed,
            complete: animationDone,
            queue: false,
            easing: options.easing
        };

        function animationDone() {
            // $(this) is the animated element.
            enableClick = true;
            $prevBtn.removeClass('waiting');
            $nextBtn.removeClass('waiting');
        }

        function move(delta) {

            var moveRight = delta > 0;

            // Prevent too fast clicking.
            if (!enableClick)
                return;
            enableClick = false;

            // Prevent going out of bounds.
            var newIndex = currentIndex + delta;
            if (newIndex < 0 || newIndex > (kids.length - 1))
                return;

            $prevBtn.addClass('waiting');
            $nextBtn.addClass('waiting');

            // Use a timeout to simulate threading.
            setTimeout(function () {
                // Get the old kid out.
                var oldKid = kids[currentIndex];
                oldKid.animate({
                    left: moveRight ?
                        -1 * $slider.width() :
                        $slider.width(),
                    opacity: 0
                }, animSettings);

                // Get the new kid in.
                var kid = kids[newIndex];
                kid.show().css({
                    left: moveRight ?
                        $slider.width() :
                        -1 * $slider.width()
                }).animate({
                    left: 0,
                    opacity: 1
                }, animSettings);
                currentIndex = newIndex;
            }, 0);

            if (newIndex == 0) {
                $prevBtn.fadeOut();
                $prevBtn.addClass('impossible');
            } else {
                $prevBtn.fadeIn();
                $prevBtn.removeClass('impossible');
            }
            if (newIndex == totalElements - 1) {
                $nextBtn.fadeOut();
                $nextBtn.addClass('impossible');
            } else {
                $nextBtn.fadeIn();
                $nextBtn.removeClass('impossible');
            }

            if (options.selectSelector) {
                $(options.selectSelector).val(newIndex);
            }

            options.afterMoveFunction(delta, newIndex);

        }

        var $prevBtn =
            $(options.prevSelector).
            fadeOut().
            addClass('impossible').
            click(function () {
                move(-1);
                return false;
            });
        var $nextBtn =
            $(options.nextSelector).
            click(function () {
                move(1);
                return false;
            });

        // Display the first element.
        kids[0].show().css('opacity', 1);

        if (options.selectSelector) {
            $(options.selectSelector).change(function (ev) {
                move($(this).val() - currentIndex);
            });
        }

        return this;

    }

})(jQuery);
;
(function ($) {

    $(function () {

        // Person listing
        $('.view-person-listing .person a').each(function () {
            // Open the links in a lightbox if JavaScript is enabled.
            return $(this).attr('href', $(this).attr('href') + '?ajax=1').attr('rel', 'people');
        }).colorbox({
            current: "{current}&nbsp;/&nbsp;{total}",
            maxWidth: 800,
            maxHeight: 600,
            scrolling: false
        });

    });

})(jQuery);
;
(function ($) {

    $(function () {

        // Front page boxes
        $('.view-id-front_page_boxes a').mouseover(function () {
            var $glow = $('.glow', this);
            var $text = $('.text', this);
            $glow.animate({ opacity: 1 },
                          { queue: false });

            // Store the old height to be able to restore it later.
            if (!$text.data('old_height'))
                $text.data('old_height', $text.height());

            $text.animate({ height: '34px' },
                          { duration: 200, queue: false });
        }).mouseout(function () {
            var $glow = $('.glow', this);
            var $text = $('.text', this);
            $glow.animate({ opacity: 0 },
                          { queue: false });
            $text.animate({ height: $text.data('old_height') + 'px' },
                          { duration: 200, queue: false });
        });

    });

})(jQuery);
;
(function ($) {

    $(function () {

        // No IE6, please.
        if ($.browser.msie && $.browser.version < 7)
            return;

        setTimeout(function () {

            // Rounded corners on all images.
            $('#columns img').each(function (_idx, img) {

                if (img.width < 30 || img.height < 30)
                    return;

                var $img = $(img);

                if ($img.hasClass('noround'))
                    return;

                var imgWidth = $img.outerWidth();
                var imgHeight = $img.outerHeight();
                var imgPosition = $img.position();

                // Get the left and top margin of the image to be able to
                // position the rounded corners correctly.  (We are positioning
                // them using "top" and "left", that's why...)
                try {
                    var imgMarginLeft = parseInt($img.css('margin-left').match(/^(\d+)px$/)[0]);
                    var imgMarginTop = parseInt($img.css('margin-top').match(/^(\d+)px$/)[0]);
                } catch (_err) {
                    var imgMarginLeft = 0;
                    var imgMarginTop = 0;
                }

                // Create the corners.
                var spans = [];
                var tl = $('<span></span>').addClass('orz-img-corner orz-tl').insertAfter(img);
                var tr = $('<span></span>').addClass('orz-img-corner orz-tr').insertAfter(img);
                var bl = $('<span></span>').addClass('orz-img-corner orz-bl').insertAfter(img);
                var br = $('<span></span>').addClass('orz-img-corner orz-br').insertAfter(img);

                // Assuming all corners have the same size.
                var cornerWidth = tl.width();
                var cornerHeight = tl.height();

                // Get the position of the image relative to its offset parent.
                var rightPosition = imgPosition.left + imgWidth + imgMarginLeft - cornerWidth;
                var bottomPosition = imgPosition.top + imgHeight + imgMarginTop - cornerHeight;
                var topPosition = imgPosition.top + imgMarginTop;
                var leftPosition = imgPosition.left + imgMarginLeft;
                tl.css({ top: topPosition, left: leftPosition });
                tr.css({ top: topPosition, left: rightPosition });
                bl.css({ top: bottomPosition, left: leftPosition });
                br.css({ top: bottomPosition, left: rightPosition });

            });

            // Alt text
            $('#columns img[alt!=""]').each(function (_idx, img) {
                var imgWidth = img.width;
                var imgHeight = img.height;

                if (imgWidth < 30 || imgHeight < 30)
                    return;

                var $img = $(img);

                if ($img.hasClass('noround') || $img.closest('.people'))
                    return;

                var alt = img.alt;
                img.alt = "";

                var $bg = $('<div class="orz-alt-bg"></div>').insertAfter(img);
                var $fg = $('<div class="orz-alt-fg"><span>' + alt + '</span></div>').insertAfter(img);

                var fgHeight = $fg.outerHeight(true);
                var imgPos = $img.position();

                var cssSettings = {
                    width: imgWidth,
                    height: fgHeight,
                    top: imgHeight + imgPos.top - fgHeight,
                    left: imgPos.left
                };

                $bg.css(cssSettings);
                $fg.css(cssSettings);

            });

        }, 500);

    });

})(jQuery);
;

