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;	
			}
		}); 
               
    //'named anchor opener'
    //If the URL has a named anchor in it (ie. xyz.html#take me to a bookmark), then open that bookmark for the user onload:
    var namedAnchorFromURL = new String(location.hash);                                               
    if(namedAnchorFromURL.length > 1) {   
      var namedAnchorFromURLwithoutLeadingPoundSign = namedAnchorFromURL.substr(1,namedAnchorFromURL.length);    
      var namedAnchorArr  = document.getElementsByName(namedAnchorFromURLwithoutLeadingPoundSign);
      var namedAnchor     = namedAnchorArr[0]; //Of course named anchors should be unique so just take the first one found         
      if(namedAnchor) {  
  		  $(namedAnchor).parent().addClass('active');
  			$(namedAnchor).parent().next('dd').toggle(100);      				
        $.scrollTo($(namedAnchor), 800, {offset: -50} ); 
      }         
    } 
   	return false;	  
    //End of named anchor opener  

	},

	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;
}

function hideEm(targetIN) {
  var x = document.getElementsByTagName(targetIN);
  for(var i=0;i<x.length;i++) {
    x[i].style.display = "none";
  }
  return false;
}



function isAnchorToTandC4Payment()
{
    var docURL = document.URL;
    var s = docURL;
    var occur = s.match("what_will_you_have_to_pay_us_for_providing_our_services_to_you");
    if (occur)
    {
      return true;
    }              
    return false;
}

/**
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne <brian@cherne.net>
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);



$(function() {
	var zIndexNumber = 1000;
	$('div').each(function() {
		$(this).css('zIndex', zIndexNumber);
		zIndexNumber -= 10;
	});
});

//Links in new window acssesible

// ARRAY EXTENSIONS

if (!Array.prototype.push) Array.prototype.push = function() {
    for (var i=0; i<arguments.length; i++) this[this.length] = arguments[i];
    return this.length;
}

Array.prototype.find = function(value, start) {
    start = start || 0;
    for (var i=start; i<this.length; i++)
        if (this[i]==value)
            return i;
    return -1;
}

Array.prototype.has = function(value) {
    return this.find(value)!==-1;
}

// FUNCTIONAL

function map(list, func) {
    var result = [];
    func = func || function(v) {return v};
    for (var i=0; i < list.length; i++) result.push(func(list[i], i, list));
    return result;
}

function filter(list, func) {
    var result = [];
    func = func || function(v) {return v};
    map(list, function(v) { if (func(v)) result.push(v) } );
    return result;
}


// DOM

function getElem(elem) {
    if (document.getElementById) {
        if (typeof elem == "string") {
            elem = document.getElementById(elem);
            if (elem===null) throw 'cannot get element: element does not exist';
        } else if (typeof elem != "object") {
            throw 'cannot get element: invalid datatype';
        }
    } else throw 'cannot get element: unsupported DOM';
    return elem;
}

function hasClass(elem, className) {
    return getElem(elem).className.split(' ').has(className);
}

function getElementsByClass(className, tagName, parentNode) {
    parentNode = !isUndefined(parentNode)? getElem(parentNode) : document;
    if (isUndefined(tagName)) tagName = '*';
    return filter(parentNode.getElementsByTagName(tagName),
        function(elem) { return hasClass(elem, className) });
}


// DOM EVENTS

function listen(event, elem, func) {
    elem = getElem(elem);
    if (elem.addEventListener)  // W3C DOM
        elem.addEventListener(event,func,false);
    else if (elem.attachEvent)  // IE DOM
        elem.attachEvent('on'+event, function(){ func(new W3CDOM_Event(elem)) } );
        // for IE we use a wrapper function that passes in a simplified faux Event object.
    else throw 'cannot add event listener';
}

function mlisten(event, elem_list, func) {
    map(elem_list, function(elem) { listen(event, elem, func) } );
}

function W3CDOM_Event(currentTarget) {
    this.currentTarget  = currentTarget;
    this.preventDefault = function() { window.event.returnValue = false }
    return this;
}


// MISC CLEANING-AFTER-MICROSOFT STUFF

function isUndefined(v) {
    var undef;
    return v===undef;
}


// the functions in this file require the supplementary library lib.js

// These defaults should be changed the way it best fits your site
var _POPUP_FEATURES = '';

function raw_popup(url, target, features) {
    // pops up a window containing url optionally named target, optionally having features
    if (isUndefined(features)) features = _POPUP_FEATURES;
    if (isUndefined(target  )) target   = '_blank';
    var theWindow = window.open(url, target, features);
    theWindow.focus();
    return theWindow;
}

function link_popup(src, features) {
    // to be used in an html event handler as in: <a href="..." onclick="link_popup(this,...)" ...
    // pops up a window grabbing the url from the event source's href
    return raw_popup(src.getAttribute('href'), src.getAttribute('target') || '_blank', features);
}

function event_popup(e) {
    // to be passed as an event listener
    // pops up a window grabbing the url from the event source's href
    link_popup(e.currentTarget);
    e.preventDefault();
}

function event_popup_features(features) {
    // generates an event listener similar to event_popup, but allowing window features
    return function(e) { link_popup(e.currentTarget, features); e.preventDefault() }
}

