var closeFunctionName = "closeNews()";
var closeText = "";

function loadContent(lang, type, id) {
	$("#actualContent").load('/info/lestroisforets/' + lang + '/popup/' + type + '/' + id);
	$("#subNav li").removeClass("active");
	$("#" + id).parent().addClass("active");
}

function showExtraNews(url) {
	showExtra(url, true);
}

function showExtra(url, news) {
	removeUI();
	var there = $("#actualContent");
	if (there != null) {
		there.remove();
	}
	$("#content").append("<div style='display:hidden' id='hiddenContent'><div id='contentInner'></div></div>");
	$("#contentInner").load(url, showExtraContent);
	closeFunctionName = (news == true ? "backToFlashFromNews()" : "closeNews()");
	closeText = (news == true ? "Close" : "Return");
}

//* Callback function for the show Method .. will copy the content from the hidden div into the show div and then delete the hidden div
function showExtraContent() {
	$("#content").show();
	$("#content").append("<div id='actualContent'></div>");
	$("#contentInner").prepend('<div id="closeButtonDiv" class="closeDiv"><div class="btn"><a href="#" onclick="javascript:' + closeFunctionName + ';">' + closeText + '</a></div></div>');
	$("#contentInner").clone().appendTo("#actualContent");
	$("#actualContent").fadeIn("slow");
	$("#hiddenContent").remove();
	initPagination();
}

function jumpToMovie(id) {
	var url = '/info/lestroisforets/' + getLanguage() + '/popup/MOV/' + id;
	$('.contentFrame').attr('src', url);
}

function jumpToItem(id) {
	var url = '/info/lestroisforets/' + getLanguage() + '/popup/CPSI/' + id;
	$('.contentFrame').attr('src', url);
}

//* Called from iFrame
function showNews(id) {
	self.parent.showExtra("/info/lestroisforets/" + getLanguage() + "/popup/NEWS/" + id, true);
}

//* News item TEASER selected from the search list
function showNewsFromSearch(id) {
	$("#actualContent").clone().attr("id", "hidden-actualContent").appendTo("#footer").css("display", "none");
	showExtra("/info/lestroisforets/" + getLanguage() + "/popup/NEWS/" + id);
}

//* Called when a news item is being viewed, and was called from a list
function closeNews() {
	var nl  = $("#actualContent");
	if (nl != null) {
		var there = $("#actualContent");
		if (there != null) {
			there.remove();
		}
		$("#hidden-actualContent").clone().attr("id", "actualContent").appendTo("#content").css("display", "block");
		$("#hidden-actualContent").remove();
	} else {
		showExtraNews("/info/lestroisforets/" + getLanguage() + "/popup/NEWSOV");
	}
}

function backToFlashFromNews() {
	$("#actualContent").fadeOut("fast");
	$("#actualContent").remove();
	slideFlashUp();
}

//* Force a content item to appear in teh main application
function jumpToItemFromSearch(p) {
	var url = '/info/lestroisforets/' + getLanguage() + '/popup/CPSI/' + p;
	if ($('#level2nav').length == 0) {
		createLevel2Nav();
	}
	closeNews();
	backToFlashFromNews();
	changeLevel2Nav(p);
	openFrame(url);
}

       
function pageselectCallback(page_index, jq){
	var new_content = $('#hiddenresult div.result:eq('+page_index+')').clone();
	$('#newslist').empty().append(new_content);
	return false;
}
	  

function initPagination() {
	var num_entries = $('#hiddenresult div.innerresult').length;
	// Create pagination element
	$("#Pagination > ul").pagination(num_entries, {
				num_edge_entries: 3,
				num_display_entries: 8,
				callback: pageselectCallback,
				items_per_page:5,
				prev_show_always:false,
				next_show_always:false
				
	});
}

function setWindowTitle (title) {
	var langTitle = getTitleForLanguage();
	var compoundTitle = "";
	
	if (title != "") 
		compoundTitle = langTitle + " : " + title;
	else
		compoundTitle = langTitle;
	
	document.title = compoundTitle;
}
	 
	 