﻿/**
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne <brian@cherne.net>
*/
(function($) { $.fn.hoverIntent = function(f, g) { var cfg = { sensitivity: 7, interval: 100, timeout: 0 }; cfg = $.extend(cfg, g ? { 

over: f, out: g} : f); var cX, cY, pX, pY; var track = function(ev) { cX = ev.pageX; cY = ev.pageY; }; var compare = function(ev, ob) { 

ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); if ((Math.abs(pX - cX) + Math.abs(pY - cY)) < cfg.sensitivity) { $(ob).unbind

("mousemove", track); ob.hoverIntent_s = 1; return cfg.over.apply(ob, [ev]); } else { pX = cX; pY = cY; ob.hoverIntent_t = setTimeout

(function() { compare(ev, ob); }, cfg.interval); } }; var delay = function(ev, ob) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); 

ob.hoverIntent_s = 0; return cfg.out.apply(ob, [ev]); }; var handleHover = function(e) { var p = (e.type == "mouseover" ? e.fromElement 

: e.toElement) || e.relatedTarget; while (p && p != this) { try { p = p.parentNode; } catch (e) { p = this; } } if (p == this) { return 

false; } var ev = jQuery.extend({}, e); var ob = this; if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); } if 

(e.type == "mouseover") { pX = ev.pageX; pY = ev.pageY; $(ob).bind("mousemove", track); if (ob.hoverIntent_s != 1) { ob.hoverIntent_t = 

setTimeout(function() { compare(ev, ob); }, cfg.interval); } } else { $(ob).unbind("mousemove", track); if (ob.hoverIntent_s == 1) { 

ob.hoverIntent_t = setTimeout(function() { delay(ev, ob); }, cfg.timeout); } } }; return this.mouseover(handleHover).mouseout

(handleHover); }; })(jQuery);

$(document).ready(function()
{
	$('body').removeClass('no-js');
	$('#plc_lt_headerZone_SideTabs_txtEmail').click(function() { $(this).val(''); $(this).unbind('click'); });

	initTabs();

	//Adds overlay behaviour to the 2 social links in the main nav
	InitOverlays('div.shareWith a.shareEmail', '600px', '500px');
	InitOverlays('div.sidecar.feedbackSidecar p.linkTo a, a.feedback-overlay', '785px', '600px');
	
	initHero('div#homeHeroControls div.heroButton', 'div#homeHeroPort');

	timer = setTimeout('heroSpin()', 3000);

	/*$('div#homeHeroControls div.heroButton a').attr('href','');*/

	initHero('div#caveHighlights a.highlightPoint', 'div#bigHeroPort');
	initHero('div#timeline .highlightPoint', 'div#bigHeroPort');

	initFaq($('div.faqItem h3'));

	//Handle all links with rel = external
	$('a[rel="external"]').ExternalLinks();

	//Modify the standard .NET client validation so we can have a bit more control over presentation
	ModifyASPNETValidation();

	/*** main navigation, with 2 second delay ***/
	var hiconfig = {
		over: hiover, // function = onMouseOver callback (REQUIRED)    
		timeout: 2000, // number = milliseconds delay before onMouseOut    
		out: hiout // function = onMouseOut callback (REQUIRED)    
	};


	function hiover()
	{
		$('div.navigation li ul.level2').hide();
		$(this).find('ul.level2').show();
	}

	function hiout()
	{
		$(this).find('ul.level2').hide();
	}
	$("div.navigation li.hasChildren").hoverIntent(hiconfig);


	lineUpSubNav();

	// remove right maring from the last sidecar
	$('div.lowerContentContainer div.sidecar').eq(3).addClass('lastsidecar');
	setCaveInformationAlertHover();

	$('#subscriptionForm input[type="text"]').focus(registerEmailAddressClick);
});

function registerEmailAddressClick()
{
	var hasBeenSelected = $(this).data('hasBeenSelected');
	if (hasBeenSelected == undefined || hasBeenSelected == null)
	{
		$(this).attr('value', '');
		$(this).data('hasBeenSelected', true);
	}
}

