$(document).ready(function() {
	// Checkbox replace
	$(':checkbox').checkboxRadioInput({
		elementClass: 'checkboxReplace',
			checkedClass: 'checkboxReplace_checked'
	});
	
	$('.all_topics li').click(function() {
			window.location.href = $(this).find('a').attr('href');
	});
	
	if ($.browser.msie && ($.browser.version < 7)) { 
		$('.all_topics li').hover( function () {
				$(this).addClass("hover");
			}, function () {
				$(this).removeClass("hover");
			});
	};
    
	$('a.unsubscribe').each(function() {
		var $link = $(this);
		var topic = this.getAttribute('data-topic');
		$link.oneShotAjax({}, function() {
			$link.parent().parent().parent().fadeOut('fast', function() {
				$(this).remove();
				$('body').sysmessage('You have been unsubscribed from ' + topic, {type: 'confirmation'});
			});
		});
	});
	
	$('li.videomedia p.topic_content_thumb').each(function() {
	    $(this).find('a img').after('<img src="/images/idea_hub/bkg.thumb-overlay-small.png" alt="play video" class="overlay" >');
	    $.ifixpng('/images/pixel.gif');
	    $('img[src$=.png]').ifixpng();    
	});
	
	$('a.unsubscribe').confirmation({ triggerClick: true });
	
	// Topic Experts switching
	$('ul.topic_experts_list').each(function() { 
		$(this).children('li').hide();
		$(this).children('li:first').addClass('active').show(); 
	});
	$('p.expert_arrow_left a').click(function() { 
		var expertList = $(this).parent().siblings('ul.topic_experts_list:first');
		var prevExpert = $(expertList).children('li.active').prev();
		
		$(expertList).children('li').removeClass('active').hide();
		if(prevExpert.length == 1) {
			$(prevExpert).addClass('active').show();
		} else {
			$(expertList).children('li:last').addClass('active').show();
		}
		
		return false;
	});
	$('p.expert_arrow_right a').click(function() { 
		var expertList = $(this).parent().siblings('ul.topic_experts_list:first');
		var nextExpert = $(expertList).children('li.active').next();
		
		$(expertList).children('li').removeClass('active').hide();
		if(nextExpert.length == 1) {
			$(nextExpert).addClass('active').show();
		} else {
			$(expertList).children('li:first').addClass('active').show();
		}
		
		return false;
	});
	
	// Hide arrows for topic experts with less than 2 experts
	$('div.topic_experts').each(function() {
		var experts = $('ul.topic_experts_list li', $(this)).size();
		if(experts > 1) {
			$('p.expert_arrow, p.expert_arrow a', $(this)).show();
		} 
		if(experts == 0) {
			$(this).hide();
		}
	});
	
	// CPB_FIX: FRONT-END TRUNCATION - NEEDS TO BE REMOVED WHEN BACKEND TRUNCATION IN PLACE
	if ($.browser.msie == true && $.browser.version == "6.0") {
	$('.topic_expert_blurb').each(function() {
			if($(this).html().length > 100) {
				var topicBlurb = $(this).html().slice(0,100);
				$(this).html(topicBlurb + '&hellip;');
			}
		});
	}
	else {
		$('.topic_expert_blurb').each(function() {
		if($(this).html().length > 125) {
			var topicBlurb = $(this).html().slice(0,125);
			$(this).html(topicBlurb + '&hellip;');
		}
	});
	}
	
	
	// Omniture tracking:
	//  left menu logged out
	$('#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;
		}
	});
	
	//utility nav clicks - logged in
	$('#Utility li a').click(function(){
		var btnType = $(this).parent().attr('id');
		switch(btnType){
			case 'UtilityNavProfile':
				btnType = 'profile_left';
				break;
			case 'UtilityNavSettings':
				btnType = 'settings_left';
				break;
			case 'UtilityNavContacts':
				btnType = 'contacts_left';
				break;
			case 'UtilityNavMessages':
				btnType = 'help_left';
				break;
		}
		return true;
	});
	
});

