<!--
currentWorkID = 0; // Where current Work ID is stored to manage request for opened window
currentAuthorID = 0; // Where current Author ID is stored to manage request for opened window
currentContestId = 0; // Where current Contest ID is stored to manage request for opened window 
defaultAuthorImage = "/dms-static/14be5641-2c2d-4e61-81a0-71b7365a3b97";
defaultWorkImage = "/dms-static/bdc1060b-96bb-489e-b0b4-aaa7422210d6";
currentBio = "";
currentWorkImage = "";
currentAuthorImage = "";
function getInfoId () {
	alert("currentAuthorID: " + currentAuthorID + " - currentWorkID: " + currentWorkID + " - currentContestId: " + currentContestId);
}

function setInformation() {
	var fromLeft = (document.documentElement.clientWidth / 2) - 325 ;
	$("#information").css("left", fromLeft);
}

function setChronicle() {
	$("#loaderLayer").show();
	// Get the Work Summary bio
	bioUrl = serverUrl + "/Administration/JsonServlet?action=workdetail&workId=" + currentWorkID + "&detail=chronicle";
	$.get(bioUrl, function(data){
		 $("#authbod1").empty();
		if (data != "" && data != "-") {
			src = serverUrl + contextPath + "/docroot/dewplayer.swf?autoplay=1&son=" + serverUrl + contextPath + data;
			$("#authbod1").empty();
			$("#authbod1").append("<table border=0><tr><td rowspan=\"2\" valign=\"top\"><img src=\"" + contextPath + "/docroot/imgs/france_bleu.gif\" alt=\"Les chroniques enregistr&eacute;es par France Bleu Pays de Savoie\" align=\"left\" style=\"margin:10px\"/></td><td align=left><b>Les chroniques enregistr&eacute;es par France Bleu Pays de Savoie</b></td></tr><tr><td align=left>dans le cadre de l'&eacute;mission \"Sur Suisse, sur France\", diffus&eacute;e chaque vendredi entre 17h et 18h</td></tr></table>");
			$("#authbod1").append ("<br /><br /><object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" allowScriptAccess=\"sameDomain\"  codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width=\"240\" height=\"20\" id=\"mediaPlayer\" name=\"mediaPlayer\"><param name=\"swliveconnect\" value=\"true\"><param name=\"movie\" value=\"" + src + "\" /><param name=\"quality\" value=\"high\" /><embed src=\"" + src + "\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"240\" height=\"20\" id=\"mediaPlayer\" name=\"mediaPlayer\" allowScriptAccess=\"sameDomain\" swliveconnect=\"true\"></embed>");
		} else {
				$("#authbod1").append ("<p>Pas de chronique disponible!</p>");
		}
	});
	$("#loaderLayer").hide();
	return false;
}


function setExtracts() {
	$("#loaderLayer").show();
	// Get the Work Summary bio
	bioUrl = serverUrl + "/Administration/JsonServlet?action=workdetail&workId=" + currentWorkID + "&detail=extracts";
	$.get(bioUrl, function(data){
		data = data.replace(/\r\n/g, "<br />");
		$("#authbod1").empty();
		$("#authbod1").append ("<table id=\"infoAuthor\" cellpadding=\"3\" border=\"0\" width=\"650\"><tr><td align=\"left\" valign=\"top\"><p>" + data + "</p></td></tr></table>");
	});
	$("#loaderLayer").hide();
	return false;
}

function setCritics() {
	$("#loaderLayer").show();
	// Get the Work Summary bio
	bioUrl = serverUrl + "/Administration/JsonServlet?action=workdetail&workId=" + currentWorkID + "&detail=critics";
	$.get(bioUrl, function(data){
		data = data.replace(/\r\n/g, "<br />");
		$("#authbod1").empty();
		$("#authbod1").append ("<table id=\"infoAuthor\" cellpadding=\"3\" border=\"0\" width=\"650\"><tr><td align=\"left\" valign=\"top\"><p>" + data + "</p></td></tr></table>");
	});
	$("#loaderLayer").hide();
	return false;
}

function setSummary() {
	$("#loaderLayer").show();
	// Get the Work Summary bio
	bioUrl = serverUrl + "/Administration/JsonServlet?action=workdetail&workId=" + currentWorkID + "&detail=summary";
	$.get(bioUrl, function(data){
		data = data.replace(/\r\n/g, "<br />");
		$("#authbod1").empty();
		$("#authbod1").append ("<table id=\"infoAuthor\" cellpadding=\"3\" border=\"0\" width=\"650\"><tr><td align=\"left\" valign=\"top\"><p>" + data + "</p></td></tr></table>");
	});
	$("#loaderLayer").hide();
	return false;
}

function setAuthorBio() {
	$("#loaderLayer").show();
	// Get the Author bio
	bioUrl = serverUrl + "/Administration/JsonServlet?action=authordetail&authorId=" + currentAuthorID + "&detail=bio";
	lowSrc = serverUrl + contextPath + "/docroot/imgs/img-loader.gif"
	//alert(lowSrc);
	$.get(bioUrl, function(data){
		data = data.replace(/\r\n/g, "<br />");
		$("#authbod1").empty();
		//$("#authbod1").append ("<table id=\"infoAuthor\" cellpadding=\"3\" border=\"0\" width=\"650\"><tr><td align=\"left\" valign=\"top\"><img  lowsrc=\"" + lowSrc + "\" src=\"" + currentAuthorImage + "\" border=\"0\" /></td><td align=\"left\" valign=\"top\"><p>" + data + "</p></td><td align=\"right\" valign=\"top\"><img src=\"" + currentWorkImage + "\" border=\"0\" /></td></tr></table>");
		$("#authbod1").append ("<table><tr><td valign=\"top\"><img id=\"imageAuthor\" align=\"left\" lowsrc=\"" + lowSrc + "\" src=\"" + currentAuthorImage + "\" border=\"0\" />" + data + "</td><td><img id=\"workImage\" align=\"right\" src=\"" + currentWorkImage + "\" border=\"0\" /></td></tr></table");
	});
	$("#loaderLayer").hide();
	return false;
}

