
(function($) {

/**
 * Drupal FieldGroup object.
 */
Drupal.FieldGroup = Drupal.FieldGroup || {};
Drupal.FieldGroup.Effects = Drupal.FieldGroup.Effects || {};
Drupal.FieldGroup.groupWithfocus = null;

Drupal.FieldGroup.setGroupWithfocus = function(element) {
  element.css({display: 'block'});
  Drupal.FieldGroup.groupWithfocus = element;
}

/**
 * Implements Drupal.FieldGroup.processHook().
 */
Drupal.FieldGroup.Effects.processFieldset = {
  execute: function (context, settings, type) {
    if (type == 'form') {
      // Add required fields mark to any fieldsets containing required fields
      $('fieldset.fieldset').each(function(i){
        if ($(this).is('.required-fields') && $(this).find('.form-required').length > 0) {
          $('legend span.fieldset-legend', $(this)).eq(0).append('&nbsp;').append($('.form-required').eq(0).clone());
        }
        if ($('.error', $(this)).length) {
          $('legend span.fieldset-legend', $(this)).eq(0).addClass('error');
          Drupal.FieldGroup.setGroupWithfocus($(this));
        }
      });
    }
  }
}

/**
 * Implements Drupal.FieldGroup.processHook().
 */
Drupal.FieldGroup.Effects.processAccordion = {
  execute: function (context, settings, type) {
    var accordions = $('div.field-group-accordion-wrapper', context).accordion({
      autoHeight: false,
      active: 0,
      collapsible: true
    });
    if (type == 'form') {
      // Add required fields mark to any element containing required fields
      $('div.accordion-item').each(function(i){
        if ($(this).is('.required-fields') && $(this).find('.form-required').length > 0) {
          $('h3.ui-accordion-header').eq(i).append('&nbsp;').append($('.form-required').eq(0).clone());
        }
        if ($('.error', $(this)).length) {
          $('h3.ui-accordion-header').eq(i).addClass('error');
          var activeOne = $(this).parent().accordion("activate" , i);
          $('.ui-accordion-content-active', activeOne).css({height: 'auto', width: 'auto', display: 'block'});
        }
      });
    }
  }
}

/**
 * Implements Drupal.FieldGroup.processHook().
 */
Drupal.FieldGroup.Effects.processHtabs = {
  execute: function (context, settings, type) {
    if (type == 'form') {
      // Add required fields mark to any element containing required fields
      $('fieldset.horizontal-tabs-pane').each(function(i){
        if ($(this).is('.required-fields') && $(this).find('.form-required').length > 0) {
          $(this).data('horizontalTab').link.find('strong:first').after($('.form-required').eq(0).clone()).after('&nbsp;');
        }
        if ($('.error', $(this)).length) {
          $(this).data('horizontalTab').link.parent().addClass('error');
          Drupal.FieldGroup.setGroupWithfocus($(this));
          $(this).data('horizontalTab').focus();
        }
      });
    }
  }
}

/**
 * Implements Drupal.FieldGroup.processHook().
 */
Drupal.FieldGroup.Effects.processTabs = {
  execute: function (context, settings, type) {
    if (type == 'form') {
      // Add required fields mark to any fieldsets containing required fields
      $('fieldset.vertical-tabs-pane').each(function(i){
        if ($(this).is('.required-fields') && $(this).find('.form-required').length > 0) {
          $(this).data('verticalTab').link.find('strong:first').after($('.form-required').eq(0).clone()).after('&nbsp;');
        }
        if ($('.error', $(this)).length) {
          $(this).data('verticalTab').link.parent().addClass('error');
          Drupal.FieldGroup.setGroupWithfocus($(this));
          $(this).data('verticalTab').focus();
        }
      });
    }
  }
}

/**
 * Implements Drupal.FieldGroup.processHook().
 * 
 * TODO clean this up meaning check if this is really 
 *      necessary.
 */
Drupal.FieldGroup.Effects.processDiv = {
  execute: function (context, settings, type) {

    $('div.collapsible', context).each(function() {
      var $wrapper = $(this);

      // Turn the legend into a clickable link, but retain span.field-group-format-toggler
      // for CSS positioning.
      var $toggler = $('span.field-group-format-toggler:first', $wrapper);
      var $link = $('<a class="field-group-format-title" href="#"></a>');
      $link.prepend($toggler.contents()).appendTo($toggler);
      
      // .wrapInner() does not retain bound events.
      $link.click(function () {
        var wrapper = $wrapper.get(0);
        // Don't animate multiple times.
        if (!wrapper.animating) {
          wrapper.animating = true;
          var speed = $wrapper.hasClass('speed-fast') ? 300 : 1000;
          if ($wrapper.hasClass('effect-none') && $wrapper.hasClass('speed-none')) {
            $('> .field-group-format-wrapper', wrapper).toggle();
          }
          else if ($wrapper.hasClass('effect-blind')) {
            $('> .field-group-format-wrapper', wrapper).toggle('blind', {}, speed);
          }
          else {
            $('> .field-group-format-wrapper', wrapper).toggle(speed);
          }
          wrapper.animating = false;
        }
        return false;
      });
      
    });
  }
};

/**
 * Behaviors.
 */
Drupal.behaviors.fieldGroup = {
  attach: function (context, settings) {
    if (settings.field_group == undefined) {
      return;
    }
    $('body', context).once('fieldgroup-effects', function () {
      // Execute all of them.
      $.each(Drupal.FieldGroup.Effects, function (func) {
        // We check for a wrapper function in Drupal.field_group as 
        // alternative for dynamic string function calls.
        var type = func.toLowerCase().replace("process", "");
        if (settings.field_group[type] != undefined && $.isFunction(this.execute)) {
          this.execute(context, settings, settings.field_group[type]);
        }
      });
    });
  }
};

})(jQuery);;
// Class for home page images
// Take images and convert them to canvas.
// For IE8 Support make sure excanvas.js is in use, http://code.google.com/p/explorercanvas/

