var current = 1;


var timer = setTimeout("FC.openButtons()",1500);

var FC = {
	
	tooltip : function(){ 
	// in order to get this function to fire, you need to call it (below), including the name of the container div and a value for the positioning of the tooltip div
		/*@cc_on 
			@if (@_jscript_version <= 5.7) 
				$.getScript('javascript/jquery.bgiframe.min.js'); 
			@end 
		@*/
	  $('.help-tooltip').each(function(i, trig) {
			var leftVar = 430; // when calling this function, pass in a value (i) for the positioning of the tooltip
			var distance = -8;
			var time = 100;
			var hideDelay = 100;
			var hideDelayTimer = null;
			var beingShown = false;
			var shown = false;
			var trigger = $(trig, this);
			var popup = $('.tooltip', this).css('opacity', 0);
			
			$([trigger.get(0), popup.get(0)]).bind("mouseover focus", function(){
																			   
				//get the real height
				var actualHeight = popup.height() + parseInt(popup.css('paddingTop')) + parseInt(popup.css('paddingBottom'));
				if (hideDelayTimer) clearTimeout(hideDelayTimer);
				if (beingShown || shown) {
					return;
				} else {
					beingShown = true;
					/*@cc_on
						@if (@_jscript_version <= 5.7) 
							popup.parent('.tooltip-wrapper').bgiframe();
						@end 
					@*/
					//animate the window
					popup.css({bottom: -actualHeight,left: leftVar,display: 'block', zIndex : 9997})
					.animate({bottom: '+=' + distance + 'px',opacity: 1}, time, 'swing', function() {
						beingShown = false;shown = true;});
					}
			}).bind("mouseout blur", function(){
				if (hideDelayTimer) clearTimeout(hideDelayTimer);
				hideDelayTimer = setTimeout(function() {
					hideDelayTimer = null;
					popup.animate({bottom: '-=' + distance + 'px', opacity: 0}, time, 'swing', function() {
						shown = false;popup.css('display', 'none');});
					},
				hideDelay);
			});
		});
	},
	
	showHideFAQ: function(){
    $('.faq dd').hide();
		$('.faq dt').bind('click', function(){
			if($(this).hasClass('active')){
				$(this).removeClass('active');
				$(this).next('dd').toggle(100);
				return false;	
			}else{
				$(this).addClass('active');
				$(this).next('dd').toggle(100);
				return false;	
			}
		});
 
	},

	showHideSitemapLinks: function(){
		$('.sitemap dd').hide();
		$('.sitemap dt').bind('click', function(){
			if($(this).hasClass('active')){
				$(this).removeClass('active');
				$(this).next('dd').toggle(100);
				return false;	
			}else{
				$(this).addClass('active');
				$(this).next('dd').toggle(100);
				return false;	
			}
		});
 
	},	

	openButtons: function(){
		$(".hero .button-container ul li a").animate({marginLeft:"-2px"},500);
	},

	cycle: function(){
	
		$("#hero-"+current).fadeOut(250,function(){
			$('.active', '.hero-links').removeClass('active');
			current++;
			if(current==5){current=1;}
			$("#hero-"+current).fadeIn(250, function(){
				homeLoader();
				$('.hero-'+current).parents('li').addClass('active');
			});		
		});
	},

	showHideHero: function(){
		
		
		var __int = setInterval("FC.cycle()",6000);
		$('.hero').hide();
		$('#hero-1').show();
			
		$('.hero-links li').bind('mouseover focus', function(){
			clearInterval(__int);
			$("#hero-"+current).stop(true,true);
												 
															 
			// make the current list item selected
			$('.active', '.hero-links').removeClass('active');
			$(this).addClass('active');	
			
			// make the correct div show
			var __targ = "#" + $(this).children('a').attr('class');
			$('.hero').hide();
			$(__targ).show();
			homeLoader();
			
			return false;
		});
		
		$(".hero-links li").bind("mouseout blur", function(){
			current = $(".active").children('a').attr("class");
			current = current.slice((current.length) - 1);
			__int = setInterval("FC.cycle()",6000);
		});

	},
	
	showHideTabs: function(){
		$('.tab-wrapper').hide();
		$('#tab-1').show();
		
		$('.bottomTextWrapper').css({bottom:"1px"});
		
		$('.tabs li a').bind('click', function(){
			// make the current tab selected
			$(".selected", ".tabs").removeClass("selected")
			$(this).parents('li').addClass("selected");
			
			// do the tab content
			var __activeTab = '#' + $(this).attr('class');
			$('.tab-wrapper').hide();
			$(__activeTab).show();
			
			return false;
		});
	
	
	}
}
$(function () { 
	
	if($(".faq").length){FC.showHideFAQ();}
	if($(".sitemap").length){FC.showHideSitemapLinks();}
	if($(".helpbutton").length){FC.tooltip('430', '.helpbutton');}	
	if($(".hero-links").length>0){
		FC.showHideHero();
	}	
	if($('.tab-wrapper').length){FC.showHideTabs();}	

	
});

function PSpopUp(source)
{
  var x = screen.width;
	var y = screen.height;
	if(x > 799)
  {
    y = screen.height - 80;
	}

  window.open(source,"window","scrollbars=yes,resizable=yes,width=750,height=" + y + ",screenX=0,screenY=0,left=0,top=0");
}	

function popUp(source)
{
	var x       = screen.width;
	var y       = screen.height;

	if(x > 799)
	{
		x = 750;
		y = screen.height - 80;
	}

	parms = new String("scrollbars=yes,resizable=yes,width=" + x + ",height=" + y + ",screenX=0,screenY=0,left=0,top=0");
	window.open(source,"popup",parms);
}

function centrePagePopUp(pageURL) {
	var w = 790;
	var h = 600;
	var left = (screen.width/2)-(w/2);
	var top = (screen.height/2)-(h/2);
	var targetWin = window.open (pageURL, '', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
}

function openNewWindowURL(url, name,siteType, extras)
{
	var tempURL = new String();
	var x       = screen.width;
	var y       = screen.height;

	if(x > 799)
	{
		x = screen.width - 10;
		y = screen.height - 80;
	
		if (extras=='yes')
		{
			y = y - 85;
		}
	}
	
	if(siteType=='External')
	{
		tempURL = url;
	}
	else
	{
		tempURL = "http://" + location.host + url;
	}
	
	parms = new String("width=" + x + ",height=" + y + ",scrollbars=yes,menubar=visible,statusbar=yes,status=yes,location=" + extras + ",toolbar=" + extras + ",history=" + extras + ",resizable=yes,screenX=0,screenY=0,top=0,left=0");
	HASWin = window.open(tempURL,name,parms);
	return;
}
			
function contactURL(url)
{
	location.href = "http://" + location.host + url;
}

