﻿
// ********************************************************************************************** //
// One4all Site Template
// JavaScript Functions v1.0


// ********************************************************************************************** //
// Boot up jQuery on page load:

jQuery(document).ready(function($)
{
	init_PageContent();
});



// ********************************************************************************************** //
// Determine Functions Relevant to Section to Initialise


// Determine functions to initialise at page load:
function init_PageContent()
{
	
	// Generic cross-site functions: (To disable functionality across the site, simply comment out the relevant line)
	init_MainNav_DropDowns();		// Enable menu dropdowns for IE, and enable animation on other browsers
	init_Card_Tooltip();				// Tooltip for 
	init_DisableDummyAnchors();	// Disable auto scroll-to-top of dummy links (#)
	init_AnimateLocalAnchors();	// Enable smooth scrolling to anchors on current page
	
	// Page specific functions:
	switch (curSection)
	{
		case("sect-faqs"):
			init_FAQ();
			break;
	}
	
}


// ======================================================================================================= //
/* Site-wide Generic Functionality */
// ======================================================================================================= //

function init_MainNav_DropDowns()
{
	$("table.header ul.main-nav").superfish(
	{
		animation	: { height:"show" },
		speed		: "fast",
		delay		: 400
	});
}


function init_Card_Tooltip()
{
	
	$("a#cardinfo-target-1").ezpz_tooltip({
		contentPosition: 'belowRightFollow'
	});
	
}


function init_DisableDummyAnchors()
{
	$("a[href='#']").click(function(e){
		e.preventDefault();
	});
}


function init_AnimateLocalAnchors() {
	// Modified from http://www.zachstronaut.com/posts/2009/01/18/jquery-smooth-scroll-bugs.html
    function filterPath(string) {
        return string
                .replace(/^\//,'')
                .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
                .replace(/\/$/,'');
    }

    var locationPath = filterPath(location.pathname);
    
    var scrollElement = 'html, body';
    $('html, body').each(function () {
        var initScrollTop = $(this).attr('scrollTop');
        $(this).attr('scrollTop', initScrollTop + 1);
        if ($(this).attr('scrollTop') == initScrollTop + 1) {
            scrollElement = this.nodeName.toLowerCase();
            $(this).attr('scrollTop', initScrollTop);
            return false;
        }    
    });
    
    $('a[href*=#]').each(function() {
        var thisPath = filterPath(this.pathname) || locationPath;
        if  (   locationPath == thisPath
                && (location.hostname == this.hostname || !this.hostname)
                && this.hash.replace(/#/, '')
            ) {
                if ($(this.hash).length) {
                    $(this).click(function(event) {
                        var targetOffset = $(this.hash).offset().top;
                        var target = this.hash;
                        event.preventDefault();
                        $(scrollElement).animate(
                            {scrollTop: targetOffset},
                            500,
                            function() {
                                location.hash = target;
                        });
                    });
                }
        }
    });
}


// ======================================================================================================= //
/* Page Specific Functionality */
// ======================================================================================================= //

function init_FAQ()
{
	$('.faq-accordion div.answer').hide();
	
	$('.faq-accordion li a').click(
		function() {
			
			var checkLink = $(this);
			var checkElement = $(this).next();
			
			$('.faq-accordion a').removeClass('selected');
			
			if((checkElement.is('div')) && (checkElement.is(':visible'))) {
				$('.faq-accordion div:visible').slideUp('normal');
				return false;
			}
			
			if((checkElement.is('div')) && (!checkElement.is(':visible'))) {
				$('.faq-accordion div:visible').slideUp('normal');
				checkElement.slideDown('normal');
				checkLink.addClass('selected');
				return false;
			}
			
			return false;
			
		}
		
	);
	
}