function setCaveInformationAlertHover()
{
	// select the cave alert, get the initial bottom, and set the css
	var caveAlert = $('div.header-cave-alert');
	var initialBottom = ($('div.header-cave-alert .content').height() + 27) * -1;
	caveAlert.css({ bottom: initialBottom + 'px' });

	// determine the bottom difference for visible and hidden, and set the animation hover state
	var bottomDifference = $('div.header-cave-alert .content').height() + 12;
	caveAlert.hoverIntent(function()
	{
		$(this).animate({
			bottom: '+=' + bottomDifference
		}, 500);
	}, function()
	{
		$(this).animate({
			bottom: '-=' + bottomDifference
		}, 500);
	});
}


function InitOverlays(control, overlaywidth, overlayheight)
{
    $(control).click(function(){
        var overlayUrl = GetOverlayUrl($(this).attr('href'));
        var hash = window.location.hash;
        if (hash.length > 0)
        {
            overlayUrl += '&h='+hash.replace('#', '');
        }        
        $.colorbox({width:overlaywidth, height:overlayheight, iframe:true, href:overlayUrl});
        return false;
    });
}

function GetOverlayUrl(baseUrl)
{
    if(baseUrl.indexOf("?") != -1)return baseUrl.replace("?","-overlay?");
        
    var path = jQuery.url.setUrl(baseUrl).attr('path');
    var overlayPath = path+'-overlay';
    return baseUrl.replace(path, overlayPath);
    
}


var timer, heroIndex = 0;
//var count = 0;
var interval = 5000;

function heroSpin()
{
    var control = $('div#homeHeroControls div.heroButton');
    
    heroIndex++;
    $(control[heroIndex]).click();
    
    if(heroIndex >= control.length - 1)
    {
        /*if(count == 1) return;
         
        count++;
        heroIndex = -1;*/
        return;
    }
    
	timer = setTimeout('heroSpin()',interval);
}

function initHero(controls,port)
{
	$(controls).each(function()
	{
		$(this).mouseover(function() { $(this).css('cursor', 'pointer'); }).mouseout(function() { $(this).css('cursor', 'default'); });

		$(this).click(function()
		{
			var btn = $(this);
			$('div', port).parent().fadeOut(1000, function()
			{
				$('div', port).html($('div.heroInfo', btn).html());

				$('div', port).css('display', 'block');
				$(port).children('img').attr('src', $('img.heroInfo', btn).attr('src'));

				$('div', port).parent().fadeIn(2000);
			});

			$(controls).removeClass('selected');
			$(this).addClass('selected');

			clearTimeout(timer);
		});
	});
}

function initTabs()
{
	var tabs = $('#container div.sideTabContainer div.sideTab');
    
    tabs.each(function()
    {
        $(this).find('.inner').click(function()
        {
            var theContent = $(this).parent(); 
            if(theContent.hasClass('expanded'))
            {
                theContent.find('.content').stop(true,true).fadeOut(function(){
                    theContent.removeClass('expanded');
                });
            }
            else
            {
                theContent.find('.content').stop(true,true).fadeIn(function(){
                    theContent.addClass('expanded');
                });
            }
            
        });
    });
}

var weatherString = "http://www.google.com/ig/api?weather=Ingleton+United+Kingdom";



//Re-assigns a couple of the ASP.NET validation JS functions to provide a more flexible approach
function ModifyASPNETValidation()
{
    //Hi-jack the ASP.NET error display only if required
    if (typeof(Page_ClientValidate) != "undefined")
    {
        ValidatorUpdateDisplay = NicerValidatorUpdateDisplay;
        AspPage_ClientValidate = Page_ClientValidate;
        Page_ClientValidate = NicerPage_ClientValidate;
    }

    //Add validation statuses to any validation controls that may be visible (i.e. visible when the page loads)
    $('span.validation:visible,span.EditingFormErrorLabel:visible').each(function(){
        AddValidationStatus($(this));
    });
} 

function AddValidationStatus(obj)
{
    if (obj.hasClass('validation') || obj.hasClass('EditingFormErrorLabel'))
    {
        //We'll look for a validation container to set the status on
        var vc = obj.parents('div.validationContainer');
        if (vc.length == 0)
        {
            //Fall back to div.formInput
            vc = obj.parents('div.formInput');
        }
        vc.addClass('invalidInput');
    }
}