// usage: CycleImage($('target'), 0.5, true);


function CycleImage(Target, Scale, Desaturate, IE) {
	if(Scale == null) Scale = 1.0;
	if(Desaturate == null) Desaturate = false;
	if(IE == null) IE = false;
	
	this.ie = IE;

	this.animation_steps = 15;	// How many times to update scale during animation. Sort of like resolution...
	this.target = Target[0];
	this.img_path = '';
	
	if(this.ie == false) {
		this.canvas = document.createElement('canvas');	
		this.context = this.canvas.getContext('2d');
		this.image_data = new Image();
		this.image_desaturated = new Image();
		this.original_image = new Image();
	}
	
	this.original_height;
	this.original_width;
	this.current_scale = 1;
	this.animation_speed;
	this.animation_interval;
	this.animation_final_scale;
	this.animation_step_count = 0;
	
	this.init(Scale, Desaturate);
}

CycleImage.prototype.init = function(scale, desaturate) {														// Create canvas object in target
	if(this.ie == false) {
		this.target.appendChild(this.canvas);
	}
	this.drawImage(scale, desaturate);
	this.scale(scale);
	if(desaturate) {
		this.desaturate();
	}
}

CycleImage.prototype.drawImage = function() {
	var img = this.target.getElementsByTagName('img')[0];
	if(this.ie == false) {
		this.img_path = img.getAttribute('src');
		this.original_image = img;
		this.canvas.setAttribute('width', img.width);
		this.canvas.setAttribute('height', img.height);
		this.context.drawImage(img, 0, 0);
		this.target.removeChild(img);
	}
	this.original_width = img.width;
	this.original_height = img.height;
}

CycleImage.prototype.setDepth = function(val) {
	this.target.style.zIndex = val;
}

CycleImage.prototype.setOffset = function(val) {
	this.target.style.marginLeft = val;
}

CycleImage.prototype.scale = function(val) {
	if(this.ie == false) {
		var y = this.canvas.height - (this.original_image.height * val);
		this.context.save();
		this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
		this.context.scale(val, val);
		this.context.drawImage(this.original_image, 0, y / val);
		this.context.restore();
	} else {
		this.target.getElementsByTagName('img')[0].setAttribute('width', this.original_width * val);
		this.target.getElementsByTagName('img')[0].setAttribute('height', this.original_height * val);
	}
	this.current_scale = val;
}

CycleImage.prototype.animate = function(val, speed) {
	clearInterval(this.animation_interval);
	this.animation_speed = speed / this.animation_steps;
	this.animation_final_scale = val;
	var inc = val / this.animation_steps;
	
	var scope = this;
	
	
	this.animation_interval = setInterval(function() {
		var step = scope.current_scale + scope.animation_step_count * inc;
		if(step < scope.animation_final_scale) {
			scope.scale(step);
			scope.desaturate();
			scope.animation_step_count++;
		} else {
			scope.scale(scope.animation_final_scale);
			clearInterval(scope.animation_interval);
			scope.animation_step_count = 0;
			scope.desaturate();
		}
	}, this.animation_speed);
}

