
$(function(){
        var this_current = current_tab;
        var curTabNum = 1;
        var timer;

        timer = setTimeout(strapLoopOut, 7000);


        function strapLoopOut() {
            $('.strapLine').fadeOut(2000, function(){
                    timer = setTimeout(strapLoopIn, 2000);
            });
        }

        function strapLoopIn() {
            $('.strapLine').fadeIn(2000, function(){
                    timer = setTimeout(strapLoopOut, 7000);
            });
        }

         /*********************************************************
         * SHOW HIDE
         *********************************************************/

        function setUpTabShowHide(){
           $('#tab_content > li').append('<div class="showHideBtn less"><a href="#" style="width:16px;"><img src="/skins/tan/images/layout/chevron.png" border="0" /></a></div>');

           $('.showHideDiv > .showHideBtn a').click(function(){
                showTab(curTabNum);
           });

            $('#tab_content .showHideBtn a').click(function(){
                $('#home_banner_wrapper').height(47);
                $('#tab_content').addClass('hide');
                $('.showHideDiv').removeClass('hide');
            });

            $('#tab_content .showHideBtn a').trigger('click');

        }

        function showTab(tab_id){

            $('#home_banner_wrapper').height(319);
            $('#tab_content').removeClass('hide');

            tab_count = 1; // loop counter.

            // first name each of our tab contents.
            $('#tab_content > li').each(function(){
                $(this).attr('rel',tab_count);
                if(tab_count != tab_id){
                        $(this).hide(); // hide all that are not current.
                }else{
                    $(this).show();
                    $(this).parent('ul').height($(this).height());
                }
                tab_count++;
            });

            $('.showHideDiv').addClass('hide');
        }

        function getSectionName(tab_id){
            if(tab_id == '1'){return 'FIND OUT MORE ABOUT <strong>INVESTORS IN PEOPLE</strong>'}
            if(tab_id == '2'){return 'FIND OUT MORE ABOUT <strong>HEALTH & WELL-BEING</strong>'}
            if(tab_id == '3'){return 'FIND OUT MORE ABOUT <strong>LEXCEL</strong>'}
            if(tab_id == '4'){return 'FIND OUT MORE ABOUT <strong>GENERAL QUALITY MARK</strong>'}
            if(tab_id == '5'){return 'FIND OUT MORE ABOUT <strong>EQUALITY & DIVERSITY</strong>'}
        }


	/**
	  * Javascript Tab Code 
	  * Copyright David Baker (dtbaker@gmail.com)
	  * Created for ThemeForest theme Nov 2009
	  */

	var tab_count = 1; // loop counter.
	
	// first name each of our tab contents.
	$('#tab_content > li').each(function(){
            $(this).attr('rel',tab_count);
            if(tab_count != current_tab){
                    $(this).hide(); // hide all that are not current.
            }else{
                $(this).show();
                //resize this li parent ul container so it fits
                $(this).parent('ul').height($(this).height());
                curTabNum = current_tab;

            }
            tab_count++;
	});

        if(show_hide_tabs == '1'){
            setUpTabShowHide();
        }

	tab_count = 1;
	// bind the clicks.
	function tab_gogo(this_tab_id){
		// find an existing tab, fade it out.
		var tab = $('#home_tabs > li a[rel='+this_tab_id+']');
		if(current_tab){
			if($.browser.msie)$('#tab_content > li[rel=' + current_tab + ']').hide();
			else $('#tab_content > li[rel=' + current_tab + ']').fadeOut();
		}
		// find the tab to display... fade it in.
		if($.browser.msie){
			$('#tab_content > li[rel=' + this_tab_id + ']').show();
                        //resize this li parent ul container so it fits
                        $('#tab_content > li[rel=' + this_tab_id + ']').parent('ul').height($('#tab_content > li[rel=' + this_tab_id + ']').height());
		}else{ 
			$('#tab_content > li[rel=' + this_tab_id + ']').fadeIn();
                        //resize this li parent ul container so it fits
			$('#tab_content > li[rel=' + this_tab_id + ']').parent('ul').height($('#tab_content > li[rel=' + this_tab_id + ']').height());
		}
		// remove any old current list items.
		$('#home_tabs li.current').removeClass('current');
		// change the state of the holding li item to current for styling.
		$(tab).parent('li').addClass('current');
		current_tab = this_tab_id;
                curTabNum = this_tab_id;
                $(".showHideText").html(getSectionName(curTabNum));
	}


        
	if(page_type != 'internal'){
            $('#home_tabs li a').each(function(){
                    // each of the a links, find it's count and set a callback on the a link.
                    $(this).attr('rel',tab_count);
                    // just for first time loading.
                    if(tab_count == current_tab)$(this).parent('li').addClass('current');
                    $(this).click(function(){
                            var this_tab_id = $(this).attr('rel');
                            tab_auto = 0;
                            tab_gogo(this_tab_id);
                            showTab(this_tab_id);
                            return false;
                    });
                    tab_count++;
            });
       }else{
            $('#home_tabs li a').each(function(){
                    // each of the a links, find it's count and set a callback on the a link.
                    $(this).attr('rel',tab_count);
                    // just for first time loading.
                    if(tab_count == current_tab)$(this).parent('li').addClass('current');
                    $(this).click(function(){
                            var this_tab_id = $(this).attr('rel');
                            tab_auto = 0;
                            //tab_gogo(this_tab_id);
                            return true;
                    });
                    tab_count++;
            });
       }

        if(tab_auto){
            function tab_auto_gogo(){
                    if(!tab_auto)return;
                    // how many tabs are there.
                    this_current = current_tab;
                    if(this_current >= $('#home_tabs li a').size())this_current = 1;
                    else this_current++;
                    tab_gogo(this_current); //$('#home_tabs li a[rel='+this_current+']').click();
                    setTimeout(tab_auto_gogo,tab_auto*1000);
            }
            setTimeout(tab_auto_gogo,tab_auto*1000);
	}
       
});
