



FC.vars = {

	selectors : {

		TOOLTIP_HOLDER : '.tooltip',

		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'

	},

	paths : {

		BGIFRAME : 'javascript/jquery.bgiframe.min.js'

	}	

};



FC.thickboxCloseAndReload = function(){

	tb_remove(); 

	window.location.reload();

}



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.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; 

		__carousel.$scroller.scrollTo(__carousel.$carouselItem[__carousel.currentIncrement], 400, {axis:'x'});

		

		// set state of button

		switch (__carousel.currentIncrement) {

			case 0 : 

				__nextIsOn = true;

				__previousIsOn = false;

				break;

			case __carousel.$carouselItem.length - 1:

				__nextIsOn = false;

				__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, false, this);

		}

	});

}







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();

});













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 : 'javascript/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.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; 

		__carousel.$scroller.scrollTo(__carousel.$carouselItem[__carousel.currentIncrement], 400, {axis:'x'});

		

		// set state of button

		switch (__carousel.currentIncrement) {

			case 0 : 

				__nextIsOn = true;

				__previousIsOn = false;

				break;

			case __carousel.$carouselItem.length - 1:

				__nextIsOn = false;

				__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, false, 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;

	$(__.CAROUSEL).length ? FC.scroller() : null;

	FC.convertThickboxLinks();

});





function ToggleUser() {

    var intSelectedRadio = $("input[name='EXISTINGUSER']:checked").val();

    if (intSelectedRadio == '') {

        $("#newUserForm").show();
        $("#oldUserForm").hide();
        $("#NewMemberPassword").show();

    } else {
    
	      $("#newUserForm").hide();
	      $("#oldUserForm").show();
          $("#NewMemberPassword").hide();
      }

      if (PerformExtraToggleUserLogic) {
          PerformExtraToggleUserLogic();
      }

}




function ShowHide(id) {
obj = document.getElementsByTagName("div");

if (obj[id].style.display == 'block'){

obj[id].style.display = 'none';

obj[id].style.height = '0px';

}

else {

obj[id].style.display = 'block';

obj[id].style.height = 'auto';

}

}





function ShowHide1(){

	$(".ShowHide1").animate({"height": "toggle"}, { duration: 1000 });

}

function ShowHide2(){

	$(".ShowHide2").animate({"height": "toggle"}, { duration: 1000 });

}

function ShowHide3(){

	$(".ShowHide3").animate({"height": "toggle"}, { duration: 1000 });

}

function ShowHide4(){

	$(".ShowHide4").animate({"height": "toggle"}, { duration: 1000 });

}

function ShowHide5(){

	$(".ShowHide5").animate({"height": "toggle"}, { duration: 1000 });

}

function ShowHide6(){

	$(".ShowHide6").animate({"height": "toggle"}, { duration: 1000 });

}

function ShowHide7(){

	$(".ShowHide7").animate({"height": "toggle"}, { duration: 1000 });

}

function ShowHide8(){

	$(".ShowHide8").animate({"height": "toggle"}, { duration: 1000 });

}

function ShowHide9(){

	$(".ShowHide9").animate({"height": "toggle"}, { duration: 1000 });

}



function ShowHideVRM(){

	$("#enterNewVRM").animate({"height": "toggle"}, { duration: 1000 });

}



function ShowHideFAQ(faqnum){

	$('#faq'+faqnum).animate({"height": "toggle"}, { duration: 1000 });

}



function ShowHideCardTypeON(){

      	if(document.getElementById('IssueNumber').style.display =='none') 

	  {

      	$("#IssueNumber").animate({"height": "toggle"}, { duration: 1000 });

		$("#CardStartDate").animate({"height": "toggle"}, { duration: 1000 });

      }

}

function ShowHideCardTypeOFF(){

	if(document.getElementById('IssueNumber').style.display =='block') 

	  {

      	$("#IssueNumber").animate({"height": "toggle"}, { duration: 1000 });

		$("#CardStartDate").animate({"height": "toggle"}, { duration: 1000 });

      }

}


function ShowHideVRM2() {

    var VRMState = $('#PurchaseVRM').css('display');

    if (VRMState != 'block') { $("#PurchaseVRM").animate({ "height": "toggle" }, { duration: 1000 }); }

}

function ShowHideVRM3() {

    var VRMState = $('#PurchaseVRM').css('display');

    if (VRMState == 'block') { $("#PurchaseVRM").animate({ "height": "toggle" }, { duration: 1000 }); }

}



function ShowHideSaleTypeOn(){

      	if(document.getElementById('VehicleOther').style.display =='none') 

	  {

      	$("#VehicleOther").animate({"height": "toggle"}, { duration: 1000 });

      }

}

function ShowHideSaleType(){

	if(document.getElementById('VehicleOther').style.display =='block') 

	  {

      	$("#VehicleOther").animate({"height": "toggle"}, { duration: 1000 });

      }

}

function disableAutoFill(){
	var b = $('#AutoFillButton');
	if (b.hasClass('alt-large-button-greyed'))
	{
		b.removeAttr('disabled');
		b.removeClass('alt-large-button-greyed');
		b.addClass('alt-large-button');
	}
	else
	{
		b.attr('disabled','true');
		b.removeClass('alt-large-button');
		b.addClass('alt-large-button-greyed');
	}
}



















