// JavaScript Document
$(document).ready(function(){
	$('#footer').corner("bottom");
	
	// Get a jquery object tag name
	$.fn.tagName = function(){
		return this.get(0).tagName.toLowerCase();
	}

	// Pending documentation
	$('.pendingpage').after(' (pending)').click(function(e){
		e.preventDefault();
		
		// Get the section and the page title
		var $sectionTitleElement =  $(this).closest('ul').prev();
		var sectionTitleTagName = $sectionTitleElement.tagName();
		var sectionTitle = (sectionTitleTagName == 'h2' || sectionTitleTagName == 'h3')?$sectionTitleElement.text() + ": ":"";
		var pageTitle = $(this).text();
		
		// Display popup message
		$.prompt("The page '" + sectionTitle + pageTitle + "' will be written soon. Please check back later. Thank you.", {top: '35%'});
	});
	
	// Tooltips
	$('#homefeatures span').tooltip({
		track: true,
		delay: 0,
		fade: 250 
	})
	
	// Load disqus comments
	$('#disqus_thread').each(function(){
		$(this).before('<div id="loadingDisqus">Retrieving comments from Disqus...</div>').end().disqus({
			domain: 'cftrigger',
			title: heading,
			message: 'cfTrigger',
			url: currentPage,
			developer: 1,
			success: function(){
				$('#loadingDisqus').text("Loading comments...");
				
				// Periodically checking for discus comments fully loaded
				checkDisqusLoaded = window.setInterval(function(){
					if ($('#dsq-new-post').length > 0)
					{
						$('#loadingDisqus').fadeOut();
						window.clearInterval(checkDisqusLoaded);
						$('#dsq-new-post').corner();
						
						// Hide the options when there is no comment
						if ($('#dsq-comments-title > h3:contains(" 0 ")').length > 0)
						{
							$('.dsq-options').hide();
						}
					}
				}, 500);
			}
		})
	})
})
