jQuery.noConflict();

cfct = {}

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

cfct.ajax_post_content = function() {
	jQuery('ol.archive .excerpt .entry-title a').unbind().click(function() {
		var post_id = jQuery(this).attr('rev').replace('post-', '');
		var excerpt = jQuery('#post-excerpt-' + post_id);
		var target = jQuery('#post-content-' + post_id + '-target');
		excerpt.hide();
		target.html(cfct.loading()).show().load(CFCT_URL + '/index.php?cfct_action=post_content&id=' + post_id, function() {
			cfct.ajax_post_comments();
			jQuery('#post_close_' + post_id + ' a').click(function() {
				target.slideUp(function() {
					excerpt.show();
				});
				return false;
			});
			jQuery(this).hide().slideDown();
		});
		return false;
	});
}

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;
	});
}

// Moves form for threaded comments: taken and modified from WordPress 2.7
addComment = {
	moveForm : function(commId, parentId, respondId, postId) {
		var t = this, div, comm = t.I(commId), respond = t.I(respondId), cancel = t.I('cancel-comment-reply-link-p' + postId), parent = t.I('comment_parent_p' + postId), post = t.I('comment_post_ID_p' + postId);

		if ( ! comm || ! respond || ! cancel || ! parent )
			return;

		t.respondId = respondId;
		postId = postId || false;

		if ( ! t.I('wp-temp-form-div-p' + postId) ) {
			div = document.createElement('div');
			div.id = 'wp-temp-form-div-p' + postId;
			div.style.display = 'none';
			respond.parentNode.insertBefore(div, respond);
		}

		comm.parentNode.insertBefore(respond, comm.nextSibling);
		if ( post && postId )
			post.value = postId;
		parent.value = parentId;
		cancel.style.display = '';

		cancel.onclick = function() {
			var t = addComment, temp = t.I('wp-temp-form-div-p' + postId), respond = t.I(t.respondId);

			if ( ! temp || ! respond )
				return;

			t.I('comment_parent_p' + postId).value = '0';
			temp.parentNode.insertBefore(respond, temp);
			temp.parentNode.removeChild(temp);
			this.style.display = 'none';
			this.onclick = null;
			return false;
		}

		try { t.I('comment-p' + postId).focus(); }
		catch(e) {}

		return false;
	},

	I : function(e) {
		return document.getElementById(e);
	}
}

jQuery(function($) {
	// :first-child fix for IE on nav
	$('.nav li:first-child').addClass('first-child');
	// :first-child fix for IE
	$('.comment .comment-content p:last-child').addClass('last-child');
	// :hover fix for full articles in IE
	$('.full').mouseover(function() {
		$(this).addClass('hover');
	});
	$('.full').mouseout(function() {
		$(this).removeClass('hover');
	});

	// Suckerfish dropdowns IE :hover fix
	$('.nav li').mouseover(function() {
		$(this).addClass('hover');
	});
	$('.nav li').mouseout(function() {
		$(this).removeClass('hover');
	});
	
	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();
	}
	$('.nav li a').removeAttr('title');
	
});


//HOME PAGE SLIDESHOW

ss_params = {
	current : '',
	next : '',
	caption : '',
	title : '',
	description : ''
	
}

function slideshow(elid) {
	el = "#" + elid; 
	jQuery(el).append('<div class="caption"></div>');
	ss_params.caption = jQuery(el + " div.caption");
	
	//jQuery(el + ' a').fadeTo(10, 0);	
	jQuery(el + ' a img').fadeTo(10, 0);
	ss_changeslide(el);
	setInterval('ss_changeslide("'+ el +'")',4000);
}

function ss_changeslide(el) {
	ss_params.current = (jQuery(el + ' a.show')?  jQuery(el + ' a.show') : jQuery(el + ' a:first'));
	ss_params.next = ((ss_params.current.next().length) ? ((ss_params.current.next().hasClass('caption'))? jQuery(el + ' a:first') :ss_params.current.next()) : jQuery(el + ' a:first'));	
	if(ss_params.next == jQuery(el + ' .caption')){ ss_params.next = jQuery(el + ' a:first')};
	
	
	ss_params.title= ss_params.next.find('img').attr('title');
	ss_params.description = ss_params.next.find('img').attr('alt');
	
	ss_params.current.removeClass('show');
	//ss_params.current.fadeTo(2000, 0);
	ss_params.current.find('img').fadeTo(2000, 0);
	ss_params.caption.fadeTo(500, 0, ss_fadein);
}

function ss_fadein(){
	ss_params.caption.html('<h1>'+ ss_params.title + '</h1><p class="description">'+ ss_params.description +'</p>');
	ss_params.next.find('img').fadeTo(2000, 1);
	//ss_params.next.fadeTo(2000, 1).addClass('show');
	ss_params.next.addClass('show');
	ss_params.caption.fadeTo(1000, 1);
}

