// function displayHomePageCompetitions() {	
// 	if ($(".compimage").size() > 0) {
// 		var links;
// 		$(".competition").each(function (i) {
// 			//var compImage = $(".compimage", this ).get(0);
// 			var title, loc, img, src;
// 			title = $("h3", this).text();
// 			loc = "http://www.kidsonthecoast.com.au";
// 			//
// 			//$(this).append(compImage);
// 			img = $("img", this).get(0);
// 			src = $(img).attr("src");
// 			$(img).attr("src", "/Utilities/ShowThumbnail.aspx?USM=1&R=1&W=137&H=137&Img=" + src);
// 			$(img).attr("title", title);
// 			$(img).attr("alt", title);
// 			$(img).attr("class", "dynamic_comp_image");
// 			$(this).wrap("<a href='" + loc + "' class='dynamic_comp_image_link'></a>");
// 			$(this).replaceWith(img);
// 		});	
// 		links = $(".dynamic_comp_image_link");
// 		$(".com-box-content").replaceWith("<div class='com-box-content'></div>");
// 		$(".com-box-content").append(links);
// 		$(".dynamic_comp_image").last().attr("class", "nm");
// 	}
// }

function initCategoryMenu() {
	//used for the review topics and article categories menus plus holiday guide activity menus
	if($('body.magazine #category_menu_list').length > 0 || $('body.holiday-guide #category_menu_list').length > 0 || $('body.community #category_menu_list').length > 0) {
		initDropDown($('#category_menu_list'), $('.direct-action-2'), $('.direct-action-2 h3.drop'), "hover");
	}

	$('#category_menu_list li').each(function () {
		$(this).click(function () {
			window.location = $('a', this).attr('href');
		});
	});
	
}

function showCurrentArticleCategory() {
	if ($('span.category_name').length > 0 && $('span.category_name').text() !== "") {
		$('.current_article_category').html($('span.category_name').html());
	}
}

function printTitle(articlesOrReviews, title) {
	return "Read all Kids on the Coast " + title.slice(0, -1).toLowerCase() + " " + articlesOrReviews;
}

function getCategoryLink() {
//takes a BC name and converts it into a URL friendly slug and returns the category URL
	if ($('a.need_category_link').length > 0 || $('.child_needs_category_link a').length > 0) {
		$('a.need_category_link, .child_needs_category_link a').each(function () {
			var n, slug, u;
			n = $(this).text();
			slug = convertToSlug(n);
			u = "/_webapp/" + slug;
			$(this).attr("href", u);
			$(this).attr("title", $(this).parent().hasClass('review') ? printTitle("reviews", n) : printTitle("articles", n));
		});
	}
}

function getCategoryLinkFromLink() {
	//takes a BC name within a link and converts it into a URL friendly slug and returns the category URL
	if ($('a.need_category_link_from_link').length > 0) {
		$('a.need_category_link_from_link').each(function () {
			if ($('h3.category_link_for_js').length > 0) {
				var n, slug, u;
				n = $('h3.category_link_for_js a').text();
				slug = convertToSlug(n);
				u = "/_webapp/" + slug;
				$(this).text(n);
				$(this).attr("href", u);
				$(this).attr("title", printTitle("articles", n));
			} else {
				$(this).hide();
			}
		});
	}
}

function initForumMenu() {
	if($('ul#category_menu_list.forum').length > 0) {
		if($('.forum-list-for-menu').length > 0) {
			var ul, list, h3;
			ul = $('ul#category_menu_list.forum');
			list = $('.forum-list-for-menu table.forum div.forum');
			$(list).each(function() {
				h3 = $(this).html();
				$(ul).append('<li>' + h3 + '</li>');
			});
		}
	}
}

$(document).ready(function () {
	getCategoryLink();
	getCategoryLinkFromLink();
	showCurrentArticleCategory();
	initCategoryMenu();
	initForumMenu();
});