function RemoveValidationStatus(obj)
{
    if (obj.hasClass('validation') || obj.hasClass('EditingFormErrorLabel'))
    {
        //We'll look for the validation container to remove the status
        var vc = obj.parents('div.validationContainer');
        if (vc.length == 0)
        {
            //Fall back to div.formInput
            vc = obj.parents('div.formInput');
        }
        vc.removeClass('invalidInput');
    }
}

//Extends the classic ASP.NET validation
function NicerValidatorUpdateDisplay(val)
{
    var $val = $(val);
    if (val.isvalid)
    {
        //Hide the validation control
        $val.hide();        
        
        //Remove the validation status if there are no more validaiton controls visible
        if ($val.parent().find('span.validation:visible,span.EditingFormErrorLabel:visible').length == 0)
        {            
            RemoveValidationStatus($val);
        }
    }
    else
    {
        //Show the validation control
        $val.show();
        
        //Add the validation status
        AddValidationStatus($val);
    }
}

//Extends classic ASP.NET validation to include parent element styling
function NicerPage_ClientValidate(validationGroup)
{
    var valid = AspPage_ClientValidate(validationGroup);
    if (!valid)
    {
        //$(this).parent().addClass('invalidInput');
    }
    else
    {
        //$(this).parent().removeClass('invalidInput');
    }
    return valid;
}

function CheckBoxValidatorDisableButton(chkId, mustBeChecked, btnId)
{
    var button = document.getElementById(btnId);
    var chkbox = document.getElementById(chkId);
    
    if (button && chkbox)
    {
        button.disabled = (chkbox.checked != mustBeChecked);
    }
}

function CheckBoxValidatorEvaluateIsValid(val)
{
    var control = document.getElementById(val.controltovalidate);
    var mustBeChecked = Boolean(val.mustBeChecked == 'true');

    return control.checked == mustBeChecked;
}

function CheckBoxListValidatorEvaluateIsValid(val)
{
    var control = document.getElementById(val.controltovalidate);
    var minimumNumberOfSelectedCheckBoxes = parseInt(val.minimumNumberOfSelectedCheckBoxes);

    var selectedItemCount = 0;
    var liIndex = 0;
    var currentListItem = document.getElementById(control.id + '_' + liIndex.toString());
    while (currentListItem != null)
    {
        if (currentListItem.checked) selectedItemCount++;
        liIndex++;
        currentListItem = document.getElementById(control.id + '_' + liIndex.toString());
    }
    
    return selectedItemCount >= minimumNumberOfSelectedCheckBoxes;
}

(function($) {
    $.fn.DefaultValue = function(options) {
        //Build main options before element iteration
        var opts = $.extend({}, $.fn.DefaultValue.defaults, options);
        
        return this.each(function() {
            SetDefault(this, opts);
        });
        
        function SetDefault(obj, opts)
        {
            //We only want to set a default on textboxes, textareas and passwords
		    if(obj.type != 'text' && obj.type != 'password' && obj.type != 'textarea')
		    {
			    return;
			}
			    
            var $obj = $(obj);
            
			//Get the text we are going to use as the default
			var text = opts.Text;
			if (text.length == 0)
			{
			    text = $obj.attr('title');
			    $obj.attr('title', '');
			}
			
			if (text.length > 0)
			{    		
		        //Set value initially if none are specified
                if(obj.value == '' || obj.value == text)
                {
                    $obj.addClass('hasDefault');
			        obj.value = text;
		        }
		        else
		        {
			        //Other value exists - ignore
			        return;
		        }
        		
		        //Remove values on focus
		        $obj.focus(function() {
			        if(this.value == text || this.value == '')
			        {
                        $(this).removeClass('hasDefault');
				        this.value = '';
				    }
		        });
        		
		        //Place values back on blur
		        $obj.blur(function() {
			        if(this.value == text || this.value == '')
			        {
                        $(this).addClass('hasDefault');
				        this.value = text;
				    }
		        });
        		
		        //Capture parent form submission
		        //Remove field values that are still default
		        //$(this).parents("form").each(function() {
			        //Bind parent form submit
		        //	$(this).submit(function() {
		        //		if(fld_current.value==text) {
		        //			fld_current.value='';
		        //		}
		        //	});
		        //});
		    }
        }
    };
  
    //Plugin defaults
    $.fn.DefaultValue.defaults = {
        Text: ''
    };
})(jQuery);

