FC.vars = {
	selectors : {
		TOOLTIP_HOLDER : '.tooltip',
		ALERTS_BOX : '.alerts-box',
		ALERT_SUMMARY : '.alert-summary',
		ALERT_DETAILS : '.alert-details',
		HIDE_ALERT_ANCHOR : '.hide-alert a',
		DESCRIPTION : '.description',
		DATE : '.date',
		
		CAROUSEL : ".carousel",
		NEXT : ".next",
		PREVIOUS : ".previous",
		SCROLLER : ".scroller",
		SCROLLER_INNER : ".scroller-inner",
		CAROUSEL_ITEM : '.carousel-item',
		
		PROTECTION_HEAD_LI : '.protection-head li',
		PROTECTION_HEAD_A : '.protection-head a',
		PROTECTION_BODY_DIV : '.protection-body > div'
	},
	paths : {
		BGIFRAME : 'Scripts/jquery.bgiframe.min.js'
	}	
};

FC.tooltip = function(){
	
	if(jQuery.browser.msie && (jQuery.browser.version < 7))	$.getScript(FC.vars.paths.BGIFRAME);
			
	$(FC.vars.selectors.TOOLTIP_HOLDER).each(function(){
		var __split = [];
		var __content;	
		if($(this).find('img').length > 0){
			__split = $(this).find('img').attr('alt').split(' - ');
			__content = '<h3>' + __split[0] + '</h3><p>' + __split[1] + '</p>';
			$(this).find('a').removeAttr('title');
		} else{
			__split = $(this).find('a').attr('title').split(' - ');
			__content = '<h3>' + __split[0] + '</h3><p>' + __split[1] + '</p>';
			$(this).find('a').removeAttr('title');
		}
		
		$(this).append('<div class="tooltip-bottom" style="display:none"><div class="tooltip-top clear"><div class="padding clear"><a href="#" class="close" style="display:none">close</a>' + __content + '</div></div></div>');
		if(!FC.hasIE) $(".tooltip-bottom", this).css("opacity", "0");
		
		$(this).find('a:first').bind('click keypress', function(e){
			switch (e.keyCode) {
				case 9:
				case 16:
				case 18:
				case 17:
					return;
				default:
					if($(this).siblings('.tooltip-bottom').hasClass('persist')){
						$(this).siblings('.tooltip-bottom').removeClass('persist').find('.close').css('display','none').unbind('click keypress');
						if(FC.hasIE){$(this).parents('.tooltip').css('z-index','100')};
						FC.hasIE ? $(this).siblings('.tooltip-bottom').css("display","none") : $(this).siblings('.tooltip-bottom').stop().animate({"opacity":0},800, function(){
							$(this).css("display","none");
							$(this).parents('.tooltip').css('z-index','100');
						});
					} else {
						$(this).siblings('.tooltip-bottom').addClass('persist').find('.close').css('display','block').bind('click keypress', function(e){
							switch (e.keyCode) {
								case 9:
								case 16:
								case 18:
								case 17:
									return;
								default:
									$(this).parents('.tooltip').find('a')[0].focus();
									$(this).css('display','none').unbind('click keypress');
									if(FC.hasIE){$(this).parents('.tooltip').css('z-index','100')};
									FC.hasIE ? $(this).parents('.tooltip-bottom').removeClass('persist').css("display","none") : $(this).parents('.tooltip-bottom').removeClass('persist').stop().animate({"opacity":0},200, function(){
										$(this).css("display","none");
										$(this).parents('.tooltip').css('z-index','100');
									});
									
									return false;
							}
						});
						if (FC.hasIE) {
							$(this).siblings('.tooltip-bottom').css("display", "block");
							if ($.fn.bgiframe) $(this).bgiframe();
						} else {
							$(this).siblings('.tooltip-bottom').stop().css("display", "block").animate({"opacity": 1}, 400);
						}
						$(this).parent().css('z-index','110');
					}
					return false;
			}
		})			
		
		$(this).bind('mouseenter', function(){
			if(FC.hasIE){
				$(this).find('.tooltip-bottom').css("display","block");
				if($.fn.bgiframe) $(this).find('.tooltip-top').bgiframe();
			} else {
				$(this).find('.tooltip-bottom').stop().css("display","block").animate({"opacity":1},400);
			}
			$(this).css('z-index','110');
			$(this).find('img').attr('title', '');
		}).bind('mouseleave', function(){
			if($(this).find('.tooltip-bottom').hasClass('persist')){
				//do nothing
			} else {
				if(FC.hasIE){$(this).css('z-index','100');};
				FC.hasIE ? $(this).find('.tooltip-bottom').css("display","none") : $(this).find('.tooltip-bottom').stop().animate({"opacity":0},800, function(){
					$(this).css("display","none");
					$(this).parent().css('z-index','100');
				});
				
			}
			$(this).find('img').removeAttr('title');
		})
	})
};

