(function ($) {
  Drupal.Panels = {};

  Drupal.Panels.autoAttach = function() {
    if ($.browser.msie) {
      // If IE, attach a hover event so we can see our admin links.
      $("div.panel-pane").hover(
        function() {
          $('div.panel-hide', this).addClass("panel-hide-hover"); return true;
        },
        function() {
          $('div.panel-hide', this).removeClass("panel-hide-hover"); return true;
        }
      );
      $("div.admin-links").hover(
        function() {
          $(this).addClass("admin-links-hover"); return true;
        },
        function(){
          $(this).removeClass("admin-links-hover"); return true;
        }
      );
    }
  };

  $(Drupal.Panels.autoAttach);
})(jQuery);
;
/* $Id*/

/**
 * @file
 * SAC JavaScript.
 */

(function ($) {

// Our namespace.
Drupal.SACShowcase = Drupal.SACShowcase || {};

// A place to cache images and videos.
Drupal.SACShowcase.ContentCache = new Array();

// Store the currenlty selected item.
Drupal.SACShowcase.CurrentItem = 0;
Drupal.SACShowcase.NextItem = 1;

// The rotation speed
Drupal.SACShowcase.RotationSpeed = 10000;

/**
 *  Attach behahior to showcase thumbnails that loads the full content into the
 *  main panel content area.
 */
Drupal.behaviors.SACShowcase = {
	attach: function (context, settings) {
  $('.pane-case-study-highlights-panel-pane-2 .view-content a', context).once( function () {

  	// Store the index.
  	var index = parseInt($(this).parents('td').attr('class').substring(4, 5)) -1;
  	
    // Attach a click handler to the link that fetches the main content.
    $(this).click(function(e) {
    	
    	// Reset the rotation timer if we came from a user click.
    	if (e.cancelable === true) {
    	  clearInterval(Drupal.SACShowcase.loadInterval);
    	  Drupal.SACShowcase.loadInterval = setInterval(Drupal.SACShowcase.RotateShowcase, Drupal.SACShowcase.RotationSpeed);
      }
    
      // Remove the default click handler.
    	e.preventDefault();
    	
    	// The path to load
    	var toLoad = $(this).attr('href');
    	
      // Slide the current content out the way
      $('.pane-case-study-highlights-panel-pane-1 .pane-content').hide('slide', {direction: 'right', easing: 'swing'}, 200);
      
    	// Load the content from cache, or an ajax request.
      if (Drupal.SACShowcase.ContentCache[toLoad]) {
      	
      	// Update the index count.
      	Drupal.SACShowcase.CurrentItem = index;
      	Drupal.SACShowcase.NextItem = index+1;
      	
      	// Show the cached content
      	Drupal.SACShowcase.UpdateShowcase(Drupal.SACShowcase.ContentCache[toLoad]);
      }
      else {
        // Make an AJAX call to load the new showcase content.
        $.ajax({
          type: 'GET',
          url: '/sac_showcase/ajax/node', // Which url should be handle the ajax request. This is a callback that loads our node view.
          success: function(data, textStatus, XMLHttpRequest) {

            // Update the index count.
          	Drupal.SACShowcase.CurrentItem = index;
          	Drupal.SACShowcase.NextItem = index+1;
            
            // cache the result.
            Drupal.SACShowcase.ContentCache[toLoad] = data;

            // Update the display.
            Drupal.SACShowcase.UpdateShowcase(data);
	        },
	        dataType: 'json', //define the type of data that is going to get back from the server
	        data: 'path='+toLoad //Pass a key/value pair
	      });
      }
    });

    // We attach the hover effect to the image's load event, to ensure that
    // webkit browsers are able to calculate the width an height properly.
  	$(this).find('img').load(function() {
    	var width = $(this).width();
    	var height = $(this).height();

      // Attach a hover handler to the image, to animate it.
      $(this).hover(function() {
      	$(this).css({'z-index' : '10'}) /*Add a higher z-index value so this image stays on top*/ 
      	  .animate({
      			marginTop: '-5px',
      			width: width+10, /* Set new width */
      			height: height+10, /* Set new height */
      		}, 100); /* this value of "200" is the speed of how fast/slow this hover animates */

      	} , function() {
      	$(this).css({'z-index' : '0'}) /* Set z-index back to 0 */
      	  .animate({
      			marginTop: '0',
      			width: width, /* Set width back to default */
      			height: height, /* Set height back to default */
      		}, 250);
      });
      
  	}); 
    
  });
  }
};

/**
 *  Automatically cycle through items.
 */
Drupal.behaviors.SACShowcaseCycle = {
  attach: function (context, settings) {
	$('.pane-case-study-highlights-panel-pane-2 .view-content', context).once( function () {
		
		// The number of items.
		Drupal.SACShowcase.itemCount = $('.pane-case-study-highlights-panel-pane-2 .view-content', context).find('a').size();
		
		// Start thge timer
		//Drupal.SACShowcase.loadInterval = setInterval(Drupal.SACShowcase.RotateShowcase, Drupal.SACShowcase.RotationSpeed);
	});
  }
};


/*---- UTILITY ----- */

/**
 * This function will get exceuted after the ajax request is completed successfully
 */
Drupal.SACShowcase.UpdateShowcase = function(data) {
	$('.pane-case-study-highlights-panel-pane-1 .pane-content')
	.html(data)
	.show('slide', {direction: 'left', easing: 'swing'}, 200);
};

/**
 * This function will get exceuted after the ajax request is completed successfully
 */
Drupal.SACShowcase.RotateShowcase = function() {

	// The initial next item.
	var nextItem = Drupal.SACShowcase.NextItem;
	
	// Work out what the next item should be.
	if (Drupal.SACShowcase.NextItem == Drupal.SACShowcase.itemCount) {
	  nextItem = 0;
  }
	else {
		nextItem = Drupal.SACShowcase.NextItem;
	}

	// Switch to the next item.
	$('.pane-case-study-highlights-panel-pane-2 .view-content').find('a:eq('+nextItem+')').click();
};


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

$(document).ready(function() {

  // Accepts a string; returns the string with regex metacharacters escaped. The returned string
  // can safely be used at any point within a regex to match the provided literal string. Escaped
  // characters are [ ] { } ( ) * + ? - . , \ ^ $ # and whitespace. The character | is excluded
  // in this function as it's used to separate the domains names.
  RegExp.escapeDomains = function(text) {
    return (text) ? text.replace(/[-[\]{}()*+?.,\\^$#\s]/g, "\\$&") : '';
  }

  // Attach onclick event to document only and catch clicks on all elements.
  $(document.body).click(function(event) {
    // Catch the closest surrounding link of a clicked element.
    $(event.target).closest("a,area").each(function() {

      var ga = Drupal.settings.googleanalytics;
      // Expression to check for absolute internal links.
      var isInternal = new RegExp("^(https?):\/\/" + window.location.host, "i");
      // Expression to check for special links like gotwo.module /go/* links.
      var isInternalSpecial = new RegExp("(\/go\/.*)$", "i");
      // Expression to check for download links.
      var isDownload = new RegExp("\\.(" + ga.trackDownloadExtensions + ")$", "i");
      // Expression to check for the sites cross domains.
      var isCrossDomain = new RegExp("^(https?|ftp|news|nntp|telnet|irc|ssh|sftp|webcal):\/\/.*(" + RegExp.escapeDomains(ga.trackCrossDomains) + ")", "i");

      // Is the clicked URL internal?
      if (isInternal.test(this.href)) {
        // Is download tracking activated and the file extension configured for download tracking?
        if (ga.trackDownload && isDownload.test(this.href)) {
          // Download link clicked.
          var extension = isDownload.exec(this.href);
          _gaq.push(["_trackEvent", "Downloads", extension[1].toUpperCase(), this.href.replace(isInternal, '')]);
        }
        else if (isInternalSpecial.test(this.href)) {
          // Keep the internal URL for Google Analytics website overlay intact.
          _gaq.push(["_trackPageview", this.href.replace(isInternal, '')]);
        }
      }
      else {
        if (ga.trackMailto && $(this).is("a[href^=mailto:],area[href^=mailto:]")) {
          // Mailto link clicked.
          _gaq.push(["_trackEvent", "Mails", "Click", this.href.substring(7)]);
        }
        else if (ga.trackOutbound && this.href) {
          if (ga.trackDomainMode == 2 && isCrossDomain.test(this.href)) {
            // Top-level cross domain clicked. document.location is handled by _link internally.
            _gaq.push(["_link", this.href]);
          }
          else if (ga.trackOutboundAsPageview) {
            // Track all external links as page views after URL cleanup.
            // Currently required, if click should be tracked as goal.
            _gaq.push(["_trackPageview", '/outbound/' + this.href.replace(/^(https?|ftp|news|nntp|telnet|irc|ssh|sftp|webcal):\/\//i, '').split('/').join('--')]);
          }
          else {
            // External link clicked.
            _gaq.push(["_trackEvent", "Outbound links", "Click", this.href]);
          }
        }
      }
    });
  });
});

})(jQuery);
;