//TopLinks forces a link to open in the top window
(function($) {
    $.fn.extend({
        TopLinks : function() {            
            return this.each(function() {                  
                if (this.tagName != 'A') {
                    return false;
                }
                
                $(this).click(function(){
                    top.location = this.href;
                    return false;
                });
            });
        }
    });
})(jQuery);

function trackGAPageview(pageName)
{
    if (typeof(_gaq) != 'undefined')
    {
        _gaq.push(['_trackPageview', pageName]);
        //alert('_trackPageview { ' + pageName + '}');
    }
}

function trackGAEvent(category, action, label, value)
{
    if (typeof(_gaq) != 'undefined')
    {
        _gaq.push(['_trackEvent', category, action, label, value]);
        
        //alert('_trackEvent { ' + category + ',  ' + action + ',  ' + label + ',  ' + value + '}');
    }
}

function getQuerystringParam(key, url)
{
  if (url == null) url = window.location.href; 
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(url);
  return qs == null ? '' : qs[1];
}

/*
 * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/ 
 * Open source under the BSD License. 
 * Copyright © 2008 George McGinley Smith
 * All rights reserved.
*/
jQuery.easing['jswing']=jQuery.easing['swing'];jQuery.extend(jQuery.easing,{def:'easeOutQuad',swing:function(x,t,b,c,d){return jQuery.easing[jQuery.easing.def](x,t,b,c,d);},easeInQuad:function(x,t,b,c,d){return c*(t/=d)*t+b;},easeOutQuad:function(x,t,b,c,d){return-c*(t/=d)*(t-2)+b;},easeInOutQuad:function(x,t,b,c,d){if((t/=d/2)<1)return c/2*t*t+b;return-c/2*((--t)*(t-2)-1)+b;},easeInCubic:function(x,t,b,c,d){return c*(t/=d)*t*t+b;},easeOutCubic:function(x,t,b,c,d){return c*((t=t/d-1)*t*t+1)+b;},easeInOutCubic:function(x,t,b,c,d){if((t/=d/2)<1)return c/2*t*t*t+b;return c/2*((t-=2)*t*t+2)+b;},easeInQuart:function(x,t,b,c,d){return c*(t/=d)*t*t*t+b;},easeOutQuart:function(x,t,b,c,d){return-c*((t=t/d-1)*t*t*t-1)+b;},easeInOutQuart:function(x,t,b,c,d){if((t/=d/2)<1)return c/2*t*t*t*t+b;return-c/2*((t-=2)*t*t*t-2)+b;},easeInQuint:function(x,t,b,c,d){return c*(t/=d)*t*t*t*t+b;},easeOutQuint:function(x,t,b,c,d){return c*((t=t/d-1)*t*t*t*t+1)+b;},easeInOutQuint:function(x,t,b,c,d){if((t/=d/2)<1)return c/2*t*t*t*t*t+b;return c/2*((t-=2)*t*t*t*t+2)+b;},easeInSine:function(x,t,b,c,d){return-c*Math.cos(t/d*(Math.PI/2))+c+b;},easeOutSine:function(x,t,b,c,d){return c*Math.sin(t/d*(Math.PI/2))+b;},easeInOutSine:function(x,t,b,c,d){return-c/2*(Math.cos(Math.PI*t/d)-1)+b;},easeInExpo:function(x,t,b,c,d){return(t==0)?b:c*Math.pow(2,10*(t/d-1))+b;},easeOutExpo:function(x,t,b,c,d){return(t==d)?b+c:c*(-Math.pow(2,-10*t/d)+1)+b;},easeInOutExpo:function(x,t,b,c,d){if(t==0)return b;if(t==d)return b+c;if((t/=d/2)<1)return c/2*Math.pow(2,10*(t-1))+b;return c/2*(-Math.pow(2,-10*--t)+2)+b;},easeInCirc:function(x,t,b,c,d){return-c*(Math.sqrt(1-(t/=d)*t)-1)+b;},easeOutCirc:function(x,t,b,c,d){return c*Math.sqrt(1-(t=t/d-1)*t)+b;},easeInOutCirc:function(x,t,b,c,d){if((t/=d/2)<1)return-c/2*(Math.sqrt(1-t*t)-1)+b;return c/2*(Math.sqrt(1-(t-=2)*t)+1)+b;},easeInElastic:function(x,t,b,c,d){var s=1.70158;var p=0;var a=c;if(t==0)return b;if((t/=d)==1)return b+c;if(!p)p=d*.3;if(a<Math.abs(c)){a=c;var s=p/4;}
else var s=p/(2*Math.PI)*Math.asin(c/a);return-(a*Math.pow(2,10*(t-=1))*Math.sin((t*d-s)*(2*Math.PI)/p))+b;},easeOutElastic:function(x,t,b,c,d){var s=1.70158;var p=0;var a=c;if(t==0)return b;if((t/=d)==1)return b+c;if(!p)p=d*.3;if(a<Math.abs(c)){a=c;var s=p/4;}
else var s=p/(2*Math.PI)*Math.asin(c/a);return a*Math.pow(2,-10*t)*Math.sin((t*d-s)*(2*Math.PI)/p)+c+b;},easeInOutElastic:function(x,t,b,c,d){var s=1.70158;var p=0;var a=c;if(t==0)return b;if((t/=d/2)==2)return b+c;if(!p)p=d*(.3*1.5);if(a<Math.abs(c)){a=c;var s=p/4;}
else var s=p/(2*Math.PI)*Math.asin(c/a);if(t<1)return-.5*(a*Math.pow(2,10*(t-=1))*Math.sin((t*d-s)*(2*Math.PI)/p))+b;return a*Math.pow(2,-10*(t-=1))*Math.sin((t*d-s)*(2*Math.PI)/p)*.5+c+b;},easeInBack:function(x,t,b,c,d,s){if(s==undefined)s=1.70158;return c*(t/=d)*t*((s+1)*t-s)+b;},easeOutBack:function(x,t,b,c,d,s){if(s==undefined)s=1.70158;return c*((t=t/d-1)*t*((s+1)*t+s)+1)+b;},easeInOutBack:function(x,t,b,c,d,s){if(s==undefined)s=1.70158;if((t/=d/2)<1)return c/2*(t*t*(((s*=(1.525))+1)*t-s))+b;return c/2*((t-=2)*t*(((s*=(1.525))+1)*t+s)+2)+b;},easeInBounce:function(x,t,b,c,d){return c-jQuery.easing.easeOutBounce(x,d-t,0,c,d)+b;},easeOutBounce:function(x,t,b,c,d){if((t/=d)<(1/2.75)){return c*(7.5625*t*t)+b;}else if(t<(2/2.75)){return c*(7.5625*(t-=(1.5/2.75))*t+.75)+b;}else if(t<(2.5/2.75)){return c*(7.5625*(t-=(2.25/2.75))*t+.9375)+b;}else{return c*(7.5625*(t-=(2.625/2.75))*t+.984375)+b;}},easeInOutBounce:function(x,t,b,c,d){if(t<d/2)return jQuery.easing.easeInBounce(x,t*2,0,c,d)*.5+b;return jQuery.easing.easeOutBounce(x,t*2-d,0,c,d)*.5+c*.5+b;}});

