$ = jQuery;
(function(c){var a=c.scrollTo=function(f,e,d){c(window).scrollTo(f,e,d)};a.defaults={axis:"xy",duration:parseFloat(c.fn.jquery)>=1.3?0:1};a.window=function(d){return c(window)._scrollable()};c.fn._scrollable=function(){return this.map(function(){var e=this,d=!e.nodeName||c.inArray(e.nodeName.toLowerCase(),["iframe","#document","html","body"])!=-1;if(!d){return e}var f=(e.contentWindow||e).document||e.ownerDocument||e;return c.browser.safari||f.compatMode=="BackCompat"?f.body:f.documentElement})};c.fn.scrollTo=function(f,e,d){if(typeof e=="object"){d=e;e=0}if(typeof d=="function"){d={onAfter:d}}if(f=="max"){f=9000000000}d=c.extend({},a.defaults,d);e=e||d.speed||d.duration;d.queue=d.queue&&d.axis.length>1;if(d.queue){e/=2}d.offset=b(d.offset);d.over=b(d.over);return this._scrollable().each(function(){var l=this,j=c(l),k=f,i,g={},m=j.is("html,body");switch(typeof k){case"number":case"string":if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(k)){k=b(k);break}k=c(k,this);case"object":if(k.is||k.style){i=(k=c(k)).offset()}}c.each(d.axis.split(""),function(r,s){var t=s=="x"?"Left":"Top",v=t.toLowerCase(),q="scroll"+t,o=l[q],n=a.max(l,s);if(i){g[q]=i[v]+(m?0:o-j.offset()[v]);if(d.margin){g[q]-=parseInt(k.css("margin"+t))||0;g[q]-=parseInt(k.css("border"+t+"Width"))||0}g[q]+=d.offset[v]||0;if(d.over[v]){g[q]+=k[s=="x"?"width":"height"]()*d.over[v]}}else{var u=k[v];g[q]=u.slice&&u.slice(-1)=="%"?parseFloat(u)/100*n:u}if(/^\d+$/.test(g[q])){g[q]=g[q]<=0?0:Math.min(g[q],n)}if(!r&&d.queue){if(o!=g[q]){h(d.onAfterFirst)}delete g[q]}});h(d.onAfter);function h(n){j.animate(g,e,d.easing,n&&function(){n.call(this,f,d)})}}).end()};a.max=function(j,i){var h=i=="x"?"Width":"Height",e="scroll"+h;if(!c(j).is("html,body")){return j[e]-c(j)[h.toLowerCase()]()}var g="client"+h,f=j.ownerDocument.documentElement,d=j.ownerDocument.body;return Math.max(f[e],d[e])-Math.min(f[g],d[g])};function b(d){return typeof d=="object"?d:{top:d,left:d}}})(jQuery);jQuery.easing.jswing=jQuery.easing.swing;jQuery.extend(jQuery.easing,{def:"easeOutQuad",swing:function(e,f,a,h,g){return jQuery.easing[jQuery.easing.def](e,f,a,h,g)},easeInQuad:function(e,f,a,h,g){return h*(f/=g)*f+a},easeOutQuad:function(e,f,a,h,g){return -h*(f/=g)*(f-2)+a},easeInOutQuad:function(e,f,a,h,g){if((f/=g/2)<1){return h/2*f*f+a}return -h/2*((--f)*(f-2)-1)+a},easeInCubic:function(e,f,a,h,g){return h*(f/=g)*f*f+a},easeOutCubic:function(e,f,a,h,g){return h*((f=f/g-1)*f*f+1)+a},easeInOutCubic:function(e,f,a,h,g){if((f/=g/2)<1){return h/2*f*f*f+a}return h/2*((f-=2)*f*f+2)+a},easeInQuart:function(e,f,a,h,g){return h*(f/=g)*f*f*f+a},easeOutQuart:function(e,f,a,h,g){return -h*((f=f/g-1)*f*f*f-1)+a},easeInOutQuart:function(e,f,a,h,g){if((f/=g/2)<1){return h/2*f*f*f*f+a}return -h/2*((f-=2)*f*f*f-2)+a},easeInQuint:function(e,f,a,h,g){return h*(f/=g)*f*f*f*f+a},easeOutQuint:function(e,f,a,h,g){return h*((f=f/g-1)*f*f*f*f+1)+a},easeInOutQuint:function(e,f,a,h,g){if((f/=g/2)<1){return h/2*f*f*f*f*f+a}return h/2*((f-=2)*f*f*f*f+2)+a},easeInSine:function(e,f,a,h,g){return -h*Math.cos(f/g*(Math.PI/2))+h+a},easeOutSine:function(e,f,a,h,g){return h*Math.sin(f/g*(Math.PI/2))+a},easeInOutSine:function(e,f,a,h,g){return -h/2*(Math.cos(Math.PI*f/g)-1)+a},easeInExpo:function(e,f,a,h,g){return(f==0)?a:h*Math.pow(2,10*(f/g-1))+a},easeOutExpo:function(e,f,a,h,g){return(f==g)?a+h:h*(-Math.pow(2,-10*f/g)+1)+a},easeInOutExpo:function(e,f,a,h,g){if(f==0){return a}if(f==g){return a+h}if((f/=g/2)<1){return h/2*Math.pow(2,10*(f-1))+a}return h/2*(-Math.pow(2,-10*--f)+2)+a},easeInCirc:function(e,f,a,h,g){return -h*(Math.sqrt(1-(f/=g)*f)-1)+a},easeOutCirc:function(e,f,a,h,g){return h*Math.sqrt(1-(f=f/g-1)*f)+a},easeInOutCirc:function(e,f,a,h,g){if((f/=g/2)<1){return -h/2*(Math.sqrt(1-f*f)-1)+a}return h/2*(Math.sqrt(1-(f-=2)*f)+1)+a},easeInElastic:function(f,h,e,l,k){var i=1.70158;var j=0;var g=l;if(h==0){return e}if((h/=k)==1){return e+l}if(!j){j=k*0.3}if(g<Math.abs(l)){g=l;var i=j/4}else{var i=j/(2*Math.PI)*Math.asin(l/g)}return -(g*Math.pow(2,10*(h-=1))*Math.sin((h*k-i)*(2*Math.PI)/j))+e},easeOutElastic:function(f,h,e,l,k){var i=1.70158;var j=0;var g=l;if(h==0){return e}if((h/=k)==1){return e+l}if(!j){j=k*0.3}if(g<Math.abs(l)){g=l;var i=j/4}else{var i=j/(2*Math.PI)*Math.asin(l/g)}return g*Math.pow(2,-10*h)*Math.sin((h*k-i)*(2*Math.PI)/j)+l+e},easeInOutElastic:function(f,h,e,l,k){var i=1.70158;var j=0;var g=l;if(h==0){return e}if((h/=k/2)==2){return e+l}if(!j){j=k*(0.3*1.5)}if(g<Math.abs(l)){g=l;var i=j/4}else{var i=j/(2*Math.PI)*Math.asin(l/g)}if(h<1){return -0.5*(g*Math.pow(2,10*(h-=1))*Math.sin((h*k-i)*(2*Math.PI)/j))+e}return g*Math.pow(2,-10*(h-=1))*Math.sin((h*k-i)*(2*Math.PI)/j)*0.5+l+e},easeInBack:function(e,f,a,i,h,g){if(g==undefined){g=1.70158}return i*(f/=h)*f*((g+1)*f-g)+a},easeOutBack:function(e,f,a,i,h,g){if(g==undefined){g=1.70158}return i*((f=f/h-1)*f*((g+1)*f+g)+1)+a},easeInOutBack:function(e,f,a,i,h,g){if(g==undefined){g=1.70158}if((f/=h/2)<1){return i/2*(f*f*(((g*=(1.525))+1)*f-g))+a}return i/2*((f-=2)*f*(((g*=(1.525))+1)*f+g)+2)+a},easeInBounce:function(e,f,a,h,g){return h-jQuery.easing.easeOutBounce(e,g-f,0,h,g)+a},easeOutBounce:function(e,f,a,h,g){if((f/=g)<(1/2.75)){return h*(7.5625*f*f)+a}else{if(f<(2/2.75)){return h*(7.5625*(f-=(1.5/2.75))*f+0.75)+a}else{if(f<(2.5/2.75)){return h*(7.5625*(f-=(2.25/2.75))*f+0.9375)+a}else{return h*(7.5625*(f-=(2.625/2.75))*f+0.984375)+a}}}},easeInOutBounce:function(e,f,a,h,g){if(f<g/2){return jQuery.easing.easeInBounce(e,f*2,0,h,g)*0.5+a}return jQuery.easing.easeOutBounce(e,f*2-g,0,h,g)*0.5+h*0.5+a}});