CycleImage.prototype.desaturate = function() {
	if(this.ie == false) {
		this.image_desaturated = this.context.getImageData(0, 0, this.canvas.width, this.canvas.height);
		for(var y = 0; y < this.image_desaturated.height; y++) {
			for(var x = 0; x < this.image_desaturated.width; x++) {
				var i = (y * 4) * this.image_desaturated.width + x * 4;
				var avg = (this.image_desaturated.data[i] + this.image_desaturated.data[i + 1] + this.image_desaturated.data[i + 2]) / 3;
				this.image_desaturated.data[i] = avg;
				this.image_desaturated.data[i + 1] = avg;
				this.image_desaturated.data[i + 2] = avg;
			}
		}
		this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
		this.context.putImageData(this.image_desaturated, 0, 0);
	} else {
		//this.target.getElementsByTagName('img')[0].style.filter = 'progid:DXImageTransform.Microsoft.BasicImage(grayScale=1)';
	}
}

CycleImage.prototype.saturate = function() {
	if(this.ie == false) {
		this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
		this.context.drawImage(this.original_image, 0, 0);
	} else {
	//	this.target.getElementsByTagName('img')[0].style.filter = 'progid:DXImageTransform.Microsoft.BasicImage(grayScale=0)';
	}
};
// Class for home page image slider

function CycleCanvas(Images) {
	this.position = 0;															// current active image
	this.percents = [1.0, 0.9, 0.8, 0.7, 0.6];									// % for scaling down images
	this.bottom_z = 100;														// base z-index for depth calculatio
	this.animation_speed = 600;													//
	this.offset = -50;															// value used to space images
	this.images_source = Images;												// all elements in slider
	this.images = [];															// will store html5 canvas images
	this.init()
}

CycleCanvas.prototype.init = function() {										// Initialize object
	this.getImages();
	this.setPositions();
	this.setDepths();
}

CycleCanvas.prototype.getImages = function() {									// Initial placement of images. First on top of second, so on.
	var count = 0;
	var scope = this;	
	this.images_source.each(function() {										// Store each image object into array
		if(count > 0) {				
			var img = new CycleImage($(this), scope.percents[count], true, $.browser.msie);
		} else {
			var img = new CycleImage($(this), scope.percents[count], false, $.browser.msie);
		}
		scope.images.push(img);
		count++;
	});
}

CycleCanvas.prototype.setDepths = function() {
	this.images.reverse();
	for(var i = 0; i < this.images.length; i++) {
		this.images[i].setDepth(this.bottom_z + i);
	}
	this.images.reverse();
}

CycleCanvas.prototype.setPositions = function() {
	for(var i = 0; i < this.images.length; i++) {
		var margin = this.offset * i + 'px';
		this.images[i].setOffset(margin);
	}
}

CycleCanvas.prototype.nextImage = function() {
	if(this.position != this.images.length-1) {
		this.position++;
	} else {
		this.position = 0;
	}
	for(var i = 0; i < this.images.length; i++) {
		var m = parseFloat($(this.images[i].target).css('margin-left').replace('px', ''));
		if(i == this.position - 1) {
			$(this.images[i].target).animate({ 'margin-left': m - this.offset, opacity: 0 },  this.animation_speed);
		} else {
			$(this.images[i].target).animate({ 'margin-left': m - this.offset },  this.animation_speed);
		}
	}
	for(i = this.images.length-1; i > this.position; i--) {
		var new_scale = this.percents[i - this.position];
		this.images[i].animate(new_scale, this.animation_speed);
	}
	this.images[this.position].saturate();
}

CycleCanvas.prototype.prevImage = function() {
	if(this.position != 0) {
		this.position--;
	} else {
		this.position = this.images.length-1;
	}
	for(var i = 0; i < this.images.length; i++) {
		var m = parseFloat($(this.images[i].target).css('margin-left').replace('px', ''));
		if(i == this.position) {
			$(this.images[i].target).animate({ 'margin-left': m + this.offset, opacity: 1 },  this.animation_speed);
		} else {
			$(this.images[i].target).animate({ 'margin-left': m + this.offset },  this.animation_speed);
		}
	}
	for(i = this.images.length-1; i > this.position; i--) {
		var new_scale = this.percents[i - this.position];
		this.images[i].animate(new_scale, this.animation_speed);
	}
};
var image_cycle,
 	intro_timeout,
	people_position = 0,
	can_animate = 1;
	
	
function getInternetExplorerVersion()
// Returns the version of Windows Internet Explorer or a -1
// (indicating the use of another browser).
{
   var rv = -1; // Return value assumes failure.
   if (navigator.appName == 'Microsoft Internet Explorer')
   {
      var ua = navigator.userAgent;
      var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
      if (re.exec(ua) != null)
         rv = parseFloat( RegExp.$1 );
   }
   return rv;
}