/*
 * Javascript Object Oriented Timer, version 1.0 - http://abcoder.com/javascript/core_javascript/javascript_timer
 * Copyright (C) 2008 zp bappi | zpbappi (at) gmail (dot) com
 * This script is distributed under the GNU Lesser General Public License (Version 3, 29 June 2007 or later).
*/
var Timer=function(millis,callback){return this._init(millis,callback);}
Timer.prototype={VERSION:1.0,_init:function(millis,callback){this._interval=1000;this._timer=null;this._cbs=[];this._multipliers=[];this._tickCounts=[];this._canRun=[];this._stoppedThreads=0;this._runOnce=false;this._startedAt=-1;this._pausedAt=-1;if(typeof(millis)=='number')this._interval=millis;this.addCallback(callback);return this;},_preset:function(){this._stoppedThreads=0;this._startedAt=-1;this._pausedAt=-1;for(var i=0;i<this._cbs.length;i++){this._canRun[i]=true;this._tickCounts[i]=0;}},_ticks:function(initInterval){var me=this;for(var i=0;i<this._cbs.length;i++){if(typeof(this._cbs[i])=='function'&&this._canRun[i]){this._tickCounts[i]++;if(this._tickCounts[i]==this._multipliers[i]){this._tickCounts[i]=0;if(this.runOnce()){this._canRun[i]=false;this._stoppedThreads++;}
window.setTimeout(me._cbs[i],0);}}}
if(this.runOnce()&&this._stoppedThreads==this._cbs.length)
this.stop();if(typeof(initInterval)=='number'){this.stop().start(null,true);}},runOnce:function(isRunOnce){if(typeof(isRunOnce)=='undefined')return this._runOnce;else if(typeof(isRunOnce)=='boolean')this._runOnce=isRunOnce;else alert("Invalid argument for runOnce(...).\n\nUsage: runOnce(true | false) /*Default value: false*/\nor, runOnce() to get status");return this;},interval:function(millis){if(typeof(millis)=='undefined')return this._interval;else if(typeof(millis)=='number')this._interval=Math.floor(millis);return this;},stop:function(isPausing){if(this._timer){if(!isPausing)this._pausedAt=-1;try{window.clearInterval(this._timer);}
catch(ex){}
this._timer=null;}
return this;},isStopped:function(){return((this._timer==null)&&!this.isPaused());},start:function(_initialInterval,_withoutPreset){if(this.isPaused())
return this.resume();if(!this.isStopped())
return this;if(!_withoutPreset)
this._preset();var tmpInterval=this._interval;if(typeof(_initialInterval)=='number')tmpInterval=_initialInterval;var me=this;this._timer=window.setInterval(function(){me._ticks(_initialInterval);},tmpInterval);this._startedAt=(new Date()).getTime();this._startedAt-=(this._interval-tmpInterval);return this;},pause:function(){if(this._timer){this._pausedAt=(new Date()).getTime();this.stop(true);}
return this;},isPaused:function(){return(this._pausedAt>=0);},resume:function(){if(this.isPaused()){var tempInterval=this._interval-((this._pausedAt-this._startedAt)%this._interval);this._pausedAt=-1;this.start(tempInterval,true);}
return this;},restart:function(){return this.stop().start();},addCallback:function(callback,N){if(typeof(callback)=='function'){this._cbs.push(callback);if(typeof(N)=='number'){N=Math.floor(N)
this._multipliers.push((N<1?1:N));}
else
this._multipliers.push(1);this._tickCounts.push(0);this._canRun.push(true);}
return this;},clearCallbacks:function(){this._cbs.length=0;this._multipliers.length=0;this._canRun.length=0;this._tickCounts.length=0;this._stoppedThreads=0;return this;}};

