jQuery.noConflict();

sprout = {};
cfct = {};

jQuery(document).ready(function($){
	sprout.ready($);
});
// After page is complete
jQuery(window).load(function() {
	jQuery('body').addClass("loaded");
});

// Ready function
sprout.ready = function($) {
// SlideShow
jQuery('.slideshow').cycle({
	fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
});

// CFCT jQuery Functions for AJAX
	if ((!$.browser.msie || $.browser.version.substr(0,1) != '6') && typeof CFCT_AJAX_LOAD != 'undefined' && CFCT_AJAX_LOAD) {
		//cfct.ajax_post_content();
		cfct.ajax_post_comments();
	}

// Add Classes
	// Add class for browsers not supporting the pseudo :last class
	jQuery("ul > li:last-child").addClass("last");
	jQuery("ul > li:first-child").addClass("first");
	jQuery("ol > li:last-child").addClass("last");
	jQuery("ol > li:first-child").addClass("first");
	
	//Add Class for comments with threads
	jQuery("ol.comments-list > li").addClass("top-level");
	jQuery("ol.comments-list > li ul.children").parents('ol.comments-list > li').addClass("threaded-comment");
	
// Trackback expansion
	jQuery('.trackback-title a').click(function(event){
		event.preventDefault();
		jQuery(this).toggleClass("active");
		jQuery('#trackbacks-wrap').toggle('fast');
		
	 });
	
};


// CFCT jQuery Functions for AJAX
cfct.loading = function() {
	return '<div class="loading"><span>Loading...</span></div>';
};

// AJAX Comments
cfct.ajax_post_comments = function() {
	jQuery('p.comments-link a').unbind().click(function() {
		var a = jQuery(this);
		var post_id = a.attr('rev').replace('post-', '');
		var target = jQuery('#post-comments-' + post_id + '-target');
		target.html(cfct.loading()).show().load(CFCT_URL + '/index.php?cfct_action=post_comments&id=' + post_id, function() {
			jQuery(this).hide().slideDown(function() {
				a.attr('rel', a.html()).html('Hide Comments').unbind().click(function() {
					target.slideUp(function() {
						a.html(a.attr('rel'));
						cfct.ajax_post_comments();
					});
					return false;
				});
			});
		});
		return false;
	});
};