// Cookie action for homepage intro
var cookieLifeSpanInMinutes = 5;
var cookie_name = 'homepage_view_intro_test_03';

// Create cookie to store data client side
function createCookie(name,value,minutes) {
	if (minutes) {
		var date = new Date();
		date.setTime(date.getTime()+(minutes*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

// Read value of cookie
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

// Remove value of cookie
function eraseCookie(name) {
	createCookie(name,"",-1);
}

jQuery(document).ready(function() {												// Make rocket go now
	$('.homepage-cycle .view-content').cycle({
		containerResize: false,
		timeout: 0,
		prev: '.cycle-prev',
		next: '.cycle-next',
		before: function() {
		},
		after: function() {
			can_animate = 1;
		},
		manualTrump: false
	});
	createBackgroundDivs();
	loadPeopleImages();
	if(readCookie(cookie_name) != 'true') {
		createCookie(cookie_name,'true',cookieLifeSpanInMinutes);
		$('.homepage-intro').show();
		$('#intro-close').click(function(e) {
			e.preventDefault();
			hideHomepageIntro();
		});
		$('.region-homepage-cycle').hide();
		intro_timeout = setTimeout(hideHomepageIntro, 9000);
	} else {
		hideHomepageIntro();
	}
	//$('.region-homepage-cycle').hide();
	
	// PNG fix?
	if (getInternetExplorerVersion() != -1) {
		var i;
		for (i in document.images) {
		    if (document.images[i].src) {
		        var imgSrc = document.images[i].src;
		        if (imgSrc.substr(imgSrc.length-4) === '.png' || imgSrc.substr(imgSrc.length-4) === '.PNG') {
		            document.images[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',sizingMethod='crop',src='" + imgSrc + "')";
		        }
		    }
		}
	}
});

jQuery(window).load(function() {
	image_cycle = new CycleCanvas($('.homepage-cycle-image .person-image'));
});

jQuery(window).resize(function() {
      checkWindowWidth();
});

function loadPeopleImages() {
	var person = $('<div />', {
			className: 'person'
		});
	var person_desat = $('<img />', { 
			className: 'desaturated'
		});
	var person_sat = $('<img />', { 
			className: 'saturated'
		});
	
	var people = ['frances-harper', 'william-goodridge', 'thaddeus-stevens', 'basil-biggs', 'sarah-mckim'];
	
	$.each(people, function(index, value) {
		var thisPerson = person.clone(),
			thisPerson_desat = person_desat.clone(),
			thisPerson_sat = person_sat.clone();
			
		thisPerson_desat.attr('src', '/sites/all/themes/default/img/' + people[index] + '-des.png');
		thisPerson_sat.attr('src', '/sites/all/themes/default/img/' + people[index] + '.png');
		
		thisPerson.append(thisPerson_desat).append(thisPerson_sat);
		
		thisPerson.addClass('front-'+index);
				// 
				// thisPerson.css({
				// 	zIndex: 5-index,
				// 	left: 100 + ((index * 50) * -1)
				// });
		
		$('#people_cycle').append(thisPerson);
		
		if(index == 0) {
			$('#people_cycle .front-0.saturated').show();
		}
	});
	
	prevNextPeopleActions();
}

function prevNextPeopleActions() {
	var person = $('<div />', {
			className: 'person'
		});
		
	var anim_speed = 450;
		
		
	$('.cycle-prev').click(function() {
			if (can_animate) {
				can_animate = 0;
				// Hide the last person
				$('.front-4').addClass('tele').switchClass('.front-4','rear-fade', anim_speed/2);

				// Transition the remaining
				$('.front-3').switchClass('front-3', 'front-4', anim_speed); 
				$('.front-2').switchClass('front-2', 'front-3', anim_speed);  
				$('.front-1').switchClass('front-1', 'front-2', anim_speed); 
				$('.front-0').switchClass('front-0', 'front-1', anim_speed);
		
				// Create a new person div and stick the last person in the front position.
				thisPerson = person.clone();
				thisPerson.addClass('front-0 newperson').append($('.tele').html());
				thisPerson.animate({opacity: 0},0);
				$('#people_cycle').prepend(thisPerson);
				setTimeout(function(){ $('.newperson').animate({opacity: 1}, anim_speed, function() {
					$('.tele').remove();
					$(this).removeClass('newperson').attr('style','');
				}) },anim_speed+1);			
			}
	});
	
	$('.cycle-next').click(function() {
			if (can_animate) {
				can_animate = 0;
				// Hide the front person
				$('.front-0').addClass('tele').switchClass('.front-0','front-fade', anim_speed/2);
				$('.front-1 .saturated').css('display', 'block');
				// Transition the remaining
				$('.front-1').switchClass('front-1', 'front-0', anim_speed); 
				$('.front-2').switchClass('front-2', 'front-1', anim_speed);  
				$('.front-3').switchClass('front-3', 'front-2', anim_speed);  
				$('.front-4').switchClass('front-4', 'front-3', anim_speed);  
		
				// Create a new person div and stick the first person in the last position.
				thisPerson = person.clone();
				thisPerson.addClass('front-4 newperson').append($('.tele').html());
				thisPerson.animate({opacity: 0},0);
				$('#people_cycle').append(thisPerson);
				setTimeout(function(){ $('.newperson').animate({opacity: 1}, anim_speed, function() {
					$('.tele').remove();
					$(this).removeClass('newperson').attr('style','');
					$('.saturated').attr('style','');
				}) },anim_speed+1);	
			}
			
	});
}



function createBackgroundDivs() {
	var ie_mod = '',
		ie_style = '';
	if(getInternetExplorerVersion() != -1) {
		ie_mod = '-ie';
		if(getInternetExplorerVersion() != 7)
			ie_style = 'max-width: 1600px;';
	}
	var homepage_backgrounds = [
		'<div id="bg-1" style="background: url(/sites/all/themes/default/img/home-header-bg-1'+ie_mod+'.jpg) 50% 0 repeat-x;'+ie_style+'"></div>',
		'<div id="bg-2" style="background: url(/sites/all/themes/default/img/home-header-bg-2'+ie_mod+'.jpg) 50% 0 repeat-x;'+ie_style+'"></div>',
		'<div id="bg-3" style="background: url(/sites/all/themes/default/img/home-header-bg-3'+ie_mod+'.jpg) 50% 0 repeat-x;'+ie_style+'"></div>',
		'<div id="bg-4" style="background: url(/sites/all/themes/default/img/home-header-bg-4'+ie_mod+'.jpg) 50% 0 repeat-x;'+ie_style+'"></div>',
		'<div id="bg-5" style="background: url(/sites/all/themes/default/img/home-header-bg-5'+ie_mod+'.jpg) 50% 0 repeat-x;'+ie_style+'"></div>',
	];
	$('.region-homepage-cycle').prepend('<div id="homepage-backgrounds"></div>');
	for(var i = 0; i < homepage_backgrounds.length; i++) {
		var div_string = '<div style=""></div>';
		$('#homepage-backgrounds').append(homepage_backgrounds[i]);
	}
	$('#homepage-backgrounds').cycle({
		timeout: 0,
		nowrap: false,
		prev: '.cycle-prev',
		next: '.cycle-next',
		manualTrump: false
	});
}


function hideHomepageIntro() {
	clearTimeout(intro_timeout);
	$('.region-section-header').css('margin-top', '-554px');
	$('.region-homepage-cycle').fadeIn(500);
	$('.region-section-header').fadeOut(500);
	$('#people_cycle').fadeIn(500);
}

function checkWindowWidth() {
    if(typeof(window.innerWidth) == 'number' ) {
        windowWidth = window.innerWidth;
    } else if (typeof(document.documentElement.clientWidth) == 'number' && document.documentElement.clientWidth > 0) {
        windowWidth = document.documentElement.clientWidth;
        good_browser = false;
    } else {
        windowWidth = document.body.clientWidth;
        good_browser = false;
    }
    
    $('#homepage-backgrounds').css({
        minWidth: windowWidth
    });
}
;
(function ($) {
	Drupal.behaviors.jrs_form = {
		attach: function() {
			$('.datepicker').datepicker();
		}
	}
})(jQuery);

jQuery(document).ready(function() {
	$('#jrs_city_radio').click(function() {
		$('.select-city').show();
		$('.select-region').hide();
	});
	
	$('#jrs_region_radio').click(function() {
		$('.select-city').hide();
		$('.select-region').show();
	});

	$('#widget_booking_form').submit(function(e) {
		var failed = false;
		if($('#jrs_city_radio:checked').length) {
			if($('#jrs_location_group_id').val() == '771') {
				failed = true;
				$('#jrs_location_group_id').addClass('form-error');
			}
		} else if($('#jrs_region_radio:checked').length) {
			if($('#jrs_region_group_id').val() == '771') {
				failed = true;
				$('#jrs_region_group_id').addClass('form-error');
			}
		}
		if(failed) {
			e.preventDefault();
		}
	});
});;
(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);
;