//See http://stackoverflow.com/questions/123999/how-to-tell-if-a-dom-element-is-visible-in-the-current-viewport
jQuery.extend(jQuery.expr[':'], {
    inView: function (el) {
        var top = el.offsetTop;
        var left = el.offsetLeft;
        var width = el.offsetWidth;
        var height = el.offsetHeight;

        while(el.offsetParent) {
            el = el.offsetParent;
            top += el.offsetTop;
            left += el.offsetLeft;
        }

        return (
            top < (window.pageYOffset + window.innerHeight) &&
            left < (window.pageXOffset + window.innerWidth) &&
            (top + height) > window.pageYOffset &&
            (left + width) > window.pageXOffset
        );
    }
});


function initFaq(resourceTitles)
{
    resourceTitles.each(function(){
        var title = $(this);
        var resourceCategory = title.parent();
        var resources = resourceCategory.find('div.explanation');
        
        resourceCategory.addClass('collapsed');        
        resources.hide();
        
        title.click(function(){
            resources.slideToggle(500);
            resourceCategory.toggleClass('expanded');
            resourceCategory.toggleClass('collapsed');
                
            //Track this as an event
            var action = resourceCategory.hasClass('expanded') ? 'expanded' : 'collapsed';
            var label = title.text();
            trackGAEvent('FAQ', action, label);
        });
    });
}