/*
 * Viewport - jQuery selectors for finding elements in viewport
 *
 * Copyright (c) 2008-2009 Mika Tuupola
 *
 * Licensed under the MIT license:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * Project home:
 *  http://www.appelsiini.net/projects/viewport
 *
 */
(function($) {

    $.belowthefold = function(element, settings) {
        var fold = $(window).height() + $(window).scrollTop();
        return fold <= $(element).offset().top - settings.threshold;
    };

    $.abovethetop = function(element, settings) {
        var top = $(window).scrollTop();
        return top >= $(element).offset().top + $(element).height() - settings.threshold;
    };

    $.rightofscreen = function(element, settings) {
        var fold = $(window).width() + $(window).scrollLeft();
        return fold <= $(element).offset().left - settings.threshold;
    };

    $.leftofscreen = function(element, settings) {
        var left = $(window).scrollLeft();
        return left >= $(element).offset().left + $(element).width() - settings.threshold;
    };

    $.inviewport = function(element, settings) {
        var $element = $(element);
        var offset = $element.offset();

        var $window = $(window);
        var windowTop = $window.scrollTop();
        var threshold = settings.threshold;

        if (offset.top - threshold < windowTop) {
            if (offset.top + $element.height() + threshold >= windowTop) {
                // top edge below the window's top
            } else {
                return false;
            }
        } else {
            if (offset.top - threshold <= windowTop + $window.height()) {
                // bottom edge above the window's bottom
            } else {
                return false;
            }
        }

        var windowLeft = $window.scrollLeft();

        if (offset.left - threshold < windowLeft) {
            if (offset.left + $element.width() + threshold >= windowLeft) {
                // left edge be on the left side of the window's left edge
            } else {
                return false;
            }
        } else {
            if (offset.left - threshold <= windowLeft + $window.width()) {
                // right edge be on the right side of the window's right edge
            } else {
                return false;
            }
        }

        return true;
    };

    $.extend($.expr[':'], {
        "below-the-fold": function(a, i, m) {
            return $.belowthefold(a, {threshold : 0});
        },
        "above-the-top": function(a, i, m) {
            return $.abovethetop(a, {threshold : 0});
        },
        "left-of-screen": function(a, i, m) {
            return $.leftofscreen(a, {threshold : 0});
        },
        "right-of-screen": function(a, i, m) {
            return $.rightofscreen(a, {threshold : 0});
        },
        "in-viewport": function(a, i, m) {
            return $.inviewport(a, {threshold : 0});
        }
    });


})(jQuery);


