/* Author: 

*/

/*
        fontScaler Widget
*/
/*  
  $.ctrl = function(key, callback, args) {
    $(document).keydown(function(e) {
      if(!args) args=[]; // IE barks when args is null
      if(e.keyCode == key.charCodeAt(0) && e.ctrlKey) {
        callback.apply(this, args);
        //return false;
        return true;
       }
    });
  };

  $(document).ready(function(){
  
    var decreaseBtn = $("<a/>", {
      "class": "decrease",
      href: "#",
      text: "A-",
      title: "decrease text size"
    });
    
    var resetBtn = $("<a/>", {
      "class": "reset",
      href: "#",
      text: "|",
      title: "reset text size"
    });
    
    var increaseBtn = $("<a/>", {
      "class": "increase",
      href: "#",
      text: "A+",
      title: "increase text size"
    });
    
    $(".fontScaler").append(decreaseBtn);
    $(".fontScaler").append("&nbsp;");
    $(".fontScaler").append(resetBtn);
    $(".fontScaler").append("&nbsp;");
    $(".fontScaler").append(increaseBtn);
    
    var scalerOptions = {
      unit:"percent",
      increment:10,
      useCookie:true,
      cookieName:'fontscale',
      cookieParams:{
      expires:null, // default 30
      path:"/"},
      adjustLeading:false};
  
    var scalerSettings = $.extend( $.fn.fontscale.defaults, scalerOptions);
    
    $(".fontScaler .decrease").fontscale("body","down", scalerOptions);  
    $(".fontScaler .reset").fontscale("body","reset");
    $(".fontScaler .increase").fontscale("body","up", scalerOptions);
  
    //on key 'ctrl' + '0', reset fontScale, then execute default browser behaviour
  
    $.ctrl('0', function() {
      $.fn.fontscale.reset( "body", scalerSettings );
    });
  
  });
*/

  
    $(document).ready(function(){
      $("ul.sf-menu").superfish({
        pathClass:  'branch',
        animation: {opacity:'show',height:'show'},   // slide-down effect with fade-in
        delay:     2000               // 1.2 second delay on mouseout
      });
    });

    $(document).ready(function(){
      // match height of scrolling tenants widget to teasers widget on home page
      var $tenants = $(".tenants.scrolling.widget").eq(0);
      var $teasers = $(".teasers.widget").eq(0);
      
      if ($tenants.length == 1 && $teasers.length ==1) {
        var $tenantsScroller = $tenants.find(".scroller").eq(0);
        var $tenantsBox= $tenants.find(".box-content").eq(0);
      
        var boxTop = $tenantsBox.offset().top;
        var boxBottom = boxTop + $tenantsBox.outerHeight();
      
        var scrollerTop = $tenantsScroller.offset().top;
        var scrollerBottom = scrollerTop + $tenantsScroller.outerHeight();
      
        var boxPadding = boxBottom - scrollerBottom;
        var teaserBase = $teasers.offset().top + $teasers.outerHeight();
      
        var top = $tenantsScroller.offset().top;
        var scrollerHeight = teaserBase - (scrollerTop + boxPadding);
      
        $tenantsScroller.css("max-height",scrollerHeight);
      }
    });      
      
$(document).ready(function(){
  /*
  var showCaptions = $(".imageGallery").metadata({type:'elem',name:'script'}).showCaptions;
  //window.log("showCaptions: " + showCaptions);
  if (showCaptions == "0") {
    window.log("removing captions...");
    $(".imageGallery a.thumbnail").removeAttr("title");
  }
  */
  /*
  var galleryName = $(".imageGallery").metadata({type:'elem',name:'script'}).galleryName;
  
  //var folderName = $(".imageGallery").metadata({type:'elem',name:'script'}).currentFolderName;
  */
  
  var $thumbnails = $("a.enlarge");
  if ($thumbnails.length > 1) {
    $thumbnails.attr("rel","prefetch['thumbnails']");
  }
  
  //remove all captions
  //$("a.thumbnail").removeAttr("title");
  //$("a.thumbnail").attr("title","");
  
  
  $("a.enlarge").prettyPhoto(
    {
      show_title: false, /* true/false */
      deeplinking: false, /* Allow prettyPhoto to update the url to enable deeplinking. */
      overlay_gallery: false, /* If set to true, a gallery will overlay the fullscreen image on mouse over */
      social_tools:false  /* html or false to disable */
    }
  );
  

});
 
/*
      Tabs
 */

$(document).ready(function(){  
  $(".tabs").accessibleTabs({
    tabhead:'h4',
    fx:"fadeIn"
  });
});  


  $(document).ready(function() {
    // Exhibition Slideshow Template (ajax)
          var slideTemplateAlias = "Slides";
          var slidesUrl = $(location).attr('pathname') + "/" + slideTemplateAlias;
          var $slideContainer = $('.slide-container');
            
          $(".slide-container .loading").ajaxStart(function(){
            //$(this).removeClass("hidden")
            $(this).show();
          });
          $(".slide-container .loading").ajaxStop(function(){
            $(this).hide();
          });
    
          $slideContainer.load(slidesUrl, function() {
            
            var $slidesList = $slideContainer.children('.exhibitionSlides');
            var $slides = $slidesList.children('.slide');
            
            $slides.each(function(index) {
              var $slide = $(this);
              var $thumbnails = $slide.find("a.enlarge");
              if ($thumbnails.length > 1) {
                $thumbnails.attr("rel",'prefetch[slide' + index + ']');
              }
            });
            
            $slideContainer.find("a.enlarge").prettyPhoto({
              show_title: false, // true/false
              deeplinking: false, // Allow prettyPhoto to update the url to enable deeplinking. 
              overlay_gallery: false, // If set to true, a gallery will overlay the fullscreen image on mouse over 
              social_tools:false  // html or false to disable 
            });
            
            $slideContainer.slideshow();
            
          });
  });   

/*
  $(document).ready(function() {
        // Exhibition Slide List Template (slides in page - no ajax)
        // needs modifying for prettyphoto image galleries
        //$('.slide-list').slideshow();

  });
*/
/*
  $(document).ready(function() {
        // Exhibition Title Slide and Exhibition Slide Templates (no scrolling slideshow)
    var $singleSlide = $('.single-slide .slide');
    if ($singleSlide.length > 1) {
      var slideSettings = $singleSlide.metadata();

    $singleSlide.data("slideSettings", slideSettings);
       
            $('.audioControls').audioPlayer({
                "audioUrl": slideSettings.audioUrl,
                ended: function (event) {
                  // on ended
                }
            });

    }
  });
*/