//ExternalLinks - tracking based on http://www.iqcontent.com/blog/2007/02/tracking-documents-and-external-links-in-google-analytics/
(function($)
{
	$.fn.extend({
		ExternalLinks: function()
		{
			return this.each(function()
			{
				if (this.tagName != 'A')
				{
					return false;
				}

				var link = String(this);
				var linkHost = this.hostname;
				var siteHost = location.host;

				if (link.match(/^mailto:/i))
				{
					$(this).click(function()
					{
						return HandleMailToLink(this);
					});
				}
				else if (linkHost == siteHost)
				{
					var parts = link.split('?');
					var path = parts[0];
					if (path.match(/\.(doc|pdf|xls|ppt|zip|txt|vsd|vxd|js|css|rar|exe|wma|mov|avi|wmv|mp3|ashx)$/))
					{
						ModifyTitleAttribute(this);
						$(this).click(function()
						{
							return HandleDocumentLink(this);
						});
					}
					else
					{
						$(this).click(function()
						{
							return HandleInternalLink(this);
						});
					}
				}
				else
				{
					ModifyTitleAttribute(this);
					$(this).click(function()
					{
						return HandleExternalLink(this);
					});
				}
			});

			function HandleMailToLink(anchor)
			{
				var email = anchor.href.substring(7);
				TrackLink('email', email);

				return true;
			}

			function HandleDocumentLink(anchor)
			{
				var doc = CleanURL(anchor.pathname, false);
				TrackLink('resources', doc);

				window.open(anchor.href);
				return false;
			}

			function HandleInternalLink(anchor)
			{
				window.open(anchor.href);
				return false;
			}

			function HandleExternalLink(anchor)
			{
				var pathname = (anchor.pathname.substr(0, 1) != '/'
					? anchor.pathname + '/'
					: anchor.pathname);

				var link = CleanURL(anchor.hostname + pathname, true);
				TrackLink('external', link);

				window.open(anchor.href);
				return false;
			}

			function TrackLink(type, virtualPath)
			{
				if (typeof (pageTracker) != 'undefined')
				{
					var linkStr = CleanURL('/' + type + '/' + virtualPath, true);
					pageTracker._trackPageview(linkStr);
				}
			}

			function CleanURL(url, end)
			{
				var url = url.toString();
				var urlLen = url.length;

				if (end)
				{
					if (url.charAt((urlLen - 1)) == '/')
					{
						url = url.substring(0, (urlLen - 1));
					}
				}
				else
				{
					if (url.charAt(0) == '/')
					{
						url = url.substring(1, urlLen);
					}
				}
				return url;
			}

			function ModifyTitleAttribute(anchor)
			{
				var jAnchor = $(anchor);
				var title = $(anchor).attr('title');
				if (title.length > 0)
				{
					title += ' [opens in a new window]';
				}
				else
				{
					title += 'Opens in a new window';
				}
				jAnchor.attr('title', title);
			}
		}
	});
})(jQuery);

function TrackInlineLink(virtualPath)
{
    /*
	if (typeof (pageTracker) != 'undefined')
	{
		pageTracker._trackPageview(virtualPath);
	}*/
	alert('This should use "trackGAPageview(pageName);"');
}

// intended to allow us to print just the google map. This is done by putting the map into a 'hidden' iframe
// and printing that.
function printFrame() {
    var frame = document.getElementById('printablemap');
	if (!frame) {
	    alert("Error: Can't find printing frame.");
        return false;
    }
	frame = frame.contentWindow;
	frame.focus();
	frame.print();
	return false;
}

// move any single children under the relevant parent.
function lineUpSubNav()
{
    var singleChildren = $('#mainNavigation li.level2.first.last');
    
    singleChildren.each(function()
    {
        var p = eval($(this).parent().parent().children('a.level1').position().left);
        var newleft = p-169;
        if (p < 490)
            newleft = p-420;
        $(this).css('margin-left', newleft);
    });
}