var amountVisible=function(c)
{
  var a=$(window).scrollTop();
  var b=a+$(window).height();
  var e=c.offset().top;
  var d=e+c.height();
  if(d>=a&&d<b)
  {
    return d-a
  }
  else
  {
    return b-e
  }
};
var fetchMatchingNavItem=function(a)
{
  return $("#" + $(a).attr("id").replace('page', 'menu-item'));
};
var setCurrentClass=function(a)
{
  a.addClass("current_page_item");
  a.siblings("#menu li").removeClass("current_page_item")
};
var determineCurrentNodeAndSetNav=function()
{
  var a=null;
  var b=$(".page:in-viewport");
  b.each(function(c)
  {
    var d=$(this);
    if(a==null||amountVisible(d)>=amountVisible(a))
    {
      a=d
    }
  });
  current_index=$(".page").index(a);
  setCurrentClass(fetchMatchingNavItem(a))
};
$(document).ready(function()
{
  var c=$(".page");
  var b=0;
  var a;
  $(window).scroll(function()
  {
    determineCurrentNodeAndSetNav()
  });
  $("#menu a").click(function(d)
  {
    a = $("#" + $(this).parent().attr('id').replace('menu-item', 'page'));
    $.scrollTo(a, 800);
    b=c.index(a);
    d.preventDefault()
  });
  $(document).keydown(function(d)
  {
    switch(d.keyCode)
    {
      case 40:
        a=c[++b];
        if(a)
        {
          $.scrollTo(a,800)
        }
        else
        {
          b=c.length-1
        }
        break;
        
      case 38:
        a=c[--b];
        if(a)
        {
          $.scrollTo(a,800)
        }
        else
        {
          b=0
        }
        break
    }
  })
});
$(document).ready(function()
{
  $(".expansion").hide();
  $(".read-more li").click(function(d)
  {
    var a=$(this);
    var b=a.children().get(0).href.split("#")[1];
    var c=$("#"+b);
    if(c.is(":visible"))
    {
      a.removeClass("current");
      c.hide()
    }
    else
    {
      a.siblings().removeClass("current");
      a.addClass("current");
      c.siblings(".expansion").hide();
      c.show();
      $.scrollTo("#read-more",800)
    }
    determineCurrentNodeAndSetNav();d.preventDefault()
  });
  $('.fancybox').fancybox({overlayColor: '#000', overlayOpacity: .8, onStart: function(a,b,c,d,e,f,g,h,i)
  {
    $($(a).attr('href') + ' .video-link').flowplayer('/wp-content/themes/trapeze/js/flowplayer/flowplayer.commercial-3.2.7.swf',{ key: fpconf.defaults.key, clip: fpconf.defaults.clip,  canvas: fpconf.defaults.canvas, plugins: fpconf.defaults.plugins });
  }});
  $('#contactButton').click(function(event)
  {
    event.preventDefault();
    showContactBar();
  });

  $('.work-page-thumbnail a').hover(function()
  {
    dimImages($(this));
  },
  function()
  {
    showImages();
  });

});