function setAuthorInfo() {
	//alert(currentAuthorID);
	if(currentContestId == undefined) {
		jsonUrl = serverUrl + "/Administration/JsonServlet?action=display";
	} else {
		jsonUrl = serverUrl + "/Administration/JsonServlet?action=display&contestId=" + currentContestId;
	}
	
	$.getJSON(jsonUrl, function(data){
			$("#authorBar").empty();
			$.each(data.authors, function(i,author){
				if(author.authorId == currentAuthorID) {
					$("#authorBar").append("<strong>" + author.firstName + " " + author.lastName + "</strong> <br />");
					$("#authorBar").append("<em>" + author.workName + " - " + author.year + " - " + author.kind+ "</em> ");
					// Check for work image
				if(author.workImage != "" && author.workImage != "-")
					currentWorkImage = serverUrl + contextPath + author.workImage;
				else
					currentWorkImage = serverUrl + contextPath + defaultWorkImage;
				// Check for Author image
				if(author.authorImage != "" && author.authorImage != "-")
					currentAuthorImage = serverUrl + contextPath + author.authorImage;
				else
					currentAuthorImage = serverUrl + contextPath + defaultAuthorImage;
				}
			});
			setAuthorBio();
	});
	return false;
}

function loadAuthor () {
	$("#loaderLayer").show();
	setInformation();
	$("#information").show();
	$("#information a.fermer").bind("click", function(){
		$("#authbod1").empty();
		$("#information").hide();   
	});
	$("#information a.author").bind("click", setAuthorInfo);
	$("#information a.summary").bind("click", setSummary);
	$("#information a.critics").bind("click", setCritics);
	$("#information a.extracts").bind("click", setExtracts);
	//$("#information").draggable();
	$("#information a.chronicle").bind("click", setChronicle);
	currentWorkID = this.id;
	tmp = this.href.toString().split("#");
	currentAuthorID = this.href.toString().substring(this.href.toString().lastIndexOf("#")+1);
	//currentAuthorID = tmp[1];
	//alert(currentAuthorID);
	//alert("currentAuthorID: " + currentAuthorID + " - " + "currentWorkID: " + currentWorkID);
	setAuthorInfo();
	return false;
}
/**
	Load the list of the authors of a year
*/
function loadAuthors() {
	$("#loaderLayer").show();
	
	currentContestId = this.id;
	if(currentContestId == undefined) {
		jsonUrl = serverUrl + "/Administration/JsonServlet?action=display";
	} else {
		jsonUrl = serverUrl + "/Administration/JsonServlet?action=display&contestId=" + currentContestId;
	}
	//alert(jsonUrl);
	$.getJSON(jsonUrl, function(data){
			$("#authorsList").empty();
			$("#authorsList").append("<div class=\"annee\">S&eacute;lection " + data.contestYear + "</div>");
			$("#authorsList").append("<div class=\"areaTitle\">SUISSE ROMANDE</div>");
			$.each(data.authors, function(i,author){
				if(author.area.toLowerCase() == "suisse romande") {
					$("#authorsList").append("<a class=\"authorsListLink\" id=\"" + author.workId + "\" href=\"#" + author.authorId + "\">" + author.firstName + " " + author.lastName + "</a>, "+ author.workName+ "<br/>");
				}
			});
			$("#authorsList").append("<br/><br/><div class=\"areaTitle\">RH&Ocirc;NE ALPES</div>");
			$.each(data.authors, function(i,author){
				if(author.area.toLowerCase() != "suisse romande") {
					$("#authorsList").append("<a class=\"authorsListLink\" id=\"" + author.workId + "\" href=\"#" + author.authorId + "\">" + author.firstName + " " + author.lastName + "</a>, "+ author.workName+ "<br/>");
				}
			});
		$("#authorsList a").bind("click", loadAuthor);
	});
	$("#loaderLayer").hide();
	return false;
}


function setLoader () {
	$("#loaderLayer").css("height", document.documentElement.clientHeight);
	$("#loaderLayer").css("width", document.documentElement.clientWidth);
}
/**
Load the Contest years
*/
function loadYears() {
	$("#loaderLayer").show();
	$("#yearList").empty();
	jsonUrl = serverUrl + "/Administration/JsonServlet?action=contests";
	$.getJSON(jsonUrl, function(data){
			$.each(data.contests, function(i,contest){
			if(contest.isFinal) {
				$("#yearList").append("<a href=\"#\"  id=\"" + contest.id + "\">" + contest.year + "</a>");
			}
		});
		$("#yearList a").bind("click", loadAuthors);
	});
	loadAuthors();
}

$(document).ready(function(){
	setLoader(); // Set the dimensions of the Loader Layer
	loadYears();
});

//-->