$.ajaxSetup({ cache: false });

/* Modernizr custom build of 1.7: csstransforms | csstransforms3d | csstransitions */
;window.Modernizr=function(a,b,c){function G(){}function F(a,b){var c=a.charAt(0).toUpperCase()+a.substr(1),d=(a+" "+p.join(c+" ")+c).split(" ");return!!E(d,b)}function E(a,b){for(var d in a)if(k[a[d]]!==c&&(!b||b(a[d],j)))return!0}function D(a,b){return(""+a).indexOf(b)!==-1}function C(a,b){return typeof a===b}function B(a,b){return A(o.join(a+";")+(b||""))}function A(a){k.cssText=a}var d="1.7",e={},f=!0,g=b.documentElement,h=b.head||b.getElementsByTagName("head")[0],i="modernizr",j=b.createElement(i),k=j.style,l=b.createElement("input"),m=":)",n=Object.prototype.toString,o=" -webkit- -moz- -o- -ms- -khtml- ".split(" "),p="Webkit Moz O ms Khtml".split(" "),q={svg:"http://www.w3.org/2000/svg"},r={},s={},t={},u=[],v,w=function(a){var c=b.createElement("style"),d=b.createElement("div"),e;c.textContent=a+"{#modernizr{height:3px}}",h.appendChild(c),d.id="modernizr",g.appendChild(d),e=d.offsetHeight===3,c.parentNode.removeChild(c),d.parentNode.removeChild(d);return!!e},x=function(){function d(d,e){e=e||b.createElement(a[d]||"div");var f=(d="on"+d)in e;f||(e.setAttribute||(e=b.createElement("div")),e.setAttribute&&e.removeAttribute&&(e.setAttribute(d,""),f=C(e[d],"function"),C(e[d],c)||(e[d]=c),e.removeAttribute(d))),e=null;return f}var a={select:"input",change:"input",submit:"form",reset:"form",error:"img",load:"img",abort:"img"};return d}(),y=({}).hasOwnProperty,z;C(y,c)||C(y.call,c)?z=function(a,b){return b in a&&C(a.constructor.prototype[b],c)}:z=function(a,b){return y.call(a,b)},r.csstransforms=function(){return!!E(["transformProperty","WebkitTransform","MozTransform","OTransform","msTransform"])},r.csstransforms3d=function(){var a=!!E(["perspectiveProperty","WebkitPerspective","MozPerspective","OPerspective","msPerspective"]);a&&"webkitPerspective"in g.style&&(a=w("@media ("+o.join("transform-3d),(")+"modernizr)"));return a},r.csstransitions=function(){return F("transitionProperty")};for(var H in r)z(r,H)&&(v=H.toLowerCase(),e[v]=r[H](),u.push((e[v]?"":"no-")+v));e.input||G(),e.crosswindowmessaging=e.postmessage,e.historymanagement=e.history,e.addTest=function(a,b){a=a.toLowerCase();if(!e[a]){b=!!b(),g.className+=" "+(b?"":"no-")+a,e[a]=b;return e}},A(""),j=l=null,e._enableHTML5=f,e._version=d,g.className=g.className.replace(/\bno-js\b/,"")+" js "+u.join(" ");return e}(this,this.document);

/* ======================================== *
jQuery Keyframe Animation
- version 0.2.2
Copyright 2009 Noah Burney
Released under the MIT and GPL licenses.
* ======================================== */

(function ($) {
	// Extend the jQuery prototype
	$.fn.keyframe = function () {
		// Return jQuery object if no options
		if (arguments.length == 0) return this;
		// Store reference to self
		var _ = this,
		args = Array.prototype.slice.call(arguments),
		// List of keyframes
		anim = args[0],
		// Capture easing option
		default_easing = args[1] || 'linear',
		// Stores object keys in numerical order
		keys = [], key_len,
		// Stores various animations to be executed
		queue = [], undefined;

		// Grap all the object key names
		for (var k in anim)
			keys.push(
		// Allow use of 'start' instead of 0
		(k == 'start') ? 0 : parseInt(k)
	  );
		// Sort the object's key names in numerical ascending order
		keys.sort(function (a, b) {
			return (a < b) ? -1 : 1;
		});

		// Loop through all the keyframes, and build of queue of animations
		for (var n = 0, l = keys.length; n < l; n++) (function (n) {
			var time = keys[n], // End-time
		  last_time = (n > 0) ? keys[n - 1] : 0, // Previous end-time
		  length = time - last_time; // Minimum duration of animation

			// If the time is 0 don't animate, just set it
			if (time == 0)
				_.stop(true, true).css(anim['start']);

			// If this is the first non-zero keyframe, just queue up whatever
			// is listed, instead of all the brouhaha below
			else if ((n == 0) || (last_time == 0))
				queue.push({
					start: 0,
					end: time,
					style: anim[time],
					easing: default_easing
				});

			// Otherwise, go through each of this keyframe's properties, building
			// up the necessary animation(s)
			else {
				// Hold potential animations for this keyframe
				var batch = {};
				// Loop through keyframe's declared properties
				for (var prop in anim[time]) {
					var prev = 0, n = queue.length,
			  easing = default_easing,
			  value = anim[time][prop];

					// If value is an array with easing, adjust stuff accordingly
					if (value.constructor.toString().match(/Array/)) {
						easing = value[1];
						value = value[0];
					}
					// Find the last time this property was specified, default to 0
					while (n--) {
						if (queue[n]['style'][prop] != undefined) {
							prev = queue[n].end;
							break;
						}
					}
					// Combine animations with same time and easing, else make a new one
					var batch_name = prev + '-' + easing;
					if (batch[batch_name] === undefined)
						batch[batch_name] = {
							start: prev,
							end: time,
							style: {},
							easing: easing
						};
					// Add in property
					batch[batch_name]['style'][prop] = value;
				}

				// Add all animations from current batch in to queue
				for (var a in batch)
					queue.push(batch[a]);

			}
		})(n);

		// Abuse jQuery.animate's magical queing properties
		_.animate({ delay: 1 }, 0, function () {
			// Loop through queue of animations, and invoke them all
			// using jQuery's built-in `animate`, and `setTimeout`
			for (var n = 0, l = queue.length; n < l; n++) (function (n) {
				var anim = queue[n];
				_.animate({ delay: 1 }, { queue: false, duration: anim.start, complete: function () {
					_.animate(anim.style, { duration: (anim.end - anim.start), easing: anim.easing, queue: false });
				}
				});
			})(n);

			_.animate({ delay: 1 }, queue[queue.length - 1].end);
		});

		// Return the jQuery object for hardcore chaingangin' action
		return this;
	};
})(jQuery);
/*!
* jQuery Reach
* http://blog.dogma.co.uk
*
* Copyright (c) 2010 Richard Kimber
* Dual licensed under the MIT and GPL licenses.
*/

(function ($) {
	// Global
	$.extend({
		reach: function (elems, callback, arg) {
			elems.sort(function () { return (Math.random() - 0.5); });
			return this.each(elems, callback, arg);
		}
	});

	// Element
	$.fn.reach = function (callback, args) {
		return $.reach(this, callback, args);
	};
})(jQuery);
/*! Copyright (c) 2010 Brandon Aaron (http://brandonaaron.net)
* Licensed under the MIT License (LICENSE.txt).
*
* Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
* Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
* Thanks to: Seamus Leahy for adding deltaX and deltaY
*
* Version: 3.0.4
* 
* Requires: 1.2.2+
*/

