var next;
documentReady("frontBannersHover");
function frontBannersHover(){
	//alert("frontBannersHover() called ONCE, only on load");
	
    $(".frontBanners a").hoverIntent(function(){
            var className = $(this).parent('li').attr('class');
          
            if(next)									
           	    //clearTimeout(next); //hover should have no effect on carousel
          
            //fadeout old banner and remove old active class
           // $(".frontBanner > div:visible:not(."+className+")").fadeOut(); // add 13/12/2011
            $(".frontBanners a.active").removeClass("active");

            // Thomas
            $(".section").removeClass("active");


            //fadeIn New Banner and add new active class
            $(".frontBanners ."+className+" a").addClass("active");
            //$(".frontBanner > div."+className).fadeIn(); // add 13/12/2011
			
            // Thomas
            $(".section."+className).addClass("active");

        },function(){
            //if(homepageCookieValue == '') 
              //  next = window.setTimeout(function() { nextActive(); }, 10000);
        }
    );

    //Thomas
    $(".section").hoverIntent(function(){
            var all_className = $(this).attr('class');
            var split_className = all_className.split(" ");
            var className = split_className[1];
            //alert(split_className[1]);
          
            if(next)						
                //clearTimeout(next); //hover should have no effect on carousel
          
            //fadeout old banner and remove old active class
            //$(".frontBanner > div:visible:not(."+className+")").fadeOut(); // add 13/12/2011
            $(".frontBanners a.active").removeClass("active");
            // Thomas
            $(".section").removeClass("active");
            $(".section."+className).addClass("active");

          
            //fadeIn New Banner and add new active class
            $(".frontBanners ."+className+" a").addClass("active");
            //$(".frontBanner > div."+className).fadeIn(); // add 13/12/2011
          
          
        },function(){
           // if(homepageCookieValue == '')
                //next = window.setTimeout(function() { nextActive(); }, 10000);
        }
      
    );  
	
}

documentReady("carousel");
function carousel(){
	//window.alert("carousel() function");
	homepageCookieValue = '';
	if(homepageCookieValue == undefined || homepageCookieValue == '')
    {  
      
        $(".frontBanner div:first-child").removeClass("active");
        var firstChildDivUnderBanner=$(".frontBanner div:first-child").attr('class');
       
        //If the first section is business
        if("business"==firstChildDivUnderBanner){
            $(".frontBanners a.active").removeClass("active");
            //$(".frontBanners ."+firstChildDivUnderBanner+" a").addClass("active");
            $(".section."+firstChildDivUnderBanner).addClass("active");           
            $(".frontBanners ."+firstChildDivUnderBanner+" a").addClass("active");
        }else {
        	$(".frontBanners a.active").removeClass("active");
	 	}

        $(".frontBanner > div."+firstChildDivUnderBanner).show();
        $(".frontBanner > div."+firstChildDivUnderBanner).addClass("active");
        //$(".frontBanners a.active").removeClass("active");
       
        next = window.setTimeout(function() { nextActive(); }, 7500);
    }
	/*else
    {
        // Highlight section
        highlightSection();
    }
	*/
}

// We come here if the cookie has been set
function highlightSection()
{
	//window.alert("highlightSection() function");
	homepageCookieValue = '';
    if(homepageCookieValue == 'BUSINESS')
    {
        $(".frontBanners a.active").removeClass("active");
        $(".frontBanners .business a").addClass("active");
      
        // Thomas
        $(".section").removeClass("active");
        $(".section.business").addClass("active");


       // $(".frontBanner > div:visible:not(.accountants)").hide();// add 13/12/2011
       // $(".frontBanner > div:visible:not(.enterprise)").hide();// add 13/12/2011
      
        $(".frontBanners .business a").addClass("active");
        //$(".frontBanner > div.business").show();// add 13/12/2011
      
    }else if(homepageCookieValue == 'ENTERPRISE')
    {
        $(".frontBanners a.active").removeClass("active");
        $(".frontBanners .enterprise a").addClass("active");
      
        // Thomas
        $(".section").removeClass("active");
        $(".section.enterprise").addClass("active");


       // $(".frontBanner > div:visible:not(.business)").hide();// add 13/12/2011
       // $(".frontBanner > div:visible:not(.accountants)").hide();// add 13/12/2011
      
        $(".frontBanners .enterprise a").addClass("active");
        //$(".frontBanner > div.enterprise").show();// add 13/12/2011
      
    }else if(homepageCookieValue == 'ACCOUNTING')
    {
        $(".frontBanners a.active").removeClass("active");
        $(".frontBanners .accountants a").addClass("active");
      
        // Thomas
        $(".section").removeClass("active");
        $(".section.accountants").addClass("active");

        //$(".frontBanner > div:visible:not(.business)").hide();// add 13/12/2011
        //$(".frontBanner > div:visible:not(.enterprise)").hide();// add 13/12/2011
      
        $(".frontBanners .accountants a").addClass("active");
        //$(".frontBanner > div.accountants").show();// add 13/12/2011
      
    }else
    {  
        //next = window.setTimeout(function() { nextActive(); }, 5000);
    }
}

function nextActive(){
	
    var prevActiveClassName;
    var newActiveClassName;
  
    var lastSlide = $(".frontBanner div:last-child").attr('class');
    var firstSlide=$(".frontBanner div:first-child").attr('class');
    
    
    //if the active class is the last slide, set active to business
   /* no concept of last slide */
   
    if($(".frontBanner div.active").attr('class')==lastSlide){
		//window.alert("nextActive() function: set active to business");
        //$(".frontBanners a.active").removeClass("active");
        //$(".frontBanners ."+firstSlide+" a").addClass("active");
       
        prevActiveClassName = lastSlide;
        newActiveClassName = firstSlide;
       
   }else {
	   
	  
       //window.alert("nextActive() function: else");
        prevActiveClassName = $(".frontBanner div.active").attr('class');
        newActiveClassName =  $(".frontBanner div.active").next().attr('class');
       
		var prevClass=prevActiveClassName.replace(' active','');        
        
        $("li."+prevClass+" a").removeClass("active");
        $("li."+newActiveClassName+" a").addClass("active");
    }
   
    prevActiveClassName=prevActiveClassName.replace(' active','');
   
    $(".frontBanner div.active").removeClass("active");
    
	
	$(".frontBanner > div."+newActiveClassName).addClass("active").fadeIn(function(){
        $(".frontBanner > div."+prevActiveClassName).hide();
    });
    
    $(".section."+prevActiveClassName).removeClass("active");
    $(".section."+newActiveClassName).addClass("active");


    next = window.setTimeout(function() { nextActive(); }, 7500);
};

documentReady("footerLinks");
function footerLinks(){
    $(".footerLinks").hide();
    $(".footerLinksReadMore").toggle(
        function(){
            $(".footerLinks").slideDown()
        }, function(){
            $(".footerLinks").slideUp();
        });
}
