// USE THIS FILE ONLY FOR SCRIPT THAT IS SPECIFIC TO THE LEARNING ENGLISH SITE
// Global scripts must go in \worldservice\js\3\core.js
// Use \lib\[modulename].js for module-specific scripts

new function($){	
	var LearningEnglish = {
		metadata: {
			author: 'BBC World Service',
			version: '0.0.2'
		},
		wsCarousel: {
			flush: true,
			divClass: "list-content",
			ulClass: "list-items"		
		}
	};
	LearningEnglish = pseudoPrototype($.core, LearningEnglish);
	$.ws = LearningEnglish;
	
}(jQuery);

$(function($){
	$.ws.wsCorners();
	$.ws.wsQuotes("inline", "block", "");
	$.ws.wsPopup();	
				
	if ($.fn.wsCarousel) {			
		// Loop through each carousel on the page
		$(".li-carousel").each(function() {				

			var thisCarousel = $.fn.wsCarousel;
		
			// Build the carousel
			thisCarousel.build($(this));	
		});						
	};
});

$(document).ready(function(){
	// Refactor the markup for enhanced styling
	
	// Metadata in teasers
	$(".teaser:has(.ts-metadata)").each(function() {
		$(this).addClass("js-enhanced");
		var newMarkup ='';
		$(this).find(".ts-metadata").each(function() {
			$(this).find("li").each(function() {
				newMarkup = newMarkup + '<span class="' + $(this).attr("class") + '">' + $(this).text() + '</span><span class="divider"> </span>'
			});					
			$(this).replaceWith('<p class="ts-metadata">' + newMarkup + '</p>');			
		});	
		$(this).find(".ts-metadata .divider:last").remove();
	});
	
	// Target-genre colours for IE 6.0
	if ($.browser.msie && $.browser.version <= 6 ) {
		$(".ts-310x130, .ts-150x130, .ts-150promo").each(function() {		
			var targetGenre = $(this).attr("class").match(/target-[a-z1-9-]*/i);	
			$(this).wrapAll('<div class="' + targetGenre + '"></div>');
		});
	};

});