(function ($) {

	var types = ['DOMMouseScroll', 'mousewheel'];

	$.event.special.mousewheel = {
		setup: function () {
			if (this.addEventListener) {
				for (var i = types.length; i; ) {
					this.addEventListener(types[--i], handler, false);
				}
			} else {
				this.onmousewheel = handler;
			}
		},

		teardown: function () {
			if (this.removeEventListener) {
				for (var i = types.length; i; ) {
					this.removeEventListener(types[--i], handler, false);
				}
			} else {
				this.onmousewheel = null;
			}
		}
	};

	$.fn.extend({
		mousewheel: function (fn) {
			return fn ? this.bind("mousewheel", fn) : this.trigger("mousewheel");
		},

		unmousewheel: function (fn) {
			return this.unbind("mousewheel", fn);
		}
	});


	function handler(event) {
		var orgEvent = event || window.event, args = [].slice.call(arguments, 1), delta = 0, returnValue = true, deltaX = 0, deltaY = 0;
		event = $.event.fix(orgEvent);
		event.type = "mousewheel";

		// Old school scrollwheel delta
		if (event.wheelDelta) { delta = event.wheelDelta / 120; }
		if (event.detail) { delta = -event.detail / 3; }

		// New school multidimensional scroll (touchpads) deltas
		deltaY = delta;

		// Gecko
		if (orgEvent.axis !== undefined && orgEvent.axis === orgEvent.HORIZONTAL_AXIS) {
			deltaY = 0;
			deltaX = -1 * delta;
		}

		// Webkit
		if (orgEvent.wheelDeltaY !== undefined) { deltaY = orgEvent.wheelDeltaY / 120; }
		if (orgEvent.wheelDeltaX !== undefined) { deltaX = -1 * orgEvent.wheelDeltaX / 120; }

		// Add event and delta to the front of the arguments
		args.unshift(event, delta, deltaX, deltaY);

		return $.event.handle.apply(this, args);
	}

})(jQuery);
/**
* @author trixta
* @version 1.2
*/
(function ($) {

	var mwheelI = {
		pos: [-260, -260]
	},
	minDif = 3,
	doc = document,
	root = doc.documentElement,
	body = doc.body,
	longDelay, shortDelay
;

	function unsetPos() {
		if (this === mwheelI.elem) {
			mwheelI.pos = [-260, -260];
			mwheelI.elem = false;
			minDif = 3;
		}
	}

	$.event.special.mwheelIntent = {
		setup: function () {
			var jElm = $(this).bind('mousewheel', $.event.special.mwheelIntent.handler);
			if (this !== doc && this !== root && this !== body) {
				jElm.bind('mouseleave', unsetPos);
			}
			jElm = null;
			return true;
		},
		teardown: function () {
			$(this)
			.unbind('mousewheel', $.event.special.mwheelIntent.handler)
			.unbind('mouseleave', unsetPos)
		;
			return true;
		},
		handler: function (e, d) {
			var pos = [e.clientX, e.clientY];
			if (this === mwheelI.elem || Math.abs(mwheelI.pos[0] - pos[0]) > minDif || Math.abs(mwheelI.pos[1] - pos[1]) > minDif) {
				mwheelI.elem = this;
				mwheelI.pos = pos;
				minDif = 250;

				clearTimeout(shortDelay);
				shortDelay = setTimeout(function () {
					minDif = 10;
				}, 200);
				clearTimeout(longDelay);
				longDelay = setTimeout(function () {
					minDif = 3;
				}, 1500);
				e = $.extend({}, e, { type: 'mwheelIntent' });
				return $.event.handle.apply(this, arguments);
			}
		}
	};
	$.fn.extend({
		mwheelIntent: function (fn) {
			return fn ? this.bind("mwheelIntent", fn) : this.trigger("mwheelIntent");
		},

		unmwheelIntent: function (fn) {
			return this.unbind("mwheelIntent", fn);
		}
	});

	$(function () {
		body = doc.body;
		//assume that document is always scrollable, doesn't hurt if not
		$(doc).bind('mwheelIntent.mwheelIntentDefault', $.noop);
	});
})(jQuery);
/*!
* jScrollPane - v2.0.0beta6 - 2010-10-28
* http://jscrollpane.kelvinluck.com/
*
* Copyright (c) 2010 Kelvin Luck
* Dual licensed under the MIT and GPL licenses.
*/

// Script: jScrollPane - cross browser customisable scrollbars
//
// *Version: 2.0.0beta6, Last updated: 2010-10-28*
//
// Project Home - http://jscrollpane.kelvinluck.com/
// GitHub       - http://github.com/vitch/jScrollPane
// Source       - http://github.com/vitch/jScrollPane/raw/master/script/jquery.jscrollpane.js
// (Minified)   - http://github.com/vitch/jScrollPane/raw/master/script/jquery.jscrollpane.min.js
//
// About: License
//
// Copyright (c) 2010 Kelvin Luck
// Dual licensed under the MIT or GPL Version 2 licenses.
// http://jscrollpane.kelvinluck.com/MIT-LICENSE.txt
// http://jscrollpane.kelvinluck.com/GPL-LICENSE.txt
//
// About: Examples
//
// All examples and demos are available through the jScrollPane example site at:
// http://jscrollpane.kelvinluck.com/
//
// About: Support and Testing
//
// This plugin is tested on the browsers below and has been found to work reliably on them. If you run
// into a problem on one of the supported browsers then please visit the support section on the jScrollPane
// website (http://jscrollpane.kelvinluck.com/) for more information on getting support. You are also
// welcome to fork the project on GitHub if you can contribute a fix for a given issue. 
//
// jQuery Versions - tested in 1.4.2+ - reported to work in 1.3.x
// Browsers Tested - Firefox 3.6.8, Safari 5, Opera 10.6, Chrome 5.0, IE 6, 7, 8
//
// About: Release History
//
// 2.0.0beta6 - (in progress) scrollToElement horizontal support
// 2.0.0beta5 - (2010-10-18) jQuery 1.4.3 support, various bug fixes
// 2.0.0beta4 - (2010-09-17) clickOnTrack support, bug fixes
// 2.0.0beta3 - (2010-08-27) Horizontal mousewheel, mwheelIntent, keyboard support, bug fixes
// 2.0.0beta2 - (2010-08-21) Bug fixes
// 2.0.0beta1 - (2010-08-17) Rewrite to follow modern best practices and enable horizontal scrolling, initially hidden
//							 elements and dynamically sized elements.
// 1.x - (2006-12-31 - 2010-07-31) Initial version, hosted at googlecode, deprecated