showContactBar = function()
{
  h = 327;
  var contactBar = $('#contactBar');
  p = contactBar.parent();
  height = p.css('height') == '40px' ? '+='+h : '-='+h;

  p.animate({
      height: height
  }, 1000);
}

dimImages = function(el)
{
  $('.dim-images').css('display', 'block');
  $(el).find('.dim-images').css('display', 'none');
}

showImages = function()
{
  $('.dim-images').css('display', 'none');
}

var fpconf = {
  defaults:
  {
	key:'#@614079840592d51c87f',
    clip:
    {
      autoPlay:true,
	  bufferLength:"0",
      scaling: 'fit',
	  onBegin: function () {
      // ensure that play button is visible
      this.getPlugin("play").css({opacity: 1});
      },
       onBeforeFinish: function () {
       // hide replay button
      this.getPlugin("play").css({opacity: 0});
  }

    },
	play: 
	{
		url: 'images/play-btn.png',
		width: 60,
		height: 60
	},
	canvas:
    {
       backgroundGradient: "none",
       backgroundColor: "#000000"
    },
    plugins:
    {
      "controls":
      {
        "borderRadius":17,
        "buttonOffColor":
        "rgba(130,130,130,1)",
        "timeColor":"#ffffff",
        "stop":true,
        "bufferGradient":"none",
        "sliderColor":"#000000",
        "zIndex":1,
        "backgroundColor":"rgba(0, 0, 0, -1)",
        "scrubberHeightRatio":0.6,
        "volumeSliderGradient":"none",
        "tooltipTextColor":"#ffffff",
        "spacing":{"time":6,"volume":8,"all":2},
        "sliderGradient":"none",
        "timeBorderRadius":20,
        "timeBgHeightRatio":0.8,
        "volumeSliderHeightRatio":0.6,
        "progressGradient":"none",
        "height":25,
        "volumeColor":"rgba(242, 135, 12, 1)",
        "name":"controls",
        "timeSeparator":" ",
        "tooltips":{"marginBottom":5,"buttons":false},
        "volumeBarHeightRatio":0.2,
        "opacity":1,
        "timeFontSize":12,
        "left":"50pct",
        "tooltipColor":"rgba(0, 0, 0, 0)",
        "border":"0px",
        "bufferColor":"#a3a3a3",
        "volumeSliderColor":"#ffffff",
        "buttonColor":"#ffffff",
        "durationColor":"rgba(242, 135, 12, 1)",
        "autoHide":
        {
          "enabled":true,
          "hideDelay":500,
          "hideStyle":"fade",
          "mouseOutDelay":500,
          "hideDuration":400,
          "fullscreenOnly":true
        },
        "backgroundGradient":"none",
        "width":"100pct",
        "sliderBorder":"1px solid rgba(128, 128, 128, 0.7)",
        "display":"block",
        "buttonOverColor":"#df8418",
        "progressColor":"rgba(242, 135, 12, 1)",
        "timeBorder":"0px solid rgba(0, 0, 0, 0.3)",
        "timeBgColor":"rgb(0, 0, 0, 0)",
        "borderWidth":0,
        "scrubberBarHeightRatio":0.2,
        "bottom":"4pct",
        "volumeBorder":"1px solid rgba(128, 128, 128, 0.7)",
        "builtIn":false,
        "margins":[2,12,2,12]
      }
    }
  }
}

