$(document).ready(function(){
    
    $('.snippet').click(function(){
       // $(this).siblings('.testimonial-body').slideToggle();
    })
    
    $('.testimonial-body').click(function(){
        //$(this).slideToggle();
    })
    
    var timerAmount = 3000;
    var transitionSpeed = 'slow';
    
    var sliderWidth = $('#featuredCauses .causeSlide').outerWidth(true);
    var sliderAmount = $('#featuredCauses .causeSlide').length;
    var completeWidth = sliderWidth*sliderAmount;
    var lastReference = completeWidth-sliderWidth;
    var animatorTracker = 1;
    
    $('#causesSlideContainer').css('width',completeWidth);
    $('#causesSlideContainer').scrollLeft(0);
    
    function animateCauses() {
        
        //recheck current position
        currentScroll = $('#featuredCauses').scrollLeft();
        
        //move to original position
        if (currentScroll == lastReference) {
            currentScroll = -sliderWidth;
        }
        
        $('#featuredCauses').animate({
            'scrollLeft':currentScroll+sliderWidth
        }, transitionSpeed, function(){
            if (animatorTracker == sliderAmount-1) {
                animatorTracker = 0;
            } else {
                animatorTracker++;
            }
            //this calls itself recursively
            setTimeout(animateCauses, timerAmount);
        })
    }
    
    setTimeout(animateCauses, timerAmount);
    
    
    $('#slide_container').click(function(){
        window.location = '/testimonials.php';
    })
    
    
    if ($('#overlay_necessary').length > 25) {
        
        if ($('#overlay').length == 0) {
        
            $('body').prepend('<div><div id = "overlay" name = "overlay"></div><div id = "popUp"><div id = "popUpInner"><div id = "popUpContentArea"><p style = "font-size: 18px;"><strong>NEWSFLASH</strong></p><p>Government lose appeal over unlawful feed in tariff cuts.</p><p style = "font-size: 14px;"><strong>Beat the deadline</strong></p><p>43.3p FIT rate reinstated</p><p>Limited number of installations available. To beat the 3rd March deadline ring now to book free survey.</p><p style = "font-size: 14px;"><strong>0800 022 4083</strong></p><p style = "text-align: right; margin: 0 0 5px 0;"><img style = "cursor: pointer;" id = "kill_overlay" src = "/images/closelabel.gif" /></p></div></div></div>');

            var docHeight = $(document).height();
            var docWidth = $(document).width();
            var addTop = $(document).scrollTop() + 55;
            var docWidth = $(window).width();
            var centralPosition = docWidth/2;
            
            $('#kill_overlay').bind('click',function(){
                $('#overlay').hide();
                $('#popUpInner').hide();
            })

            $('#overlay').css('height',docHeight+'px');
            $('#overlay').css('width',docWidth+'px');
            $('#overlay').css('display','block');
            $('#overlay').css('opacity','0.5');

            $('#popUp').css('margin-top',addTop);

            $('#overlay').hide();
            $('#popUp').hide();
        
        }

    } 
    
    append_value = 1;
    
    
    $('#add_another_friend').click(function(){

        $.get('/recommend_template.php?number='+append_value, function(data){
            $('.recommend_right').append(data);
            append_value++;
        })
        
    })
    
    
    
    
    
    
    
    

})