(function ($, window, undefined) {

	$.fn.jScrollPane = function (settings) {
		// JScrollPane "class" - public methods are available through $('selector').data('jsp')
		function JScrollPane(elem, s) {

			var settings, jsp = this, pane, paneWidth, paneHeight, container, contentWidth, contentHeight,
				percentInViewH, percentInViewV, isScrollableV, isScrollableH, verticalDrag, dragMaxY,
				verticalDragPosition, horizontalDrag, dragMaxX, horizontalDragPosition,
				verticalBar, verticalTrack, scrollbarWidth, verticalTrackHeight, verticalDragHeight, arrowUp, arrowDown,
				horizontalBar, horizontalTrack, horizontalTrackWidth, horizontalDragWidth, arrowLeft, arrowRight,
				reinitialiseInterval, originalPadding, originalPaddingTotalWidth, previousPaneWidth,
				wasAtTop = true, wasAtLeft = true, wasAtBottom = false, wasAtRight = false,
				mwEvent = $.fn.mwheelIntent ? 'mwheelIntent.jsp' : 'mousewheel.jsp';

			originalPadding = elem.css('paddingTop') + ' ' +
								elem.css('paddingRight') + ' ' +
								elem.css('paddingBottom') + ' ' +
								elem.css('paddingLeft');
			originalPaddingTotalWidth = (parseInt(elem.css('paddingLeft')) || 0) +
										(parseInt(elem.css('paddingRight')) || 0);

			initialise(s);

			function initialise(s) {

				var clonedElem, tempWrapper, /*firstChild, lastChild, */isMaintainingPositon, lastContentX, lastContentY,
						hasContainingSpaceChanged;

				settings = s;

				if (pane == undefined) {

					elem.css(
						{
							'overflow': 'hidden',
							'padding': 0
						}
					);
					// TODO: Deal with where width/ height is 0 as it probably means the element is hidden and we should
					// come back to it later and check once it is unhidden...
					paneWidth = elem.innerWidth() + originalPaddingTotalWidth;
					paneHeight = elem.innerHeight();

					elem.width(paneWidth);

					pane = $('<div class="jspPane" />').wrap(
						$('<div class="jspContainer" />')
							.css({
								'width': paneWidth + 'px',
								'height': paneHeight + 'px'
							}
						)
					);

					elem.wrapInner(pane.parent());
					// Need to get the vars after being added to the document, otherwise they reference weird
					// disconnected orphan elements...
					container = elem.find('>.jspContainer');
					pane = container.find('>.jspPane');
					pane.css('padding', originalPadding);

					/*
					// Move any margins from the first and last children up to the container so they can still
					// collapse with neighbouring elements as they would before jScrollPane 
					firstChild = pane.find(':first-child');
					lastChild = pane.find(':last-child');
					elem.css(
					{
					'margin-top': firstChild.css('margin-top'),
					'margin-bottom': lastChild.css('margin-bottom')
					}
					);
					firstChild.css('margin-top', 0);
					lastChild.css('margin-bottom', 0);
					*/
				} else {
					elem.css('width', '');

					hasContainingSpaceChanged = elem.outerWidth() + originalPaddingTotalWidth != paneWidth || elem.outerHeight() != paneHeight;

					if (hasContainingSpaceChanged) {
						paneWidth = elem.innerWidth() + originalPaddingTotalWidth;
						paneHeight = elem.innerHeight();
						container.css({
							'width': paneWidth + 'px',
							'height': paneHeight + 'px'
						});
					}

					previousPaneWidth = pane.innerWidth();

					if (!hasContainingSpaceChanged && pane.outerWidth() == contentWidth && pane.outerHeight() == contentHeight) {
						// Nothing has changed since we last initialised
						if (isScrollableH || isScrollableV) { // If we had already set a width then re-set it
							pane.css('width', previousPaneWidth + 'px');
							elem.css('width', (previousPaneWidth + originalPaddingTotalWidth) + 'px');
						}
						// Then abort...
						return;
					}

					pane.css('width', '');
					elem.css('width', (paneWidth) + 'px');

					container.find('>.jspVerticalBar,>.jspHorizontalBar').remove().end();
				}

				// Unfortunately it isn't that easy to find out the width of the element as it will always report the
				// width as allowed by its container, regardless of overflow settings.
				// A cunning workaround is to clone the element, set its position to absolute and place it in a narrow
				// container. Now it will push outwards to its maxium real width...
				clonedElem = pane.clone().css('position', 'absolute');
				tempWrapper = $('<div style="width:1px; position: relative;" />').append(clonedElem);
				$('body').append(tempWrapper);
				contentWidth = Math.max(pane.outerWidth(), clonedElem.outerWidth());
				tempWrapper.remove();

				contentHeight = pane.outerHeight();
				percentInViewH = contentWidth / paneWidth;
				percentInViewV = contentHeight / paneHeight;
				isScrollableV = percentInViewV > 1;

				isScrollableH = percentInViewH > 1;

				//console.log(paneWidth, paneHeight, contentWidth, contentHeight, percentInViewH, percentInViewV, isScrollableH, isScrollableV);

				if (!(isScrollableH || isScrollableV)) {
					elem.removeClass('jspScrollable');
					pane.css({
						'top': 0,
						'width': container.width() - originalPaddingTotalWidth
					});
					removeMousewheel();
					removeFocusHandler();
					removeKeyboardNav();
					removeClickOnTrack();
					unhijackInternalLinks();
				} else {
					elem.addClass('jspScrollable');

					isMaintainingPositon = settings.maintainPosition && (verticalDragPosition || horizontalDragPosition);
					if (isMaintainingPositon) {
						lastContentX = contentPositionX();
						lastContentY = contentPositionY();
					}

					initialiseVerticalScroll();
					initialiseHorizontalScroll();
					resizeScrollbars();

					if (isMaintainingPositon) {
						scrollToX(lastContentX);
						scrollToY(lastContentY);
					}

					initFocusHandler();
					initMousewheel();
					if (settings.enableKeyboardNavigation) {
						initKeyboardNav();
					}
					if (settings.clickOnTrack) {
						initClickOnTrack();
					}

					observeHash();
					if (settings.hijackInternalLinks) {
						hijackInternalLinks();
					}
				}

				if (settings.autoReinitialise && !reinitialiseInterval) {
					reinitialiseInterval = setInterval(
						function () {
							initialise(settings);
						},
						settings.autoReinitialiseDelay
					);
				} else if (!settings.autoReinitialise && reinitialiseInterval) {
					clearInterval(reinitialiseInterval)
				}

				elem.trigger('jsp-initialised', [isScrollableH || isScrollableV]);
			}

			function initialiseVerticalScroll() {
				if (isScrollableV) {

					container.append(
						$('<div class="jspVerticalBar" />').append(
							$('<div class="jspCap jspCapTop" />'),
							$('<div class="jspTrack" />').append(
								$('<div class="jspDrag" />').append(
									$('<div class="jspDragTop" />'),
									$('<div class="jspDragBottom" />')
								)
							),
							$('<div class="jspCap jspCapBottom" />')
						)
					);

					verticalBar = container.find('>.jspVerticalBar');
					verticalTrack = verticalBar.find('>.jspTrack');
					verticalDrag = verticalTrack.find('>.jspDrag');

					if (settings.showArrows) {
						arrowUp = $('<a class="jspArrow jspArrowUp" />').bind(
							'mousedown.jsp', getArrowScroll(0, -1)
						).bind('click.jsp', nil);
						arrowDown = $('<a class="jspArrow jspArrowDown" />').bind(
							'mousedown.jsp', getArrowScroll(0, 1)
						).bind('click.jsp', nil);
						if (settings.arrowScrollOnHover) {
							arrowUp.bind('mouseover.jsp', getArrowScroll(0, -1, arrowUp));
							arrowDown.bind('mouseover.jsp', getArrowScroll(0, 1, arrowDown));
						}

						appendArrows(verticalTrack, settings.verticalArrowPositions, arrowUp, arrowDown);
					}

					verticalTrackHeight = paneHeight;
					container.find('>.jspVerticalBar>.jspCap:visible,>.jspVerticalBar>.jspArrow').each(
						function () {
							verticalTrackHeight -= $(this).outerHeight();
						}
					);


					verticalDrag.hover(
						function () {
							verticalDrag.addClass('jspHover');
						},
						function () {
							verticalDrag.removeClass('jspHover');
						}
					).bind(
						'mousedown.jsp',
						function (e) {
							// Stop IE from allowing text selection
							$('html').bind('dragstart.jsp selectstart.jsp', function () { return false; });

							verticalDrag.addClass('jspActive');

							var startY = e.pageY - verticalDrag.position().top;

							$('html').bind(
								'mousemove.jsp',
								function (e) {
									positionDragY(e.pageY - startY, false);
								}
							).bind('mouseup.jsp mouseleave.jsp', cancelDrag);
							return false;
						}
					);
					sizeVerticalScrollbar();
				}
			}

			function sizeVerticalScrollbar() {
				verticalTrack.height(verticalTrackHeight + 'px');
				verticalDragPosition = 0;
				scrollbarWidth = settings.verticalGutter + verticalTrack.outerWidth();

				// Make the pane thinner to allow for the vertical scrollbar
				pane.width(paneWidth - scrollbarWidth - originalPaddingTotalWidth);

				// Add margin to the left of the pane if scrollbars are on that side (to position
				// the scrollbar on the left or right set it's left or right property in CSS)
				if (verticalBar.position().left == 0) {
					pane.css('margin-left', scrollbarWidth + 'px');
				}
			}

			function initialiseHorizontalScroll() {
				if (isScrollableH) {

					container.append(
						$('<div class="jspHorizontalBar" />').append(
							$('<div class="jspCap jspCapLeft" />'),
							$('<div class="jspTrack" />').append(
								$('<div class="jspDrag" />').append(
									$('<div class="jspDragLeft" />'),
									$('<div class="jspDragRight" />')
								)
							),
							$('<div class="jspCap jspCapRight" />')
						)
					);

					horizontalBar = container.find('>.jspHorizontalBar');
					horizontalTrack = horizontalBar.find('>.jspTrack');
					horizontalDrag = horizontalTrack.find('>.jspDrag');

					if (settings.showArrows) {
						arrowLeft = $('<a class="jspArrow jspArrowLeft" />').bind(
							'mousedown.jsp', getArrowScroll(-1, 0)
						).bind('click.jsp', nil);
						arrowRight = $('<a class="jspArrow jspArrowRight" />').bind(
							'mousedown.jsp', getArrowScroll(1, 0)
						).bind('click.jsp', nil);
						if (settings.arrowScrollOnHover) {
							arrowLeft.bind('mouseover.jsp', getArrowScroll(-1, 0, arrowLeft));
							arrowRight.bind('mouseover.jsp', getArrowScroll(1, 0, arrowRight));
						}
						appendArrows(horizontalTrack, settings.horizontalArrowPositions, arrowLeft, arrowRight);
					}

					horizontalDrag.hover(
						function () {
							horizontalDrag.addClass('jspHover');
						},
						function () {
							horizontalDrag.removeClass('jspHover');
						}
					).bind(
						'mousedown.jsp',
						function (e) {
							// Stop IE from allowing text selection
							$('html').bind('dragstart.jsp selectstart.jsp', function () { return false; });

							horizontalDrag.addClass('jspActive');

							var startX = e.pageX - horizontalDrag.position().left;

							$('html').bind(
								'mousemove.jsp',
								function (e) {
									positionDragX(e.pageX - startX, false);
								}
							).bind('mouseup.jsp mouseleave.jsp', cancelDrag);
							return false;
						}
					);
					horizontalTrackWidth = container.innerWidth();
					sizeHorizontalScrollbar();
				} else {
					// no horizontal scroll
				}
			}

			function sizeHorizontalScrollbar() {

				container.find('>.jspHorizontalBar>.jspCap:visible,>.jspHorizontalBar>.jspArrow').each(
					function () {
						horizontalTrackWidth -= $(this).outerWidth();
					}
				);

				horizontalTrack.width(horizontalTrackWidth + 'px');
				horizontalDragPosition = 0;
			}

			function resizeScrollbars() {
				if (isScrollableH && isScrollableV) {
					var horizontalTrackHeight = horizontalTrack.outerHeight(),
						verticalTrackWidth = verticalTrack.outerWidth();
					verticalTrackHeight -= horizontalTrackHeight;
					$(horizontalBar).find('>.jspCap:visible,>.jspArrow').each(
						function () {
							horizontalTrackWidth += $(this).outerWidth();
						}
					);
					horizontalTrackWidth -= verticalTrackWidth;
					paneHeight -= verticalTrackWidth;
					paneWidth -= horizontalTrackHeight;
					horizontalTrack.parent().append(
						$('<div class="jspCorner" />').css('width', horizontalTrackHeight + 'px')
					);
					sizeVerticalScrollbar();
					sizeHorizontalScrollbar();
				}
				// reflow content
				if (isScrollableH) {
					pane.width((container.outerWidth() - originalPaddingTotalWidth) + 'px');
				}
				contentHeight = pane.outerHeight();
				percentInViewV = contentHeight / paneHeight;

				if (isScrollableH) {
					horizontalDragWidth = 1 / percentInViewH * horizontalTrackWidth;
					if (horizontalDragWidth > settings.horizontalDragMaxWidth) {
						horizontalDragWidth = settings.horizontalDragMaxWidth;
					} else if (horizontalDragWidth < settings.horizontalDragMinWidth) {
						horizontalDragWidth = settings.horizontalDragMinWidth;
					}
					horizontalDrag.width(horizontalDragWidth + 'px');
					dragMaxX = horizontalTrackWidth - horizontalDragWidth;
					_positionDragX(horizontalDragPosition); // To update the state for the arrow buttons
				}
				if (isScrollableV) {
					verticalDragHeight = 1 / percentInViewV * verticalTrackHeight;
					if (verticalDragHeight > settings.verticalDragMaxHeight) {
						verticalDragHeight = settings.verticalDragMaxHeight;
					} else if (verticalDragHeight < settings.verticalDragMinHeight) {
						verticalDragHeight = settings.verticalDragMinHeight;
					}
					verticalDrag.height(verticalDragHeight + 'px');
					dragMaxY = verticalTrackHeight - verticalDragHeight;
					_positionDragY(verticalDragPosition); // To update the state for the arrow buttons
				}
			}

			function appendArrows(ele, p, a1, a2) {
				var p1 = "before", p2 = "after", aTemp;

				// Sniff for mac... Is there a better way to determine whether the arrows would naturally appear
				// at the top or the bottom of the bar?
				if (p == "os") {
					p = /Mac/.test(navigator.platform) ? "after" : "split";
				}
				if (p == p1) {
					p2 = p;
				} else if (p == p2) {
					p1 = p;
					aTemp = a1;
					a1 = a2;
					a2 = aTemp;
				}

				ele[p1](a1)[p2](a2);
			}

			function getArrowScroll(dirX, dirY, ele) {
				return function () {
					arrowScroll(dirX, dirY, this, ele);
					this.blur();
					return false;
				}
			}

			function arrowScroll(dirX, dirY, arrow, ele) {
				arrow = $(arrow).addClass('jspActive');

				var eve, doScroll = function () {
					if (dirX != 0) {
						positionDragX(horizontalDragPosition + dirX * settings.arrowButtonSpeed, false);
					}
					if (dirY != 0) {
						positionDragY(verticalDragPosition + dirY * settings.arrowButtonSpeed, false);
					}
				},
					scrollInt = setInterval(doScroll, settings.arrowRepeatFreq);

				doScroll();

				eve = ele == undefined ? 'mouseup.jsp' : 'mouseout.jsp';
				ele = ele || $('html');
				ele.bind(
					eve,
					function () {
						arrow.removeClass('jspActive');
						clearInterval(scrollInt);
						ele.unbind(eve);
					}
				);
			}

			function initClickOnTrack() {
				removeClickOnTrack();
				if (isScrollableV) {
					verticalTrack.bind(
						'mousedown.jsp',
						function (e) {
							if (e.originalTarget == undefined || e.originalTarget == e.currentTarget) {
								var clickedTrack = $(this),
									scrollInt = setInterval(
										function () {
											var offset = clickedTrack.offset(), pos = e.pageY - offset.top;
											if (verticalDragPosition + verticalDragHeight < pos) {
												positionDragY(verticalDragPosition + settings.trackClickSpeed);
											} else if (pos < verticalDragPosition) {
												positionDragY(verticalDragPosition - settings.trackClickSpeed);
											} else {
												cancelClick();
											}
										},
										settings.trackClickRepeatFreq
									),
									cancelClick = function () {
										scrollInt && clearInterval(scrollInt);
										scrollInt = null;
										$(document).unbind('mouseup.jsp', cancelClick);
									};
								$(document).bind('mouseup.jsp', cancelClick);
								return false;
							}
						}
					);
				}
				if (isScrollableH) {
					horizontalTrack.bind(
						'mousedown.jsp',
						function (e) {
							if (e.originalTarget == undefined || e.originalTarget == e.currentTarget) {
								var clickedTrack = $(this),
									scrollInt = setInterval(
										function () {
											var offset = clickedTrack.offset(), pos = e.pageX - offset.left;
											if (horizontalDragPosition + horizontalDragWidth < pos) {
												positionDragX(horizontalDragPosition + settings.trackClickSpeed);
											} else if (pos < horizontalDragPosition) {
												positionDragX(horizontalDragPosition - settings.trackClickSpeed);
											} else {
												cancelClick();
											}
										},
										settings.trackClickRepeatFreq
									),
									cancelClick = function () {
										scrollInt && clearInterval(scrollInt);
										scrollInt = null;
										$(document).unbind('mouseup.jsp', cancelClick);
									};
								$(document).bind('mouseup.jsp', cancelClick);
								return false;
							}
						}
					);
				}
			}

			function removeClickOnTrack() {
				horizontalTrack && horizontalTrack.unbind('mousedown.jsp');
				verticalTrack && verticalTrack.unbind('mousedown.jsp');
			}

			function cancelDrag() {
				$('html').unbind('dragstart.jsp selectstart.jsp mousemove.jsp mouseup.jsp mouseleave.jsp');

				verticalDrag && verticalDrag.removeClass('jspActive');
				horizontalDrag && horizontalDrag.removeClass('jspActive');
			}

			function positionDragY(destY, animate) {
				if (!isScrollableV) {
					return;
				}
				if (destY < 0) {
					destY = 0;
				} else if (destY > dragMaxY) {
					destY = dragMaxY;
				}

				// can't just check if(animate) because false is a valid value that could be passed in...
				if (animate == undefined) {
					animate = settings.animateScroll;
				}
				if (animate) {
					jsp.animate(verticalDrag, 'top', destY, _positionDragY);
				} else {
					verticalDrag.css('top', destY);
					_positionDragY(destY);
				}

			}

			function _positionDragY(destY) {
				if (destY == undefined) {
					destY = verticalDrag.position().top;
				}

				container.scrollTop(0);
				verticalDragPosition = destY;

				var isAtTop = verticalDragPosition == 0,
					isAtBottom = verticalDragPosition == dragMaxY,
					percentScrolled = destY / dragMaxY,
					destTop = -percentScrolled * (contentHeight - paneHeight);

				if (wasAtTop != isAtTop || wasAtBottom != isAtBottom) {
					wasAtTop = isAtTop;
					wasAtBottom = isAtBottom;
					elem.trigger('jsp-arrow-change', [wasAtTop, wasAtBottom, wasAtLeft, wasAtRight]);
				}

				updateVerticalArrows(isAtTop, isAtBottom);
				pane.css('top', destTop);
				elem.trigger('jsp-scroll-y', [-destTop, isAtTop, isAtBottom]);
			}

			function positionDragX(destX, animate) {
				if (!isScrollableH) {
					return;
				}
				if (destX < 0) {
					destX = 0;
				} else if (destX > dragMaxX) {
					destX = dragMaxX;
				}

				if (animate == undefined) {
					animate = settings.animateScroll;
				}
				if (animate) {
					jsp.animate(horizontalDrag, 'left', destX, _positionDragX);
				} else {
					horizontalDrag.css('left', destX);
					_positionDragX(destX);
				}
			}

			function _positionDragX(destX) {
				if (destX == undefined) {
					destX = horizontalDrag.position().left;
				}

				container.scrollTop(0);
				horizontalDragPosition = destX;

				var isAtLeft = horizontalDragPosition == 0,
					isAtRight = horizontalDragPosition == dragMaxX,
					percentScrolled = destX / dragMaxX,
					destLeft = -percentScrolled * (contentWidth - paneWidth);

				if (wasAtLeft != isAtLeft || wasAtRight != isAtRight) {
					wasAtLeft = isAtLeft;
					wasAtRight = isAtRight;
					elem.trigger('jsp-arrow-change', [wasAtTop, wasAtBottom, wasAtLeft, wasAtRight]);
				}

				updateHorizontalArrows(isAtLeft, isAtRight);
				pane.css('left', destLeft);
				elem.trigger('jsp-scroll-x', [-destLeft, isAtLeft, isAtRight]);
			}

			function updateVerticalArrows(isAtTop, isAtBottom) {
				if (settings.showArrows) {
					arrowUp[isAtTop ? 'addClass' : 'removeClass']('jspDisabled');
					arrowDown[isAtBottom ? 'addClass' : 'removeClass']('jspDisabled');
				}
			}

			function updateHorizontalArrows(isAtLeft, isAtRight) {
				if (settings.showArrows) {
					arrowLeft[isAtLeft ? 'addClass' : 'removeClass']('jspDisabled');
					arrowRight[isAtRight ? 'addClass' : 'removeClass']('jspDisabled');
				}
			}

			function scrollToY(destY, animate) {
				var percentScrolled = destY / (contentHeight - paneHeight);
				positionDragY(percentScrolled * dragMaxY, animate);
			}

			function scrollToX(destX, animate) {
				var percentScrolled = destX / (contentWidth - paneWidth);
				positionDragX(percentScrolled * dragMaxX, animate);
			}

			function scrollToElement(ele, stickToTop, animate) {
				var e, eleHeight, eleWidth, eleTop = 0, eleLeft = 0, viewportTop, maxVisibleEleTop, maxVisibleEleLeft, destY, destX;

				// Legal hash values aren't necessarily legal jQuery selectors so we need to catch any
				// errors from the lookup...
				try {
					e = $(ele);
				} catch (err) {
					return;
				}
				eleHeight = e.outerHeight();
				eleWidth = e.outerWidth();

				container.scrollTop(0);
				container.scrollLeft(0);

				// loop through parents adding the offset top of any elements that are relatively positioned between
				// the focused element and the jspPane so we can get the true distance from the top
				// of the focused element to the top of the scrollpane...
				while (!e.is('.jspPane')) {
					eleTop += e.position().top;
					eleLeft += e.position().left;
					e = e.offsetParent();
					if (/^body|html$/i.test(e[0].nodeName)) {
						// we ended up too high in the document structure. Quit!
						return;
					}
				}

				viewportTop = contentPositionY();
				maxVisibleEleTop = viewportTop + paneHeight;
				if (eleTop < viewportTop || stickToTop) { // element is above viewport
					destY = eleTop - settings.verticalGutter;
				} else if (eleTop + eleHeight > maxVisibleEleTop) { // element is below viewport
					destY = eleTop - paneHeight + eleHeight + settings.verticalGutter;
				}
				if (destY) {
					scrollToY(destY, animate);
				}

				viewportLeft = contentPositionX();
				maxVisibleEleLeft = viewportLeft + paneWidth;
				if (eleLeft < viewportLeft || stickToTop) { // element is to the left of viewport
					destX = eleLeft - settings.horizontalGutter;
				} else if (eleLeft + eleWidth > maxVisibleEleLeft) { // element is to the right viewport
					destX = eleLeft - paneWidth + eleWidth + settings.horizontalGutter;
				}
				if (destX) {
					scrollToX(destX, animate);
				}

			}

			function contentPositionX() {
				return -pane.position().left;
			}

			function contentPositionY() {
				return -pane.position().top;
			}

			function initMousewheel() {
				container.unbind(mwEvent).bind(
					mwEvent,
					function (event, delta, deltaX, deltaY) {
						var dX = horizontalDragPosition, dY = verticalDragPosition;
						positionDragX(horizontalDragPosition + deltaX * settings.mouseWheelSpeed, false)
						positionDragY(verticalDragPosition - deltaY * settings.mouseWheelSpeed, false);
						// return true if there was no movement so rest of screen can scroll
						return dX == horizontalDragPosition && dY == verticalDragPosition;
					}
				);
			}

			function removeMousewheel() {
				container.unbind(mwEvent);
			}

			function nil() {
				return false;
			}

			function initFocusHandler() {
				pane.unbind('focusin.jsp').bind(
					'focusin.jsp',
					function (e) {
						if (e.target === pane[0]) { return; }
						scrollToElement(e.target, false);
					}
				);
			}

			function removeFocusHandler() {

				pane.unbind('focusin.jsp');
			}

			function initKeyboardNav() {
				var pressed, pressedTimer;
				elem.attr('tabindex', 0)
					.unbind('keydown.jsp')
					.bind(
						'keydown.jsp',
						function (e) {
							if (e.target !== elem[0]) {
								return;
							}
							var dX = horizontalDragPosition, dY = verticalDragPosition, step = pressed ? 2 : 16;
							switch (e.keyCode) {
								case 40: // down
									positionDragY(verticalDragPosition + step, false);
									break;
								case 38: // up
									positionDragY(verticalDragPosition - step, false);
									break;
								case 34: // page down
								case 32: // space
									scrollToY(contentPositionY() + Math.max(32, paneHeight) - 16);
									break;
								case 33: // page up
									scrollToY(contentPositionY() - paneHeight + 16);
									break;
								case 35: // end
									scrollToY(contentHeight - paneHeight);
									break;
								case 36: // home
									scrollToY(0);
									break;
								case 39: // right
									positionDragX(horizontalDragPosition + step, false);
									break;
								case 37: // left
									positionDragX(horizontalDragPosition - step, false);
									break;
							}

							if (!(dX == horizontalDragPosition && dY == verticalDragPosition)) {
								pressed = true;
								clearTimeout(pressedTimer);
								pressedTimer = setTimeout(function () {
									pressed = false;
								}, 260);
								return false;
							}
						}
					);
				if (settings.hideFocus) {
					elem.css('outline', 'none');
					if ('hideFocus' in container[0]) {
						elem.attr('hideFocus', true);
					}
				} else {
					elem.css('outline', '');
					if ('hideFocus' in container[0]) {
						elem.attr('hideFocus', false);
					}
				}
			}

			function removeKeyboardNav() {
				elem.attr('tabindex', '-1')
					.removeAttr('tabindex')
					.unbind('keydown.jsp');
			}

			function observeHash() {
				if (location.hash && location.hash.length > 1) {
					var e, retryInt;
					try {
						e = $(location.hash);
					} catch (err) {
						return;
					}

					if (e.length && pane.find(e)) {
						// nasty workaround but it appears to take a little while before the hash has done its thing
						// to the rendered page so we just wait until the container's scrollTop has been messed up.
						if (container.scrollTop() == 0) {
							retryInt = setInterval(
								function () {
									if (container.scrollTop() > 0) {
										scrollToElement(location.hash, true);
										$(document).scrollTop(container.position().top);
										clearInterval(retryInt);
									}
								},
								50
							)
						} else {
							scrollToElement(location.hash, true);
							$(document).scrollTop(container.position().top);
						}
					}
				}
			}

			function unhijackInternalLinks() {
				$('a.jspHijack').unbind('click.jsp-hijack').removeClass('jspHijack');
			}

			function hijackInternalLinks() {
				unhijackInternalLinks();
				$('a[href^=#]').addClass('jspHijack').bind(
					'click.jsp-hijack',
					function () {
						var uriParts = this.href.split('#'), hash;
						if (uriParts.length > 1) {
							hash = uriParts[1];
							if (hash.length > 0 && pane.find('#' + hash).length > 0) {
								scrollToElement('#' + hash, true);
								// Need to return false otherwise things mess up... Would be nice to maybe also scroll
								// the window to the top of the scrollpane?
								return false;
							}
						}
					}
				)
			}

			// Public API
			$.extend(
				jsp,
				{
					// Reinitialises the scroll pane (if it's internal dimensions have changed since the last time it
					// was initialised). The settings object which is passed in will override any settings from the
					// previous time it was initialised - if you don't pass any settings then the ones from the previous
					// initialisation will be used.
					reinitialise: function (s) {
						s = $.extend({}, s, settings);
						initialise(s);
					},
					// Scrolls the specified element (a jQuery object, DOM node or jQuery selector string) into view so
					// that it can be seen within the viewport. If stickToTop is true then the element will appear at
					// the top of the viewport, if it is false then the viewport will scroll as little as possible to
					// show the element. You can also specify if you want animation to occur. If you don't provide this
					// argument then the animateScroll value from the settings object is used instead.
					scrollToElement: function (ele, stickToTop, animate) {
						scrollToElement(ele, stickToTop, animate);
					},
					// Scrolls the pane so that the specified co-ordinates within the content are at the top left
					// of the viewport. animate is optional and if not passed then the value of animateScroll from
					// the settings object this jScrollPane was initialised with is used.
					scrollTo: function (destX, destY, animate) {
						scrollToX(destX, animate);
						scrollToY(destY, animate);
					},
					// Scrolls the pane so that the specified co-ordinate within the content is at the left of the
					// viewport. animate is optional and if not passed then the value of animateScroll from the settings
					// object this jScrollPane was initialised with is used.
					scrollToX: function (destX, animate) {
						scrollToX(destX, animate);
					},
					// Scrolls the pane so that the specified co-ordinate within the content is at the top of the
					// viewport. animate is optional and if not passed then the value of animateScroll from the settings
					// object this jScrollPane was initialised with is used.
					scrollToY: function (destY, animate) {
						scrollToY(destY, animate);
					},
					// Scrolls the pane by the specified amount of pixels. animate is optional and if not passed then
					// the value of animateScroll from the settings object this jScrollPane was initialised with is used.
					scrollBy: function (deltaX, deltaY, animate) {
						jsp.scrollByX(deltaX, animate);
						jsp.scrollByY(deltaY, animate);
					},
					// Scrolls the pane by the specified amount of pixels. animate is optional and if not passed then
					// the value of animateScroll from the settings object this jScrollPane was initialised with is used.
					scrollByX: function (deltaX, animate) {
						var destX = contentPositionX() + deltaX,
							percentScrolled = destX / (contentWidth - paneWidth);
						positionDragX(percentScrolled * dragMaxX, animate);
					},
					// Scrolls the pane by the specified amount of pixels. animate is optional and if not passed then
					// the value of animateScroll from the settings object this jScrollPane was initialised with is used.
					scrollByY: function (deltaY, animate) {
						var destY = contentPositionY() + deltaY,
							percentScrolled = destY / (contentHeight - paneHeight);
						positionDragY(percentScrolled * dragMaxY, animate);
					},
					// This method is called when jScrollPane is trying to animate to a new position. You can override
					// it if you want to provide advanced animation functionality. It is passed the following arguments:
					//  * ele          - the element whose position is being animated
					//  * prop         - the property that is being animated
					//  * value        - the value it's being animated to
					//  * stepCallback - a function that you must execute each time you update the value of the property
					// You can use the default implementation (below) as a starting point for your own implementation.
					animate: function (ele, prop, value, stepCallback) {
						var params = {};
						params[prop] = value;
						ele.animate(
							params,
							{
								'duration': settings.animateDuration,
								'ease': settings.animateEase,
								'queue': false,
								'step': stepCallback
							}
						);
					},
					// Returns the current x position of the viewport with regards to the content pane.
					getContentPositionX: function () {
						return contentPositionX();
					},
					// Returns the current y position of the viewport with regards to the content pane.
					getContentPositionY: function () {
						return contentPositionY();
					},
					// Returns whether or not this scrollpane has a horizontal scrollbar.
					getIsScrollableH: function () {
						return isScrollableH;
					},
					// Returns whether or not this scrollpane has a vertical scrollbar.
					getIsScrollableV: function () {
						return isScrollableV;
					},
					// Gets a reference to the content pane. It is important that you use this method if you want to
					// edit the content of your jScrollPane as if you access the element directly then you may have some
					// problems (as your original element has had additional elements for the scrollbars etc added into
					// it).
					getContentPane: function () {
						return pane;
					},
					// Scrolls this jScrollPane down as far as it can currently scroll. If animate isn't passed then the
					// animateScroll value from settings is used instead.
					scrollToBottom: function (animate) {
						positionDragY(dragMaxY, animate);
					},
					// Hijacks the links on the page which link to content inside the scrollpane. If you have changed
					// the content of your page (e.g. via AJAX) and want to make sure any new anchor links to the
					// contents of your scroll pane will work then call this function.
					hijackInternalLinks: function () {
						hijackInternalLinks();
					}
				}
			);
		}

		// Pluginifying code...

		settings = $.extend({}, $.fn.jScrollPane.defaults, settings);

		var ret;
		this.each(
			function () {
				var elem = $(this), jspApi = elem.data('jsp');
				if (jspApi) {
					jspApi.reinitialise(settings);
				} else {
					jspApi = new JScrollPane(elem, settings);
					elem.data('jsp', jspApi);
				}
				ret = ret ? ret.add(elem) : elem;
			}
		)
		return ret;
	};

	$.fn.jScrollPane.defaults = {
		'showArrows': false,
		'maintainPosition': true,
		'clickOnTrack': true,
		'autoReinitialise': false,
		'autoReinitialiseDelay': 500,
		'verticalDragMinHeight': 0,
		'verticalDragMaxHeight': 99999,
		'horizontalDragMinWidth': 0,
		'horizontalDragMaxWidth': 99999,
		'animateScroll': false,
		'animateDuration': 300,
		'animateEase': 'linear',
		'hijackInternalLinks': false,
		'verticalGutter': 4,
		'horizontalGutter': 4,
		'mouseWheelSpeed': 10,
		'arrowButtonSpeed': 10,
		'arrowRepeatFreq': 100,
		'arrowScrollOnHover': false,
		'trackClickSpeed': 30,
		'trackClickRepeatFreq': 100,
		'verticalArrowPositions': 'split',
		'horizontalArrowPositions': 'split',
		'enableKeyboardNavigation': true,
		'hideFocus': false
	};

})(jQuery, this);

