$(document).ready(function() {
 
 	//belt actions
	$(".scrollingbelt").jCarouselLite({
		btnPrev: ".beltnavleft",
		btnNext: ".beltnavright",
		visible: 4,
		circular: false,
		scroll: 1
	});
	
	//hacks to keep belt in place
	$(".beltnavleft").addClass("disabled");

	$(".scrollingbelt").css("width","670px");
	$(".scrollingbelt").css("height","140px");
	$("li.beltitem").css("height","140px");
	
	$(".invisiblebelt li").show(); //was hidden for graceful degradation
	$("li.invisiblebeltitem").show(); //stupid IE
		

//adCouch groks GAM's dom manipulation and prettifies page accordingly
function adCouch(addiv) {
	var premiumbox = "#google_ads_div_home-super-blog-box";
   		$(addiv).each(function() {
   		if ($(this).children().length > 0) {
			$(this).addClass("mainblog_box_couch");
				if (addiv != premiumbox) {	
					$(this).after("<div class='divider'></div>");
				}
			} else {
		$(this).hide();
		}
	});
}

adCouch("#google_ads_div_home-super-blog-box");
adCouch("#google_ads_div_MainPage-TopBox");
adCouch("#google_ads_div_MainPage-SecondBox");

//stats param function
function appendRef(container, reftag) {
	var match = "talkingpointsmemo";
    $(container).each(function() {

    	if ( ($(this).attr('href').match(match)) && (!$(this).hasClass("noref")) ) {  		   		
        	var href = $(this).attr('href');             	
     		
     		var href = href.replace(/\?ref=.*$/,'');
     		
     			if ($(this).attr('href').match(/(id=|img=|page=)/)) {
     			
     				var refprefix = "&";
     			
     			} else {
     			
     				var refprefix = "?";
     			
     			}
     			
     			
     		var href = (href + refprefix + reftag); 
     		
     		
     		
     		$(this).attr('href', href);        
        
        }
    });
}

//fill this in for all the sections
appendRef(".blog_inner a", "ref=fpblg");
appendRef(".banner a", "ref=fpban");
appendRef(".breaking a", "ref=fpbrk");
appendRef(".feature a", "ref=fpa");
appendRef(".areab a", "ref=fpb");
appendRef(".areac a", "ref=fpc");
appendRef(".aread a", "ref=fpd");
appendRef(".belt a", "ref=fpblt");



//searchpop
$("a.searchpop").click(function() {
	$("#mainnavright").fadeOut("fast");
	$("#searchpop").fadeIn("fast");
});

$("a.hidesearchpop").click(function() {
	$("#searchpop").fadeOut("fast");
	$("#mainnavright").fadeIn("fast");	
});


//adjust big reccounts in reader voices
$("a.reccount").each(function() {

	if ($(this).html().length >= 3) {
		$(this).css("font-size","18px").css("margin-left","-2px");
	}
	});





}); //dom ready function