FC.alertShowHide = function () {
	var __ = FC.vars.selectors;
	
	var __$alertsBox = $(__.ALERTS_BOX),
		__alertSummary,
		__alertDetails,
		__descriptionCssObject = {'margin-right' : '100px'};
	
	__$alertsBox.each(function () {
		__$alertDetails = $(__.ALERT_DETAILS, this);
		
		// heading
		$(__.ALERT_SUMMARY, this).each(function (i) {
			var __$this = $(this);
			
			$(__.DESCRIPTION, this).css(__descriptionCssObject);
			
			if (i) {
				this.isOpen = false;
				$(__.DATE, this).after('<p class="hide-alert"><a href="#">show alert</a></p>');
			} else {
				this.isOpen = true;
				$(__.DATE, this).after('<p class="hide-alert"><a href="#">hide alert</a></p>');
			}
			
			$(__.HIDE_ALERT_ANCHOR ,this).bind("click", {sibling : $(__$alertDetails[i]), parent : this}, function (e) {
				var __$sibling = e.data.sibling;
				var __parent = e.data.parent;
				if (__parent.isOpen === true) {
					__parent.isOpen = false;
					$(this).text("show alert");
					__$sibling.stop(false, true);
					__$sibling.find('.button').hide(); // Works around an issue in IE 7 and 6 where button would stay visible during slide
					__$sibling.slideUp(0);
				} else {
					__parent.isOpen = true;
					$(this).text("hide alert");
					__$sibling.stop(false, true);
					__$sibling.slideDown(0, function(){
						__$sibling.find('.button').show(); // Works around an issue in IE 7 and 6 where button would stay visible during slide
					});
				}
				
				FC.stopReturn(e)
			});
		});
		
		// content
		__$alertDetails.each(function (i) {
			if (i) {
				$(this).hide();
				$(this).find('.button').hide();
			}
		});
	})
};

FC.scroller = function (){
	var __ = FC.vars.selectors;
		
	function doSlider (e) { // receives an Event Object
		var __carousel = e.data.carousel,
			__nextIsOn,
			__previousIsOn;
			
		// set view of carousel
		__carousel.currentIncrement += (e.data.direction) ? 1 : -1; 
		
		if (__carousel.currentIncrement == -1)
			__carousel.currentIncrement = __carousel.$carouselItem.length - 1;
		
		if (__carousel.currentIncrement >= __carousel.$carouselItem.length)
			__carousel.currentIncrement = 0;
		
		__carousel.$scroller.scrollTo(__carousel.$carouselItem[__carousel.currentIncrement], 400, {axis:'x'});
		
		// set state of button
		switch (__carousel.currentIncrement) {
			case 0 : 
				__nextIsOn = true;
				__previousIsOn = true;
				break;
			case __carousel.$carouselItem.length - 1:
				__nextIsOn = true;
				__previousIsOn = true;
				break;
			default :
				__nextIsOn = true;
				__previousIsOn = true;
		}
		
		setButtonViewAndBehaviour(__carousel.$next, true, __nextIsOn, __carousel);
		setButtonViewAndBehaviour(__carousel.$previous, false, __previousIsOn, __carousel);
			
		FC.stopReturn(e);
	}
	
	function setButtonViewAndBehaviour (button, direction, isEnabled, carousel) {
		if (isEnabled) {
			// set view
			button.addClass("on");
			button.removeClass("off");
			
			// set behaviour
			button.css({cursor:"pointer"});
			button.bind('click keypress', {direction : direction, carousel : carousel}, doSlider);
		} else {
			// set view 
			button.removeClass("on");
			button.addClass("off");
			
			// set behaviour
			button.css({cursor:"default"});
			button.unbind();
		}
	}
	
	$(__.CAROUSEL).each(function (i) {
		this.$carouselItem = $(__.CAROUSEL_ITEM, this);
		
		if (this.$carouselItem.length > 1) {
			this.currentIncrement = 0;
			this.$scroller = $(__.SCROLLER, this);
			this.$next = $(__.NEXT, this);
			this.$previous = $(__.PREVIOUS, this);
			
			// set carousel view
			this.className += " isCarousel"; 
			$(__.SCROLLER_INNER, this).width(this.$carouselItem.length * this.$carouselItem.width());	
			
			setButtonViewAndBehaviour(this.$next, true, true, this);
			setButtonViewAndBehaviour(this.$previous, false, true, this);
		}
	});
}

