function updatePosition(elm) {       	
	var vc = document.getElementById('viewer_Canvas');
	var cl = document.getElementById('clickelm');
	var wh = getWH();
        
	vc.style.width = 0+"px";
	vc.style.height = 0+"px";
	cl.style.width = 0+"px";
	cl.style.height = 0+"px"; 
	w = 0;
	h = 0;

	if(document.height != undefined) {
		h =document.height;
		w =document.width;                	
	} else if (document.body.scrollHeight != undefined) {                	
       	h = document.body.scrollHeight;
       	w = document.body.scrollWidth;   
	} else {
		h = document.documentElement.scrollHeight;
		w = document.documentElement.scrollWidth;
	}

	vc.style.width = w+"px";
	vc.style.height = h+"px";
	cl.style.width = w+"px";
	cl.style.height = h+"px";

	if(elm){
		objw = parseInt(elm.style.width)/2;
		objh = parseInt(elm.style.height)/2;
		elm.style.marginLeft = ((wh[0]/2)-(objw))+"px";
			elm.style.marginTop = ((wh[1]/2)-(objh))+"px";
	}
}

function getWH() {
	w = 0;
	h = 0;

	if(document.height != undefined) {                	
		h =document.height;
		w =document.width;                	
	} else if (document.body.scrollHeight != undefined) {                	
       	h = document.body.scrollHeight;
       	w = document.body.scrollWidth;   
	} else {
		h = document.documentElement.scrollHeight;
		w = document.documentElement.scrollWidth;
	}

	return [w,h];
}

function showViewer(c_id) {
	var confs = [];
	for(var i in window.mwcData.presentations)
		confs.push(window.mwcData.presentations[i].presId);

	var vc = document.getElementById('viewer_Canvas');
	var c = document.getElementById('viewer_'+c_id);
	var container = document.getElementById('viewer_container');
	var wh = getWH();

	vc.style.display = 'block';
	c.style.display = 'block';

	container.style.marginLeft = ((wh[0] / 2) - 260) + 'px';
	container.style.marginRight = ((wh[0] / 2) - 260) + 'px';

	for(conf_index in confs) {
		if(c_id != confs[conf_index]) {
			var vDiv = document.getElementById('viewer_'+confs[conf_index]);
			if(vDiv == null) {
				// DIV is not done loading yet -- do nothing.
			} else {
				vDiv.style.display = 'none';
			}
		}
	}

	updatePosition();
}

function closeViewer() {
	var vc = document.getElementById('viewer_Canvas');
	vc.style.display = 'none';
}

function addPresentationLinksTable() {
	if(window.mwcData.session_count <= 1) {
		addPresentationLinksTableNoSessions();
	} else {
		addPresentationLinksTableWithSessions();
	}
}

function addPresentationLinksTableNoSessions() {
	var html = "<table>\n";
	var count = 0;

	for(var i in window.mwcData.presentations) {
		// Add <tr> for new row
		if(count % 2 == 0)
			html += "  <tr>\n";

		// Add presentation link
		html += "    <td><img src=\"http://www.multiwebcast.com/image/photo_speaker/" + window.mwcData.presentations[i].speakerId + ".jpg\" /></td>\n";
		html += "    <td class=\"boite_presentation\">\n";
		html += "      <a href=\"#\" onClick=\"showViewer(" + window.mwcData.presentations[i].presId + ");\">" + window.mwcData.presentations[i].presTitle + "</a><br/>";
		html += "      by " + window.mwcData.presentations[i].speakerName + "<br><br>\n";
		html += "      <span>" + window.mwcData.presentations[i].presDate + " | " + window.mwcData.presentations[i].presLength + " minute" + (window.mwcData.presentations[i].presLength > 1 ? 's' : '')+"</span>\n";
		html += "    </td>\n";			

		// Add closing <tr>
		count++;
		if(count % 2 == 0)
			html += "  </tr>\n";

	}

	// Add blank cells on the right if the last presentation was at the left	
	if(count % 2 == 1) {
		html += "    <td>&nbsp;</td>\n";
		html += "    <td>&nbsp;</td>\n";
		html += "  </tr>\n";
	}

	html += "</table>\n";

	document.getElementById('div_pres_links').innerHTML = html;
}

function addPresentationLinksTableWithSessions() {
	var html = "";

	for(var s in window.mwcData.sessions) {	
		var count = 0;
		html += "<div class='session_title'>&raquo;&nbsp;" + window.mwcData.sessions[s].session_name + "</div>\n";
		html += "<table class='session'>\n";

		for(var i in window.mwcData.sessions[s].presentations) {
			var c_id = window.mwcData.sessions[s].presentations[i];

			// Add <tr> for new row
			if(count % 2 == 0)
				html += "  <tr>\n";

			// Add presentation link
			html += "    <td><img src=\"http://www.multiwebcast.com/image/photo_speaker/" + window.mwcData.presentations[c_id].speakerId + ".jpg\" /></td>\n";
			html += "    <td class=\"boite_presentation\">\n";
			html += "      <a href=\"#\" onClick=\"showViewer(" + window.mwcData.presentations[c_id].presId + ");\">" + window.mwcData.presentations[c_id].presTitle + "</a><br/>";
			html += "      by " + window.mwcData.presentations[c_id].speakerName + "<br><br>\n";
			html += "      <span>" + window.mwcData.presentations[c_id].presDate + " | " + window.mwcData.presentations[c_id].presLength + " minute" + (window.mwcData.presentations[c_id].presLength > 1 ? 's' : '')+"</span>\n";
			html += "    </td>\n";				

			// Add closing <tr>
			count++;
			if(count % 2 == 0)
				html += "  </tr>\n";

		}//presentations

		// Add blank cells on the right if the last presentation was at the left	
		if(count % 2 == 1) {
			html += "    <td>&nbsp;</td>\n";
			html += "    <td>&nbsp;</td>\n";
			html += "  </tr>\n";
		}

		html += "</table>\n";
	}//sessions

	document.getElementById('div_pres_links').innerHTML = html;
}


function getViewerFlashObjectsHTML() {
	var html = "";

	for(var i in window.mwcData.presentations) {
		html += "<div id=\"viewer_" + window.mwcData.presentations[i].presId + "\" style=\"display:none;\">\n";
		html += "  <sc" + "ript src=\"https://www.multiwebcast.com/viewer/" + window.mwcData.config.vemb_code + "/js/" + window.mwcData.presentations[i].presId + "/" + window.mwcData.presentations[i].cm_id + "/get/\" type=\"text/javascript\"></sc" + "ript>\n";
		html += "  <noscript>\n"
		html += "    <div class=\"title\">" + window.mwcData.presentations[i].presTitle + "</div>\n";
		html += "    <div class=\"author\">" + window.mwcData.presentations[i].speakerName + "</div>\n";
		html += "    <div class=\"event\">" + window.mwcData.event.name + "</div>\n";
		html += "    <div class=\"publisher\">Webcast by <a href=\"https://www.multiwebcast.com/\">MULTIWEBCAST.com</a></div>\n";
		html += "  </noscript>\n";
		html += "</div>\n\n";
	}

	return html;
}
