$(function() {
 	 

    //HOMEPAGE BUCKET PAGERS
    $('#box-people .previewcontainer').cycle({
        fx: 'scrollHorz',
        scrollExpr: 'div',
        timeout: 0,
        pager: '#box1-pager',
        pagerAnchorBuilder: function(idx) {
            return '<li><a href="#">'+ (idx + 1) + '</li>';
        }
    });
    $('#box-project .previewcontainer').cycle({
        fx: 'scrollHorz',
        scrollExpr: 'div',
        timeout: 0,
        pager: '#box2-pager',
        pagerAnchorBuilder: function(idx) {
            return '<li><a href="#">'+ (idx + 1) + '</li>';
        }
    });
    $('#box-partners .previewcontainer').cycle({
        fx: 'scrollHorz',
        scrollExpr: 'div',
        timeout: 0,
        pager: '#box3-pager',
        pagerAnchorBuilder: function(idx) {
            return '<li><a href="#">'+ (idx + 1) + '</li>';
        }
    });
    $('#box-sponsors .previewcontainer').cycle({
        fx: 'scrollHorz',
        scrollExpr: 'div',
        timeout: 0,
        pager: '#box4-pager',
        pagerAnchorBuilder: function(idx) {
            return '<li><a href="#">'+ (idx + 1) + '</li>';
        }
    });
    
    
    $('ul#accordion li ul').hide();
		$('ul#accordion li ul.show-accordion').show();
		$('ul#accordion li.parent-2 > a').click(function(){
			$('ul#accordion li ul').slideUp();
			$(this).next().slideDown();
			return false;
		});
		$('ul#accordion > li.cat-item > a').click(function(){
			$('ul#accordion li ul').slideUp();
			$(this).next().slideDown();
			return false;
		});
    

    $('#giveForm, #adoptForm, #sponsorForm').validate();
    
    
    //HOMEPAGE SLIDER
   /* $('.slide-images').cycle({
        fx: 'fade',
        timeout: 8000,
        speed: 100,
        next: '.banner-pager .next',
        prev: '.banner-pager .prev',
        after: function(curr, next, opts, flag) {
            var src = $('.slide-images img:eq('+ opts.nextSlide +')').attr('src')
            var txt = $('.slide-content ul li:eq('+ opts.nextSlide +') h6 em').html();
            $('.slide-content li').fadeOut('fast');
            $('.slide-content li:eq('+ opts.currSlide +')').fadeIn('fast');
           
            if (src.indexOf('blank.gif') < 0) {
                $('.banner-pager span').html('<img src="'+ src +'" height="50" width="50" />'+ txt);
            } else {
                $('.banner-pager span').html('<img src="'+ src +'" height="48" width="48" style="border:1px solid #ccc" />'+ txt);
            }
        }
    }); */
    $('#slideshow').cycle({
        fx: 'fade',
        timeout: 8000,
        speed: 600,
        next: '.banner-pager .next',
        prev: '.banner-pager .prev',
        pager: '.banner-pager',
        
        pagerAnchorBuilder: function(idx, slide) { 
        var txt = $('.slide-desc:eq('+ idx +') h6 em').html();
        var img = $('#slideshow img:eq('+ idx +')').attr('src');
        return '<li><a href="#"><img src="' + img + '" width="50" height="40" /><span>'+txt+'</span></a></li>'; 
    } 
        
    
        
    /*    after: function(curr, next, opts, flag) {
            var src = $('.slide-images img:eq('+ opts.nextSlide +')').attr('src')
            var txt = $('.slide-desc:eq('+ opts.nextSlide +') h6 em').html();
          //  $('.slide-content li').fadeOut('fast');
         //   $('.slide-content li:eq('+ opts.currSlide +')').fadeIn('fast');
           
            if (src.indexOf('blank.gif') < 0) {
                $('.banner-pager').html('<img src="'+ src +'" height="50" width="50" />'+ txt);
            } else {
                $('.banner-pager').html('<img src="'+ src +'" height="48" width="48" style="border:1px solid #ccc" />'+ txt);
            }
        } */
    });
    
   
    //RESIZE HOMEPAGE BUCKETS
    var height = 0;
    
    $('.previewcontainer').each(function() {
        var thisheight = $(this).height();
        
        if (thisheight > height) {
            $('.previewcontainer').height(thisheight + 25);
            height = thisheight;
        }
    });
    
    //MAKE FOOTER COLS SAME SIZE
    if ($('.footerLeft').height() < $('.footerRight').height()) { $('.footerLeft').height($('.footerRight').height()); }
    else { $('.footerRight').height($('.footerLeft').height())}
    
    //SETUP SHADOWBOX
    Shadowbox.init();
    
    $('.slide-content ul.banner-pager').jcarousel({
        vertical: true,
        scroll: 2
    });
    
    $('.banner-ad').cycle({
        fx: 'fade',
        timeout: 10000,
        speed: 600 });
});

function serverTime() {
    var time = null; 
    $.ajax({
        url: 'server-time.php', 
        async: false,
        dataType: 'text', 
        success: function(text) { time = new Date(text); },
        error: function(http, message, exc) { time = new Date(); }
    }); 
    return time;
}

		

