/* 
 * WWW
 * this is where we are putting our custom js on the site
 */

    /* accordian for FAQ page */

    jQuery(document).ready(function() {
									
			jQuery('.sitemap li.page_item').has("ul.children").each(function(index)
            {
				jQuery(this).prepend('<span class="indicator"></span>');
                jQuery(this).addClass('haschild');

            });
			 
            //ACCORDION BUTTON ACTION
            jQuery('div.accordionButton').click(function()
            {
                if (jQuery(this).next().is(":hidden"))
                {
                  jQuery('div.accordionContent').slideUp('normal');
                  jQuery(this).next().slideDown('normal');
                }
                else
                {
                  jQuery(this).next().slideUp('normal');
                }
            });
            //HIDE THE DIVS ON PAGE LOAD
            jQuery("div.accordionContent").hide();

            jQuery('a.showall').click(function()
            {
                jQuery('.accordionContent').each(function(index)
                {
                    jQuery(this).slideDown('normal');
                });
            });

            jQuery('a.hideall').click(function()
            {
                jQuery('.accordionContent').each(function(index)
                {
                    jQuery(this).slideUp('normal');
                });
            });

            // SITE MAP START -------------------------------------------
            //ACCORDION BUTTON ACTION FOR SITEMAP
            jQuery('a.showallsitemap').click(function()
            {
                jQuery('.children').each(function(index)
                {
                    jQuery(this).slideDown('normal');
                    jQuery(this).parent().children('span').addClass('open');
                });
            });

            jQuery('a.hideallsitemap').click(function()
            {
                jQuery('.children').each(function(index)
                {
                    jQuery(this).slideUp('normal');
                    jQuery(this).parent().children('span').removeClass('open');
                });
            });
            
            jQuery('.sitemap li.page_item span').click(function()
            {
				
                if (jQuery(this).siblings('ul').is(":hidden"))
                {
//                    console.log(jQuery(this));
//                  jQuery('.sitemap li.page_item ul.children').slideUp('normal');
                  jQuery(this).siblings('ul').slideDown('normal');
                  jQuery(this).addClass('open');
                }
                else
                {
                  jQuery(this).siblings('ul').slideUp('normal');
                  jQuery(this).removeClass('open');
                }
            });
            
            //HIDE THE DIVS ON PAGE LOAD SITEMAP
            jQuery(".sitemap li.page_item ul.children").hide();


            // SITE MAP END ---------------------------
    });

/* home page tabs */

    jQuery(document).ready(function() {
            jQuery("#tabs #tab-1").addClass('active');
            jQuery("#tabs #tab-2").addClass('hidden');
            jQuery("#tabs #tab-3").addClass('hidden');
            jQuery("#tabs #tab-4").addClass('hidden');

            jQuery("#tabs ul.navigation .nav_1").addClass('selected');

    });

    jQuery(document).ready(function() {
        jQuery("#tabs ul.navigation li").click(function(){
            jQuery("#tabs ul.navigation li").removeClass('selected');
            jQuery("#tabs ul.navigation li").addClass('');
            
            jQuery("#tabs .tab").removeClass('active');
            jQuery("#tabs .tab").addClass('hidden');

            var show = jQuery(this).attr("class");
//            alert(show.substring(4));

//            jQuery("#tabs #tab-1").addClass('active');
//            jQuery("#tabs #tab-2").addClass('hidden');
//            jQuery("#tabs #tab-3").addClass('hidden');
//            jQuery("#tabs #tab-4").addClass('hidden');
//
            jQuery(this).addClass('selected');
            jQuery('#tabs #tab-'+show.substring(4)).removeClass('hidden');
            jQuery('#tabs #tab-'+show.substring(4)).addClass('active');
        });
    });

// This is for slider for home page for testimonials.
jQuery(document).ready(function() {
    jQuery('.slider .wrap .cfct-mod-content').bxSlider();
});

/* custom script from Simon */

(function($){

	$.fn.leftNav = function()
	{
		
		$('.cfct-row-inner').equalHeights('.carrington-sidebar .wrap, .cfct-callout .wrap, .cfct-module-why-choose .wrap, .cfct-jobs-latest-jobs .wrap, .cfct-module-jobs-why-work .wrap, .cfct-just-approved .wrap, .cfct-module-customer-spotlight .wrap, .cfct-module-loop .wrap, .cfct-module-testimonialsloop .wrap, .cfct-module-faqloop .wrap, .cfct-list-teaser .wrap, .cfct-module-text-teaser .wrap, .cfct-lowest-payment-guarantee-teaser .wrap, .cf-post-callout-module .wrap, .cf-post-callout-module .testimonials, .cfct-contact-us .wrap, .cfct-module-related-links-sidebar .cfct-mod-related-links .wrap, .cfct-thanks-contact-us .wrap, .cfct-plain-form .wrap');

			
		$('.sub-menu .dwn_arrow ul').hide();
		$('.sub-menu .selected .sub-menu').show();
		$('.current_menu_parent, .current_page_parent, .current_page_ancestor').children('ul').show();
		$('ul.auto_left-nav .sub-menu .sub-menu').hide();
		$(this).find('.sub-menu li').each(function()
		{
			//console.log($(this).removeClass('dwn_arrow'));
			if ($(this).children('ul').length)
			{
				if ($(this).hasClass('current_menu_parent') || $(this).hasClass('current_menu_item') || $(this).hasClass('current_page_item') || $(this).hasClass('current_page_parent') || $(this).hasClass('current_page_ancestor'))
				{
					$(this).children('a').append('<span class="selected"></span>');
					$(this).children().show();
				}
				else
				{
					$(this).children('a').append('<span class="default"></span>');
				}

			}
		});

		$('ul li a span').click(function()
		{
			if ($(this).hasClass('default'))
			{
				$(this).parent().parent().children('ul').slideDown('normal')
				$(this).addClass('selected');
				$(this).removeClass('default');
				return false;
			}
			else if ($(this).hasClass('selected'))
			{
				$(this).parent().parent().children('ul').slideUp('normal');
				$(this).addClass('default');
				$(this).removeClass('selected');
				return false;
			}
		});

	};

	$(function(){
		$('#main .cfct-module-wallace-subpages_1 , #main .widget_autoLeftNav, #main .widget_nav_menu').leftNav();
	});

})(jQuery);

//jQuery(document).ready(function() {
//            //ACCORDION BUTTON ACTION
//            jQuery('#single-related-products .comment a').click(function()
//            {
//                $('.comment-form').slideDown('normal');
//            });
//        });


