Cufon.now();
$(function () {
	if ($("#currency-container").length)
	{
		setupMarketNews ();
	}
	if ($(".banner_panels").length)
	{
		$(".banner_panels").bannerFade();
	}
	if ($(".location-container").length)
	{
		$(".location-container").hide(),
		$("#clicker-map a").click (function () {
			$(".location-container").hide();
			$($(this).attr('href')).show();
			return false;
		}),
		$("#clicker-map a span").hide(),
		$("#clicker-map a").hover (function () {
				el = $(this).find("span")[0];
				$(el).css('margin-top', '10px').animate({'marginTop': 0}, 300);
		});
	}
});

function setupMarketNews ()
{
	var height = 0;
	$("#currency-container div").each (function () {
		height = height > $(this).height() ? height : $(this).height();
	});
	$("#currency-container").css("height", height).css('position', 'relative');
	$("#currency-container div").css ("position", "absolute").css('top', 0).css('left',0);
	fallback = true;
	if (location.hash)
	{
		if ($("#currency-container").find(location.hash).length)
		{
			$("#currency-container div").hide();
			$("#currency-container div" + location.hash).show();
			$("#currency-clicker a").css("font-weight", "normal");
			$("#currency-clicker a[href="+location.hash+"]").css("font-weight", "bold");
			iefix();
			fallback = false;
		}
	}
	else if (fallback)
	{
		$("#currency-container div:gt(0)").hide();
		$("#currency-clicker a[href=#gbp]").css("font-weight", "bold");
	}
	$("#currency-clicker a").click (function () {
		$("#currency-clicker a").css("font-weight", "normal");
		$(this).siblings("a").andSelf().css("font-weight", "bold");
		$("#currency-container div").fadeOut();
		$("#currency-container div" + $(this).attr("href")).fadeIn();
		iefix ();
		return false;
	});

	function iefix()
	{
		if ($.browser.msie && $.browser.version < 7)
			$("#primary").css("zoom", "1");
	}
}



jQuery.extend( jQuery.easing,
{
def: 'easeOutQuad',
	def: 'easeOutQuad',
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	}
});


jQuery.easing['jswing'] = jQuery.easing['easeOutQuad'];


/**
 * jquery.bannerFade.js
 * Date: 11 June 2009
 * 
 * Author: Clinton Montague
 * Mail: clinton@oneltd.co.uk
 */

(function ($)
{
	$.fn.bannerFade = function (args)
	{
		settings = $.extend({
			selector: '.banner_panel',
			nextButton: '.next_arrow',
			prevButton: '.prev_arrow',
			delay: 8000,
			initialDelay: 8000
		}, args || {});
		var container = this;
		var elems = $(this).find (settings.selector);
		total = elems.length;
		var curr = 0;
		function setup ()
		{
			$(".hide_unless_javascript").show();
			$(container).css("position", "relative");
			$(elems).css ("position", "absolute")
							.css('top',0)
							.css('left',0)
							.css("width", $(container).width())
							.css('height', $(container).height())
							.each (function (index) 
							{
								$(this).data('idx', index);
							})
							.hide();
			$($(elems)[0]).show();
			$(".banner_panel_tabs").css ("z-index", 999);
			$(".banner_panel_tabs li:not(.hide_unless_javascript) a").each (function ()
			{
				$(this).click(function () {
					goTo($($(this).attr("href")).data('idx'));
					return false;
				});
			});
			$(settings.nextButton).click (function () {
				forwards();
				return false;
			});
			$(settings.prevButton).click (function () {
				backwards();
				return false;
			});
			$(".banner_panel_tabs li:not(.hide_unless_javascript) a[href=#" + $(settings.selector + ":first-child").attr("id") + "]").addClass("active");
		};
		
		function forwards ()
		{
			goTo ((++curr)%total);
			setTimeout(function () {forwards()}, settings.delay); 
		}
		
		function backwards ()
		{
			goTo ((--curr)%total);
		}
		
		function goTo (idx)
		{
			if (idx < 0 || idx >= total)
			{
				return false;
			}
			transOut($($(elems).filter(":not(:nth-child("+idx+1+"))")))
			transIn($($(elems)[idx]));
			$(".banner_panel_tabs a").removeClass("active");
			$(".banner_panel_tabs a[href=#" + $($(elems)[idx]).attr('id') + "]:not("+settings.prevButton+","+settings.nextButton+")").addClass("active");
			curr = idx;
		}
		
		function transOut (els)
		{
			$(els).css('z-index', 200);
			$(els).fadeOut('slow');
		}
		
		function transIn (els)
		{
			$(els).css('z-index', 100);
			$(els).show();
		}
		if ((elems).length)
		{
			setup ();
		}
		setTimeout (function () {forwards()}, settings.initialDelay);
		return container;
	}
})(jQuery);

function initExternalLinks() {
	httpEx = /https?:\//;
	hostEx = /https?:\/\/([A-Za-z0-9-_.]*?travelex.dev[A-Za-z0-9-_.]*?|(www.)?travelexbusiness.com)\//;
	$("a").each (function () {
		hrf = $(this).attr("href");
		if ((hrf.match(httpEx) /* can only be external if it has a http */
					&& !hrf.match (hostEx) /* checking the hostname is also important */
				||
					hrf.match (hostEx) 
					&& hrf.split('/',4)[3]!==location.href.split('/',4)[3]
				||
					!hrf.match (httpEx) /* deal with /na/ going to /hk/ */
					&& hrf.split('/',2)[1]!==location.href.split('/',4)[3]
				) && /* now check to see if it's not just a hash */
					hrf.substring(0,1) !== '#'
				)
		{
			$(this).click (function () {
				$(this).attr("target", "_blank");
			});
		}
	});
}

initExternalLinks();