$(document).ready(function() {
	
	$.fn.bindCharacterCounting();
	$.fn.commentForm();
	$.fn.commentPagination();
	
	$.fn.mediaCommentPagination();
	
//	$('.ContactCarousel').contactcarousel({ visible: 4});
	
	$.fn.thisWeeksPoll();
	
	$('div#featured_experts ul#experts_paged_list').featured_experts_pager({ pageSize: 6 });
	
	//pre-populate mailto share link
	var mailtoSubj = $('.media h5').first().text().replace(/^\s*|\s*$/g, "");
	//$('p.share .mailto').attr('href', 'mailto:?subject=FW: '+mailtoSubj+'&body='+location.href);
	
	// Article tools
	$('p.content_stats').prepend('<a href="#" class="content_stats_print" title="Print">Print</a>');
	$('a.content_stats_print').click(function() {
		window.print();
		return false;
	});
	
	if($.cookie('closedTout')){
		$('.carausel_cta_sm').remove();
	}
	
	// alert box close binding
	$('p.close a').click(function(e) {
		e.preventDefault();
		$.cookie('closedTout', 'true');
		$(this).parent().parent().hide();
	});
	
	// External links in new window
	$('a[href^="http://"]').attr("target", "_blank");
	
	// Shorten Share Links
	var twitterUrl = $('p.share a.twitter').attr('href');
	var stumbleUponUrl = $('p.share a.stumbleupon').attr('href');
	var articleTitle = unescape($('p.share a.twitter').attr('rel')).split(':')[0];
	$('p.share a.twitter').attr('href', twitterUrl + articleTitle + ' @OPENForum: ');
	$('p.share a.stumbleupon').attr('href', stumbleUponUrl + location.href);
	$('p.share a.twitter, p.share a.facebook, p.share a.linkedin, p.share a.digg, p.share a.reddit').shortenUrl();
	

	if (window.location.protocol == 'https:') {
		$('a.twitter').remove();
	}
	
	$('div#viewed .ContactCarousel').contactcarousel({ visible: 4, boxPagination: true, pageSize: 4 });
	
	$('.alert .close a').click(function(e) {
		$(this).parent().parent().fadeOut('fast');
		
		return false;
	});
	
	$('a.recommendations').each(function() {
		var $link = $(this);
		$link.oneShotAjax({}, function() {
			$link.html(parseInt($link.html(),10) + 1);
			$link.replaceWith('<span class="recommendations">'+$link.html()+'</span>');
		});
	});
	
	$('#archived_comments .pod_tools a').click(function(e) {
		$('#archived_comments').toggleClass('active');
		
		e.preventDefault();
	});
	
	if ($('.comments_add').length > 0) {
		$('.toutArticle').css({'padding-bottom':'3px', 'display':'none'});
	}
	
	/*
	var article_title = $('.post_title h5').text();
		article_title = article_title.replace(/&/g,'%26');
		article_title = article_title.replace(/ /g,'%20');
		mailto_href = "mailto:?subject="+article_title+'&body='+location.href;
		$('a.mailto').attr('href',mailto_href);
	*/
	
	// Omniture tracking:
	// Idea Hub > Topics > [topic_name] > xxxx
	var topicname = parseTitle('topic');
	var articlename = $("h5").text();
	
	$('#LoggedOutUtility li a').click(function(){
		var btnType = $(this).parent().attr('id'); var action = "";
		switch(btnType){
			case 'UtilityLogin':
				btnType = 'login_left'; action = 'login';
				break;
			case 'UtilityRegister':
				btnType = 'register_left'; action = 'register';
				break;
			case 'UtilityAbout':
				btnType = 'about_left'; action = 'browse';
				break;
			case 'UtilityNoCard':
				btnType = 'apply_left'; action = 'apply_now';
				break;
		}
	});

}); 

