(function() { //Add Comment Counts
	var commentCats = ['', '149651', '154671', '149654', '160058', '172581', '153990', '174894']; //Limit comment counts to these categories (Home, hot button)  
	var validPage = ( jQuery.inArray( location.querystring.C, commentCats ) > -1 || jQuery.inArray( location.querystring, commentCats ) > -1 ) ? true : false;
	if( !validPage )  { return; }
	
	var countHTML = '<span class="comment-count">&nbsp;<span class="js-kit-comments-count" path="/story{id}">0</span>&nbsp;</span>';
	//var links =  $("#WNCol2 .wnRole-STORY a");
	  var links =  $("#WNCol2 .wnDVSummary p a");
	$(links).each(function(i, link) {									  
		try{
			var id = $(link).attr('href').split('S=')[1].split('&')[0]; //Get the story ID
			if( $(link).find('img.wnVideoIncluded').length > 0 ) { //If story has video image, insert count before that
				$( countHTML.replace(/\{id\}/, id) ).insertBefore( $(link).find('img.wnVideoIncluded') );
			} else {
				$(link).append( countHTML.replace(/\{id\}/, id) );
			}
		} catch(e) { console.log(e); }
	});
	if(links.length > 0) { jQuery.require(['http://js-kit.com/comments-count.js']); }
})();

$("#wnJsKitCommentingLimited .terms").html("<span class='terms_of_use'>PLEASE READ TERMS OF USE: CBS 8 welcomes your comments. We provide our comments feature as a forum for CIVIL debate and communication. Posters who are OFF-TOPIC, DISRESPECTFUL, INSULT, FLAME or ABUSE other users in any way will not be tolerated. Comment abusers will have their posts removed AND be blocked from participating in future discussions on our comments board. Please keep your comments on point. Notify us of any inappropriate comments by clicking the 'Flag' icon. By submitting a comment, you agree to the Terms of Service located at the bottom of this page.</span> ");

// STORY IMAGE ENLARGEMENT
$(document).ready(function() {

	// IF STORY PAGE
	if (wng_pageInfo.containerType == 'S') {

		// LOAD FANCYBOX CSS
		$('<link rel="stylesheet" type="text/css" href="http://ftpcontent.worldnow.com/kfmb/custom/js/fancybox/jquery.fancybox-1.2.6.css" media="screen" />').appendTo('body');	

		// LOAD FANCYBOX JS
		$.getScript("http://ftpcontent.worldnow.com/kfmb/custom/js/fancybox/jquery.fancybox-1.2.6.pack.js",  function(){
			// REWRITE PHOTO DISPLAY
			$('.wnStoryBodyGraphic img').wrap('<a></a>');

			$('<div style="height:25px;"><img style="width: 16px;float:left;padding:8px 0 0 15px;" src="http://ftpcontent.worldnow.com/kfmb/images/enlarge-icon.png"><span style="padding:0 0 0 5px;float:left;"> Click image to enlarge</span></div>').appendTo(".wnStoryBodyGraphic:last");
			
			$('.wnStoryBodyGraphic a').each(function(){
				$(this).attr('href', $(this).find('img').attr('src'));
				$(this).attr('title', $(this).find('img').attr('title'));
			});	
			
			$('.wnStoryBodyGraphic a').fancybox({
				'zoomOpacity':true,
				'zoomSpeedIn':300,
				'zoomSpeedOut':300
			});
		});

		/*
		// Chitika Ad Insert
		ch_client = "mgruber";
		ch_type = "mpu";
		ch_width = 550;
		ch_height = 250;
		ch_non_contextual = 4;
		ch_vertical = "premium";
		ch_ad_element = "chitika_ad";
		ch_callback = "ch_ad_render_search";
		ch_sid = "CommunityList_Bottom_3";
		ch_nump = 3;
		ch_codev = 1.1;
		ch_hq=1;          
		function ch_ad_render_search(){
		var adBody = '';
		adBody += "<h4 id='related_res'>Related Results</h4><ul>";
		
		for (var x = 0; x < ads.length; x++) {
		var vendor = ads[x]; //Each ad is a vendor object.
		adBody += '<li';
		adBody += '><h4 class="ch_title_head"><a href="' + vendor['vendors']['vendor'][0]['url'] + '">' + vendor['title'] + '</a></h4><div class="Img"><img src="' + vendor['vendors']['vendor'][0]['image'] + '" width="50" height="50" align="left"></div><div class="desc">' + vendor['description'] + '</div><a target="_blank" class="link" href="' + vendor['vendors']['vendor'][0]['url'] + '">' + vendor['vendors']['vendor'][0]['name'] + '</a></li>';
		if(x !=(ads.length-1)){adBody += '<li class="brd">&nbsp</li>';};
		}
		adBody += "</ul>";
		adBody += '<div class="sponsored"><a href="http://chitika.com/publishers.php?refid=ezd123" class="brand" target="_blank">Ads By Chitika</a></div>';
		//document.getElementById(ch_ad_element).innerHTML = adBody;
		chObj.removeScriptTag();
		
		$("#WNStoryBody").after('<div id="'+ch_ad_element+'">'+adBody+'</div>');
		}
		$.getScript("http://scripts.chitika.net/eminimalls/ajmm.js");
		*/
	}
});
