- $.fn.exists = function(){
- return $(this).length>0;
- };
- $.fn.reverse = function(){
- return this.pushStack(this.get().reverse(), arguments);
- };
- $(document).ready(function(){
- //Full Caption Sliding (Hidden to Visible)
- $('.menuItem.captionfull').hover(function(){
- $(".cover", this).stop().animate({top:'0px'},{queue:false,duration:160});
- }, function() {
- $(".cover", this).stop().animate({top:'160px'},{queue:false,duration:160});
- });
- });
- /*--------------------------------------------------------------------------------------------
- *
- * setup_forms
- *
- *--------------------------------------------------------------------------------------------*/
- function setup_forms()
- {
- $('form').each(function(){
- var form = $(this);
- // focus blur
- if($(this).hasClass('focus-blur'))
- {
- form.focus_blur();
- }
- // validate
- form.validate({
- highlight: function(element, errorClass, validClass) {
- $(element).closest('.field').addClass('error');
- },
- unhighlight: function(element, errorClass, validClass) {
- $(element).closest('.field').removeClass('error');
- }
- });
- // style selects
- form.style_form();
- });
- }
- /*--------------------------------------------------------------------------------------------
- *
- * accordion
- *
- *--------------------------------------------------------------------------------------------*/
- var accordion_speed = 500;
- $('.accordion .toggle').live('click', function(){
- var accordion = $(this).closest('.accordion');
- if(accordion.hasClass('active'))
- {
- accordion.removeClass('active').children('.content').css({display : 'block'});
- }
- else
- {
- $('html, body').animate({scrollTop : accordion.offset().top - 10}, 500);
- accordion.addClass('active').children('.content').css({display : 'none'});
- }
- accordion.children('.content').animate({'height' : 'toggle'}, accordion_speed);
- return false;
- });
- /*--------------------------------------------------------------------------------------------
- *
- * setup_hero
- *
- *-------------------------------------------------------------------------------------------*/
- function setup_hero(options)
- {
- if(!$('#hero').exists())
- {
- return false;
- }
- // default options
- var defaults = {
- parallax : false,
- auto_slide : true
- };
- options = $.extend(defaults, options);
- // vars
- var div = $('#hero');
- var nav = div.find('.thumbnail-controls');
- var timer;
- var delay = 8000;
- var i = 1;
- // stop if no parallax
- if(nav.find('ul li a').length == 1){
- nav.hide();
- }
- // set active
- nav.find('ul li a[data-i="'+i+'"]').addClass('active');
- // click nav
- nav.find('ul li a').click(function(){
- options.auto_slide = true;
- var new_i = parseInt($(this).attr('data-i'));
- if(new_i == i)
- {
- return false;
- }
- var direction = (new_i > i) ? "left" : "right";
- // update nav active
- nav.find('a[data-i="'+i+'"]').removeClass('active');
- nav.find('a[data-i="'+new_i+'"]').addClass('active');
- var new_percent = (new_i-1) * 100;
- if(direction == "left")
- {
- div.find('.slides-bird').animate({left : -new_percent + '%'}, 1500);
- setTimeout(function(){
- div.find('.slides-text').animate({left : -new_percent + '%'}, 1500);
- }, 100);
- setTimeout(function(){
- div.find('.slides-bg').animate({left : -new_percent + '%'}, 1500);
- }, 200);
- }
- else
- {
- div.find('.slides-text').animate({left : -new_percent + '%'}, 1500);
- setTimeout(function(){
- div.find('.slides-bird').animate({left : -new_percent + '%'}, 1500);
- }, 100);
- setTimeout(function(){
- div.find('.slides-bg').animate({left : -new_percent + '%'}, 1500);
- }, 200);
- }
- // set new i
- i = new_i;
- // set timout for next slide
- slide_next();
- return false;
- });
- // click prev
- nav.find('.prev').click(function(){
- options.auto_slide = false;
- if(!nav.find('ul li a[data-i="'+(i-1)+'"]').exists())
- {
- return false;
- }
- nav.find('ul li a[data-i="'+(i-1)+'"]').trigger('click');
- return false;
- });
- // click next
- nav.find('.next').click(function(){
- options.auto_slide = false;
- if(!nav.find('ul li a[data-i="'+(i+1)+'"]').exists())
- {
- return false;
- }
- nav.find('ul li a[data-i="'+(i+1)+'"]').trigger('click');
- return false;
- });
- // auto slide
- function slide_next(new_delay)
- {
- if(!options.auto_slide){
- return false;
- }
- new_delay = (new_delay != null) ? new_delay : delay;
- clearTimeout(timer);
- var a = nav.find('ul li a[data-i="'+(i+1)+'"]').exists() ? nav.find('ul li a[data-i="'+(i+1)+'"]') : false;
- if(a == false){
- return false;
- }
- timer = setTimeout(function(){
- a.trigger('click');
- }, new_delay);
- }
- slide_next();
- // hover pause
- var timer_start = 0;
- div.hover(function(){
- // stop auto
- clearTimeout(timer);
- // start timer
- var newDate = new Date();
- timer_start = newDate.getTime();
- }, function(){
- var newDate = new Date();
- var hover_length = newDate.getTime() - timer_start;
- var new_delay = delay - hover_length;
- if(new_delay < 0)
- {
- new_delay = 0;
- }
- slide_next(new_delay);
- });
- // stop if no parallax
- if(!options.parallax){
- return false;
- }
- var interval;
- var interval2;
- var mouse_page_x = 0;
- var old_x1 = 0;
- var old_x2 = 0;
- var new_x1 = 50;
- var new_x2 = 50;
- div.mousemove(function(e){
- mouse_page_x = e.pageX;
- });
- div.hover(function(){
- clearInterval(interval2);
- interval = setInterval(function(){
- var x = mouse_page_x - div.offset().left;
- var x_percent = x / div.width();
- // set old values
- old_x1 = new_x1;
- old_x2 = new_x2;
- // new x
- new_x1 = 50 + ((-20*x_percent) + 10);
- new_x2 = 50 + ((20*x_percent) - 10);
- // dif
- var diff_1 = (new_x1 - old_x1);
- var diff_2 = (new_x2 - old_x2);
- new_x1 = old_x1 + (diff_1 / 3);
- new_x2 = old_x2 + (diff_2 / 3);
- //console.log(diff_1);
- //console.log(diff_1);
- //console.log(diff_2);
- div.find('.slides-bird .slide').css({'background-position' : new_x1 + '% 0%'});
- div.find('.slides-bg .slide').css({'background-position' : new_x2 + '% 0%'});
- }, 30);
- }, function(){
- clearInterval(interval);
- // animate to center
- var reset_speed = 1800;
- interval2 = setInterval(function(){
- var x_percent = 0.5;
- // set old values
- old_x1 = new_x1;
- old_x2 = new_x2;
- // new x
- new_x1 = 50 + ((-20*x_percent) + 10);
- new_x2 = 50 + ((20*x_percent) - 10);
- // dif
- var diff_1 = (new_x1 - old_x1);
- var diff_2 = (new_x2 - old_x2);
- new_x1 = old_x1 + (diff_1 / 3);
- new_x2 = old_x2 + (diff_2 / 3);
- //console.log(diff_1);
- //console.log(diff_1);
- //console.log(diff_2);
- div.find('.slides-bird .slide').css({'background-position' : new_x1 + '% 0%'});
- div.find('.slides-bg .slide').css({'background-position' : new_x2 + '% 0%'});
- }, 30);
- setTimeout(function(){
- clearInterval(interval2);
- }, reset_speed);
- });
- }
- /*--------------------------------------------------------------------------------------------
- *
- * setup_home_projects
- *
- *-------------------------------------------------------------------------------------------*/
- function setup_widget_projects()
- {
- if(!$('#widget-projects').exists())
- {
- return false;
- }
- // vars
- var div = $('#widget-projects');
- var nav = div.find('.thumbnail-controls');
- var text = div.find('.texts');
- var image = div.find('.images');
- var i = 0;
- // set active
- nav.find('ul li a[data-i="'+i+'"]').addClass('active');
- text.find('.text[data-i="'+i+'"]').css({display: 'block', opacity : 1});
- image.find('.image[data-i="'+i+'"]').css({left : 0});
- nav.find('ul li a').click(function(){
- var new_i = parseInt($(this).attr('data-i'));
- if(new_i == i)
- {
- return false;
- }
- // update nav active
- nav.find('ul li a[data-i="'+i+'"]').removeClass('active');
- nav.find('ul li a[data-i="'+new_i+'"]').addClass('active');
- // fade texts
- text.find('.text[data-i="'+i+'"]').animate({opacity : 0}, 500);
- text.find('.text[data-i="'+new_i+'"]').css({display: 'block'}).animate({opacity : 1}, 500);
- // slide image
- image.find('.image').css({'z-index' : 0})
- image.find('.image[data-i="'+i+'"]').css({'z-index' : 1});
- var image_css = {'z-index' : 2, 'left' : 298};
- if(i > new_i)
- {
- image_css = {'z-index' : 2, 'left' : -298};
- }
- image.find('.image[data-i="'+new_i+'"]').css(image_css).animate({left : 0}, 500);
- i = new_i;
- return false;
- });
- // click prev
- nav.find('.prev').click(function(){
- if(!nav.find('ul li a[data-i="'+(i-1)+'"]').exists())
- {
- return false;
- }
- nav.find('ul li a[data-i="'+(i-1)+'"]').trigger('click');
- return false;
- });
- // click next
- nav.find('.next').click(function(){
- if(!nav.find('ul li a[data-i="'+(i+1)+'"]').exists())
- {
- return false;
- }
- nav.find('ul li a[data-i="'+(i+1)+'"]').trigger('click');
- return false;
- });
- }
- /*--------------------------------------------------------------------------------------------
- *
- * setup_widget_wbit
- *
- *-------------------------------------------------------------------------------------------*/
- function setup_widget_wbit()
- {
- if(!$('#widget-wbit,#widget-wbit-sidebar,#widget-whatson').exists())
- {
- return false;
- }
- // vars
- $('#widget-wbit,#widget-wbit-sidebar,#widget-whatson').hover(function(){
- $(this).find('img').stop().animate({width : 324, left : -13, top: -10}, 250);
- }, function(){
- $(this).find('img').stop().animate({width : 298, left : 0, top: 0}, 500);
- });
- }
- /*--------------------------------------------------------------------------------------------
- *
- * setup_home_news
- *
- *-------------------------------------------------------------------------------------------*/
- function setup_home_news()
- {
- // vars
- var div = $('#home-news');
- div.find('.tabs li a').click(function(){
- var i = $(this).attr('data-i');
- $(this).parent('li').addClass('active').siblings('li').removeClass('active');
- div.find('.content .inner').removeClass('active');
- div.find('.content .inner[data-i="'+i+'"]').addClass('active');
- return false;
- });
- }
- /*--------------------------------------------------------------------------------------------
- *
- * setup_featured_birds
- *
- *-------------------------------------------------------------------------------------------*/
- function setup_featured_birds()
- {
- var i = 1;
- var div = $('#featured-birds');
- var w = 588 + 30;
- div.find('.slide:first-child').show();
- // fly
- function fly(direction)
- {
- var slide = div.find('.slide[data-i="'+i+'"]');
- var delay = 0;
- var birds = (direction == "right") ? slide.find('a').reverse() : slide.find('a');
- birds.each(function(){
- var a = $(this);
- setTimeout(function(){
- var css_1 = (direction == "right") ? {'top' : 0, 'right' : w*-1} : {'top' : 0, 'right' : w};
- //var css_2 = (direction == "right") ? {'top' : 0, 'right' : 0} : {'top' : 0, 'right' : 0};
- a.animate(css_1, 600, function(){
- //a.animate(css_2, 600);
- });
- }, delay);
- delay += 50;
- });
- // update i for next slide
- if(direction == "right")
- {
- i++;
- }
- else
- {
- i--;
- }
- // after birds have flown off
- setTimeout(function(){
- var slide = div.find('.slide[data-i="'+i+'"]');
- var delay_2 = 0;
- var birds = (direction == "right") ? slide.find('a').reverse() : slide.find('a');
- birds.each(function(){
- var a = $(this);
- var css_3 = (direction == "right") ? {'top' : 0, 'right' : w} : {'top' : 0, 'right' : (w)*-1};
- a.css(css_3);
- setTimeout(function(){
- a.animate({'top' : 0, 'right' : 0}, 600);
- }, delay_2);
- delay_2 += 50;
- });
- slide.show();
- }, delay + 400);
- }
- // next
- div.find('.thumbnail-controls a.next').click(function(){
- div.find('.thumbnail-controls a.prev').css({opacity : 1});
- if(!div.find('.slide[data-i="'+(i+1)+'"]').exists())
- {
- return false;
- }
- fly("right");
- if(!div.find('.slide[data-i="'+(i+1)+'"]').exists())
- {
- div.find('.thumbnail-controls a.next').css({opacity : 0.25});
- }
- });
- // prev
- div.find('.thumbnail-controls a.prev').click(function(){
- div.find('.thumbnail-controls a.next').css({opacity : 1});
- if(!div.find('.slide[data-i="'+(i-1)+'"]').exists())
- {
- return false;
- }
- fly("left");
- if(!div.find('.slide[data-i="'+(i-1)+'"]').exists())
- {
- div.find('.thumbnail-controls a.prev').css({opacity : 0.25});
- }
- });
- div.find('.thumbnail-controls a.prev').css({opacity : 0.25});
- }
- /*--------------------------------------------------------------------------------------------
- *
- * Scroll to
- *
- *--------------------------------------------------------------------------------------------
- $('a#download-case-study').live('click', function(){
- var id = $(this).attr('href');
- var y = $(id).offset().top - 50;
- $('body, html').stop().animate({scrollTop : y}, 500);
- return false;
- });
- */
- /*--------------------------------------------------------------------------------------------
- *
- * setup_header
- *
- *--------------------------------------------------------------------------------------------*/
- function setup_header()
- {
- // vars
- var div = $('#header');
- var toolbar_toggle = div.find('#toolbar-toggle');
- var toolbox = $('#header-toolbox');
- var i = 0;
- // toolbar toggle
- toolbar_toggle.find('a:not(.support-link)').click(function(){
- var new_i = parseInt($(this).attr('data-i'));
- if(new_i == i)
- {
- console.log('new_i == i');
- // if open, close div
- $(this).removeClass('active');
- toolbox.children('.mask').stop().animate({height : 'toggle'}, 250);
- i = 0;
- return false;
- }
- else if(i == 0)
- {
- // open up toolbox
- toolbox.find('.content').hide();
- toolbox.find('.content[data-i="'+new_i+'"]').show();
- toolbox.children('.mask').stop().animate({height : 'toggle'}, 250);
- $(this).addClass('active');
- i = new_i;
- }
- else
- {
- console.log('else');
- // change toolbox content
- toolbox.find('.content[data-i="'+new_i+'"]').show();
- var h = toolbox.find('.content[data-i="'+new_i+'"]').outerHeight();
- toolbox.find('.content[data-i="'+new_i+'"]').hide();
- toolbox.children('.mask').stop().animate({height : h}, 250, function(){
- $(this).css({height : 'auto'});
- });
- // fade out old
- toolbox.find('.content[data-i="'+i+'"]').animate({opacity : 0}, 250, function(){
- $(this).css({opacity : 1, display : 'none'});
- toolbox.find('.content[data-i="'+new_i+'"]').show();
- });
- toolbar_toggle.find('a[data-i="'+i+'"]').removeClass('active');
- $(this).addClass('active');
- i = new_i;
- }
- return false;
- });
- // dropdown
- var dropdown;
- var stop_hide = false;
- $('#nav li a[data-i]').live('mouseenter', function(){
- stop_hide = true;
- var new_i = $(this).attr('data-i');
- if(!$('#subnavs .subnav.'+new_i).exists())
- {
- return false;
- }
- // if a dropdown is already active, dont animate
- if(dropdown != null)
- {
- if(dropdown.hasClass(new_i))
- {
- return false;
- }
- // hide old dropdown
- dropdown.css({
- display : 'none'
- });
- dropdown = null;
- // load new dropdown
- dropdown = $('#subnavs .subnav.'+new_i);
- show_dropdown(false);
- }
- else
- {
- dropdown = $('#subnavs .subnav.'+new_i);
- show_dropdown();
- }
- }).mouseleave(function(){
- stop_hide = false;
- setTimeout(function(){
- if(!stop_hide)
- {
- hide_dropdown();
- }
- }, 250);
- });
- // sub nav mouse enter
- $('#subnavs .subnav').live('mouseenter', function(){
- // you just rolled onto the subnav, dont hide it
- stop_hide = true;
- });
- // sub nav mouse leave
- $('#subnavs .subnav').live('mouseleave', function(){
- stop_hide = false;
- setTimeout(function(){
- if(!stop_hide)
- {
- hide_dropdown();
- }
- }, 50);
- });
- function show_dropdown(animation)
- {
- // vars
- var speed = (animation == false) ? 0 : 250;
- if(dropdown == null) return false;
- //console.log('show_dropdown');
- // clear the previous hover stuff
- dropdown.unbind('mouseenter').unbind('mouseleave');
- // animate in dropdown
- dropdown.stop().css({
- top : -10,
- display : 'block',
- opacity : 0
- }).animate({
- top : 0,
- opacity : 1
- }, speed);
- }
- function hide_dropdown()
- {
- if(dropdown == null) return false;
- //console.log('hide_dropdown');
- // animate in dropdown
- dropdown.animate({
- top : 20,
- opacity : 0
- }, 50, function(){
- $(this).css({
- display : 'none'
- });
- });
- dropdown = null;
- }
- // hover on map
- toolbox.find('#search-map a').hover(function(){
- $(this).parent().attr('class', $(this).attr('class'));
- toolbox.find('#search-map-location').html($(this).attr('data-location'));
- }, function(){
- $(this).parent().attr('class', '');
- toolbox.find('#search-map-location').html('');
- });
- // tool tips
- toolbar_toggle.find('li').hover(function(){
- $(this).stop().find('.tool-tip').css({
- display : 'block',
- opacity : 0,
- 'margin-top' : '5px'
- }).animate({
- opacity : 1,
- 'margin-top' : '0px'
- }, 250);
- }, function(){
- $(this).stop().find('.tool-tip').css({
- opacity : 1,
- 'margin-top' : '0px'
- }).animate({
- opacity : 0,
- 'margin-top' : '5px'
- }, 250);
- });
- }
- /*--------------------------------------------------------------------------------------------
- *
- * define_page_side_height
- *
- *--------------------------------------------------------------------------------------------*/
- function define_page_side_height()
- {
- if(!$('#page-side').exists())
- {
- return false;
- }
- var side = $('#page-side').height();
- var main = $('#page-main').height();
- if(side > main){
- $('#page-side').addClass('shorter');
- }
- }
- /*--------------------------------------------------------------------------------------------
- *
- * setup_event_category_graph
- *
- *--------------------------------------------------------------------------------------------*/
- function setup_event_category_graph()
- {
- var div = $('#event-category-graph');
- var max = 0;
- // find max
- div.find('.count').each(function(){
- var new_max = parseFloat($(this).html());
- if(new_max > max)
- {
- max = new_max;
- }
- });
- // set heights
- div.find('.count').each(function(i){
- var bar = $(this).siblings('.bar');
- var new_max = parseFloat($(this).html());
- var percent = (new_max / max) * 179;
- bar.css({height : 0});
- setTimeout(function(){
- bar.animate({height : percent}, 500);
- }, 100 * i);
- //$(this).siblings('.bar').css({ height : percent + '%'});
- });
- }
- function setup_galleries(){
- if(!$('.photo-tiles').exists())
- {
- return false;
- }
- var div = $('.photo-tiles');
- div.find('a.gallery').click(function(){
- var images = [];
- $(this).find('span[data-image_url]').each(function(){
- images.push($(this).attr('data-image_url'));
- });
- $.fancybox(images, {
- 'padding' : 0,
- 'transitionIn' : 'none',
- 'transitionOut' : 'none',
- 'type' : 'image',
- 'changeFade' : 0
- });
- return false;
- });
- }
- /*--------------------------------------------------------------------------------------------
- *
- * Calendar
- *
- *-------------------------------------------------------------------------------------------*/
- $('.calendar').find('.event').live('click', function(){
- window.location = $(this).attr('data-url');
- });
- $('.calendar').find('select').live('change', function(){
- window.location = $(this).val();
- });
- /*--------------------------------------------------------------------------------------------
- *
- * document.ready
- *
- *--------------------------------------------------------------------------------------------*/
- $(document).ready(function()
- {
- setup_forms();
- setup_header();
- //define_page_side_height();
- });
- /*--------------------------------------------------------------------------------------------
- *
- * window.load
- *
- *--------------------------------------------------------------------------------------------*/
- $(window).load(function()
- {
- });
Raw Paste