/// <reference path="jQuery/jquery-1.4.1-vsdoc.js" />

//(function () {
var c_bi = "background-image";
var c_bp = "background-position";
var c_eob = "easeOutBounce";


// Site
function _backgroundPosition($self) {
	var bp = $self.css(c_bp);

	if (bp === undefined)
		bp = $self.css(c_bp + "-x") + " " + $self.css(c_bp + "-y");

	return bp;
};

function loadImage(src, callback) {
	if (src == "none")
		return;
	
	var run = false;

	var img = new Image();
	img.src = "";
	img.onload = function () {
		run = true;
		callback();
	};
	img.src = src.replace(/(^url\(["']*)|(["']*\)$)/g, "");
};

function animateLogo() {
	if ($("html.home-page").length == 0)
		return;

	var $logo = $("h1.logo");

	if ($logo.length == 0)
		return;

	loadImage($logo.css(c_bi), function () {
		setTimeout(function () {
			$("h1.logo")
					.animate({ top: 0 }, 1000, c_eob);
		}, 1);
	});
};

function buildNav() {
	$("nav li")
			.reach(function (i, self) {
				if ($("html.home-page").length == 0)
					return;

				loadImage($(self).css(c_bi), function () {
					setTimeout(function () {
						if (!$.browser.msie || $.browser.version >= 9) {
							var $self = $(self);
							$self.animate({ top: 0 }, 1000, c_eob);
						}
					}, 500 * i);
				});
			})
			.children()
				.hover(function (evt) {
					var $self = $(this).parent();

					var bpArr = _backgroundPosition($self).split(" ");
					var backgroundPosition = bpArr[0];

					if ($.browser.msie && $.browser.version < 9) {
						//$self.css("background-position", backgroundPosition + " -140px");
					}
					else
						$self.keyframe({
							75: {
								"background-position": backgroundPosition + " -250px"
							},
							150: {
								"background-position": backgroundPosition + " -500px"
							},
							225: {
								"background-position": backgroundPosition + " -750px"
							},
							300: {
								"background-position": backgroundPosition + " -1000px"
							},
							375: {
								"background-position": backgroundPosition + " -750px"
							},
							450: {
								"background-position": backgroundPosition + " -500px"
							},
							525: {
								"background-position": backgroundPosition + " -250px"
							},
							600: {
								"background-position": backgroundPosition + " 0"
							},
							675: {
								"background-position": backgroundPosition + " -250px"
							},
							750: {
								"background-position": backgroundPosition + " -500px"
							}
						});
				}, function (evt) {
					var $self = $(this).parent();

					var bpArr = _backgroundPosition($self).split(" ");
					var backgroundPosition = bpArr[0];

					if ($.browser.msie && $.browser.version < 9) {
						//$self.css("background-position", backgroundPosition + " 0");
					}
					else if ($self.hasClass("active")) {
						var timeout = $self.data("timeout");
						if (timeout)
							clearTimeout(timeout);

						var bgp = backgroundPosition;
						$self.data("timeout", setTimeout(function () {
							$self.stop().css("background-position", bgp + " -1250px");
						}, 750));
					}
				});

	var $shareHand = $("#share-hand");
	if ($shareHand.length > 0) {
		loadImage($shareHand.css(c_bi), function () {
			$("#share-hand")
				.animate({ left: 0, top: 0 }, 750)
				.mouseover(function (evt) {
					var $self = $(this);
					var count = 0;
					var limit = 2;

					$self.stop();

					function poke() {
						$self.animate({ left: -72, top: -17 }, 250, function () {
							$self.animate({ left: 0, top: 0 }, 250, function () {
								count += 1;
								if (count < limit)
									poke();
							});
						});
					};

					poke();
				});
		});
	}

	var $watchHand = $("#watch-hand");
	if ($watchHand.length > 0) {
		loadImage($watchHand.css(c_bi), function () {
			$("#watch-hand")
				.animate({ right: 0, top: 0 }, 750)
				.mouseover(function (evt) {
					var $self = $(this);
					var count = 0;
					var limit = 2;

					$self.stop();

					function poke() {
						$self.animate({ right: -72, top: -17 }, 250, function () {
							$self.animate({ right: 0, top: 0 }, 250, function () {
								count += 1;
								if (count < limit)
									poke();
							});
						});
					};

					poke();
				});
		});
	}
};

function siteInit() {
	setTimeout(function () {
		animateLogo();
		buildNav();
	}, 1);

	if (/iphone|ipad|ios/i.exec(navigator.userAgent) == null)
		$(".scroll-pane").jScrollPane({ maintainPosition: false, verticalDragMinHeight: 59, verticalDragMaxHeight: 59 });
};

// Movie
function movieEnd() {
	var $self = $(typeof arguments[0] == "string" ? "object[resource=" + arguments[0].replace("http://www.ybsmovies.co.uk/", "") + "swf]" : this);
	var $parent = $self.parent();

	$self.css({ display: "none" });

	var $container = $("<div />", { "class": "end-movie-splash" })
			.appendTo($parent);


	var clickEvent = function (evt) {
		evt.preventDefault();

		var $a = $(this);

		if ($a.hasClass("replay")) {
			movieInit();
			$(".end-movie-splash").remove();
			return;
		}

		var url = "?int_cmp=";

		if ($(".offset-stage").length > 0)
			url += "offset_movie";
		else if ($(".tracker-stage").length > 0)
			url += "tracker_movie";
		else if ($(".fixed-stage").length > 0)
			url += "fixed_movie";
		else url += "ftb_movie";

		if ($a.hasClass("yes"))
			url += "_yes";
		else if ($a.hasClass("no"))
			url += "_no";
		else url += "_bit";

		$.get(url, function () {
			movieInit();
			$(".end-movie-splash").remove();
		});
	};
	
	window.replayEvent = function() {
		$(".end-movie-splash iframe").animate({
			height: 366
		}, 1000, function() {
			movieInit();
			$(".end-movie-splash").remove();
		});
	};

	if ($(".offset-stage").length > 0 || $(".first-time-stage").length > 0) {
		$(".end-movie-splash").append($("<iframe />", {
			src: ($(".offset-stage").length > 0 ? "tools/video-spinner/index.html" : "tools/video-borrow/index.html"),
			seamless: "seamless",
			scrolling: "no",
			marginwidth: "0",
			marginheight: "0",
			frameborder:"0",
			vspace: "0",
			hspace:"0"
		}));
		
		if ($(".offset-stage").length > 0)
			$(".end-movie-splash iframe").animate({
				height: 579
			}, 1000);
	}
	else {
		$("<a />", { "class": "yes", href: "#", text: "Yes", click: clickEvent })
				.appendTo($container);

		$("<a />", { "class": "bit", href: "#", text: "A little bit", click: clickEvent })
				.appendTo($container);

		$("<a />", { "class": "no", href: "#", text: "Not really", click: clickEvent })
				.appendTo($container);

		$("<a />", {
			"class": "replay",
			href: "#",
			text: "Replay",
			click: clickEvent
		})
				.appendTo($container);
		
		$("<a />", {
			"class": "branch",
			href: "http://view.atdmt.com/action/p7aybm_YBSMMicrositefindlocalbranch_4",
			text: "Find your local branch",
			target: "_blank"
		})
				.appendTo($container);
				
		$("<a />", {
			"class": "appointment",
			href: "http://view.atdmt.com/action/p7aybm_YBSMMicrositebookanappointment_4",
			text: "Book an appointment",
			target: "_blank"
		})
				.appendTo($container);
	}
};

var tryCount = 0;
function playFlash(elem) {
	if (elem !== undefined && typeof elem.playMe == "function") {
		elem.playMe();
		tryCount = 0;
	}
	else if (elem === undefined || tryCount > 5) {
		tryCount = 0;
	}
	else {
		tryCount += 1;
		setTimeout(function () { playFlash(elem); }, 100);
	}
};

function tabChange(selector, on) {
	var $self = $(selector);
	var $parent = $self.parent();

	if (on)
		$parent.addClass("active");
	else $parent.removeClass("active");
};

function tabToggle(selector) {
	var $self = $(selector);
	var $parent = $self.parent();
	var index = $parent.index();

	tabChange(".tabs a", false);
	tabChange(selector, true);

	var switches = [];

	var isFixed, isOffset, isTracker, isFTB;
	//newM newR existM ftb

	$(".collapsiblePanel tbody tr").hide()

	switch (index) {
		case 0:
			switches = ["none", "block", "none", "none"];
			$(".collapsiblePanel tbody tr.newM").show();
			break;
		case 3:
			switches = ["none", "block", "none", "none"];
			$(".collapsiblePanel tbody tr.existM").show();
			break;
		case 4:
			switches = ["none", "block", "none", "block"];
			$(".collapsiblePanel tbody tr.ftb").show();
			break;
		case 1:
			switches = ["none", "block", "block", "none"];
			$(".collapsiblePanel tbody tr.newR").show();
			break;
		case 2:
			switches = ["block", "none", "none", "none"];
			break;
	}

	$(".existing-remort-panel").css({ display: switches[0] });
	$(".fixed-mort-panel, .offset-mort-panel, .tracker-mort-panel").css({ display: switches[1] });
	$(".rollover-mort-panel").css({ display: switches[2] });
	$(".ftb-mort-panel").css({ display: switches[3] });

	if (/iphone|ipad|ios/i.exec(navigator.userAgent) == null)
		$(".scroll-pane").data("jsp").reinitialise();
};

function movieInit() {
	if ($(".movie-container").length == 0)
		return;
	
	$("video")
			.one("ended", movieEnd);

	$(".movie-container")
			.children()
				.css({ display: "none" });

	var movieHtml;
	if ($(".offset-stage").length > 0)
		movieHtml = "<h2>What is an Offset account?</h2><p>An Offset account is a great option if you have savings. It can help to take years off your mortgage or even reduce your monthly repayments. <strong>Watch this short video to see if you might benefit.</strong></p>";
	else if ($(".tracker-stage").length > 0)
		movieHtml = "<h2>What is a Tracker mortgage?</h2><p>With a Tracker mortgage you could pay more if interest rates go up or you could save money if they go down. <strong>Find out more by watching this short video.</strong></p>";
	else if ($(".fixed-stage").length > 0)
		movieHtml = "<h2>What is a Fixed Rate mortgage?</h2><p>If you don't like surprises and would like to know that your monthly repayments will remain stable, a Fixed Rate mortgage could be the right choice for you. <strong>Find out more by watching this short video.</strong></p>";
	else movieHtml = "<h2>An introduction to mortgage for First Time Buyers</h2><p>If you're a first time buyer, getting on the property ladder can be expensive and complicated. <strong>This short video introduces some of the ways mortgage providers can help.</strong></p>";

	$("<div />", { "class": "movie-splash",
		"html": movieHtml
	})
			.appendTo(".movie-container")
			.click(function () {
				var $self = $(".movie-splash");
				var $parent = $self.parent();

				$self.remove();

				var $children = $parent.find("video, object");
				$children
					.css({ display: "block" });

				if ($children.is("video")) {
					try {
						$children[0].play();
					}
					catch (err) {
						playFlash($parent.find("object")[0]);
					}
				}
				else playFlash($children[0]);
			});

	if (typeof Cufon !== "undefined" && Cufon.replace)
		Cufon.replace(".movie-container h2", { letterSpacing: "-1px" });

	$(".tabs a").click(function (evt) {
		evt.preventDefault();

		tabToggle(this);
	});

	if ($(".first-time-stage").length > 0) {
		$(".tabs li:eq(0), .tabs li:eq(1), .tabs li:eq(2), .tabs li:eq(3)").css({ display: "none" });
		$(".tabs a:eq(4)").click();
	}
	else {
		$(".tabs a:eq(0)").click();
	}

	$("aside.offset-tool").click(function (evt) {
		location = $(this).children("a").attr("href");
	});
};

// Home
function growElement(selector, height, delay) {
	var $elem = $(selector);

	if ($elem.length == 0)
		return;

	loadImage($elem.css(c_bi), function () {
		setTimeout(function () {
			$elem.animate({ height: height }, 1000);
		}, delay);
	});
};

function homeInit() {
	if ($("html").hasClass("enhanced")) {
		growElement("#hill-4", 424, 1000);
		growElement("#hill-2", 424, 1250);
		growElement("#hill-3", 424, 1500);
		growElement("#hill-1", 424, 1750);
	}
	
	if (!$("html").hasClass("csstransitions"))
		$(".quick-links").hover(function() {
			$(".quick-links").addClass("hover");
		}, function() {
			$(".quick-links").removeClass("hover");
		});
};

// Accordian
var accordianSpeed = 500;
function hideAll() {
	var $self = $(".accordian .active");

	$self
			.removeClass("active")
			.children("h2")
				.css("background-position", "0 0");

	if (typeof Cufon !== "undefined" && Cufon.replace)
		Cufon.replace("h2", { letterSpacing: "-1px" });

	$self
			.children("div")
				.animate({
					height: 0
				}, accordianSpeed);
};

function showSection($self, height) {
	$self
			.find("iframe")
				.each(function () {
					var $iframe = $(this);
					var src = $iframe.data("src");
					if (src) {
						$iframe.attr("src", src);
						$iframe.data("src", false)
					}
				})
				.end()
			.addClass("active")
			.children("h2")
				.css("background-position", "0 -48px");

	if (typeof Cufon !== "undefined" && Cufon.replace)
		Cufon.replace("h2", { letterSpacing: "-1px" });

	$self
			.children("div")
				.animate({
					height: height
				}, accordianSpeed);
};

function accordianInit() {
	$(".accordian section")
			.children("h2")
				.click(function (evt) {
					evt.preventDefault();
					var $parent = $(this).parent();
					var isActive = ($parent.hasClass("active"));

					hideAll();

					if (!isActive)
						showSection($parent, ($parent.data("height") || 300));
				})
				.end()
			.children("div")
				.css({ height: 0 });

	if (location.hash && location.hash != "") {
		var $target = $(location.hash);
		if ($target.parent().hasClass("accordian")) {
			$target.children("h2").click();
			setTimeout(function () {
				scrollTo(0, 0);
			}, 1);
		}
	}
};

$(function () {
	siteInit();
	homeInit();
	movieInit();
	accordianInit();


	if ($.browser.msie && $.browser.version < 8)
		setInterval(function () {
			var $ac = $("#fa_autosuggest");
			var $sc = $(".social-container");
			if ($ac.css("visibility") == "visible")
				$sc.css({ visibility: "hidden" });
			else $sc.css({ visibility: "visible" });
		}, 500);
});
//})();

function faqtagent() {
	var search = document.getElementById("searchtext").value;
	var path = "http://www.ybs.co.uk/faq/index.html?search=" + search;
	window.open(path, 'FaqtAgent', 'top=150,width=846,height=668,scrollbars=no,menubar=no,toolbar=no,resizable=no');
	return true;
};