FC.setProtectionTabs = function () {
	var __ = FC.vars.selectors;
	var __$protectionBodyDiv = $(__.PROTECTION_BODY_DIV),
		__opacityOff = {opacity : 0, display : 'none'};
	
	__$protectionBodyDiv.each(function (i) {
		if (i) {
			$(this).css(__opacityOff);
		} else {
			$(this).css({opacity : 1, display : 'block'})
		}
	});
	
	var __$protectionHeadA = $(__.PROTECTION_HEAD_A);
	var __$currentLi = $(__.PROTECTION_HEAD_LI + ".selected");
	
	__$protectionHeadA.bind('click', function (e) {
		var __href = this.href,
			__currentHref,
			__$outDiv,
			__$inDiv,
			__$parentLi = $(this).parents('li');
		
		if (__$parentLi[0].className == 'selected') {
			return FC.stopReturn(e);
		}
		
		__$currentLi.removeClass('selected');		
		__currentHref = $("a", __$currentLi)[0].href;
		__$parentLi.addClass('selected');
		
		__$protectionBodyDiv.each(function (i) {
			if(__currentHref.indexOf(this.className) != -1) {
				__$outDiv = $(this);
			}
			
			if (__href.indexOf(this.className) != -1) {
				__$inDiv = $(this);
			}
		});
		
		__$outDiv.animate({opacity : 0}, 500, function () {
			this.style.display = 'none';
			__$inDiv[0].style.display = 'block';
			__$inDiv.animate({opacity : 1}, 500);
		})
		
		__$currentLi = __$parentLi;
		
		return FC.stopReturn(e);
	});
};

FC.convertThickboxLinks = function() {
	$('a.thickbox').each(function(){
		// For non-JavaScript users, thickbox links point to full pages, with the site navigation etc.
		// When JavaScript is enabled, change the links to point to pages just containing the content, minus site navigation etc., so that they look sensible within thickbox.
		this.href = this.href.replace('_non-js', '');
	});
}

$(function(){
	var __ = FC.vars.selectors;
	
	FC.setJS();
	$(__.TOOLTIP_HOLDER).length ? FC.tooltip() : null;
	$(__.ALERTS_BOX).length ? FC.alertShowHide() : null;
	$(__.CAROUSEL).length ? FC.scroller() : null;
	$(__.PROTECTION_HEAD_A).length ? FC.setProtectionTabs() : null;
	FC.convertThickboxLinks();
});

///*Start UK08574 20100415*/
function showArrrow(boxNum)
{
	i = 1;
	do
	{
		var theBox = document.getElementById('lst'+i);
	
        if (theBox != null)
		{
			if (i == boxNum)
			{
				theBox.className = theBox.className + ' ' + "selected";
			}
			else
			{
				if (theBox.className.substring(0,3) == 'end')
				{
					theBox.className = 'end';
				}
				else
				{
					theBox.className = '';
				}
			}
        }
		i++;
    }
	while(theBox !=null)                
}
///*END UK08574*/


