
// modal
function showVideoModal(video) {	
	var videoModalShell = document.getElementById('videoModalShell');
	videoModalShell.style.display = 'block';
	showVideo(video);
	var header = videoModalShell.getElementsByTagName('h5')[0];
	header.className = video;
}

function closeModal(modalId) {
	var modal = document.getElementById(modalId);
	var elements = modal.getElementsByTagName('p');
	var header = modal.getElementsByTagName('h5')[0];
	for (i = 0; i < elements.length; i++) {
		elements[i].innerHTML = '&nbsp;';
	}
	header.innerHTML = '&nbsp;';
	modal.style.display = 'none';
}

function showModal(link){
	var contentElement = document.getElementById(link.getAttribute('href').substring(link.getAttribute('href').lastIndexOf('#') + 1));
	if (contentElement) {
		
		var modalBackground = document.createElement('div');
		modalBackground.className = 'modalbackground';
		document.body.appendChild(modalBackground);
		
		var modalWindow = document.createElement('div');
		modalWindow.className = 'modalwindow';
		//if (bVideo) modalWindow.className = 'modalwindow videomodal';
		document.body.appendChild(modalWindow);
	
		var dialogDiv = document.createElement('div');
		dialogDiv.className = 'dialog';
		
		var contentDiv = document.createElement('div');
		contentDiv.className = 'dialogcontent';
		
		var tDiv = document.createElement('div');
		tDiv.className = 't';
		
		var bDiv = document.createElement('div');
		bDiv.className = 'b';
		bDiv.innerHTML = '<div></div>';
		
		var closeButton = document.createElement('input');
		closeButton.setAttribute('type', 'button');
		closeButton.className = 'modalclose';
		closeButton.value = ''
		
		contentDiv.appendChild(closeButton);
		contentDiv.appendChild(tDiv);
		dialogDiv.appendChild(contentDiv);
		dialogDiv.appendChild(bDiv);
		
		modalWindow.appendChild(dialogDiv);
		var contentClone = contentElement.cloneNode(true);
		contentClone.setAttribute('id', contentClone.getAttribute('id') + '-modal');
		contentDiv.appendChild(contentClone);
		
		// text nodes
		
		var legalCopy = document.createElement('p');
		legalCopy.setAttribute('id','legalCopy');
		dialogDiv.appendChild(legalCopy);

		//close modal
		closeButton.onclick = function(){
			document.body.removeChild(modalBackground);
			document.body.removeChild(modalWindow)
		};
		modalBackground.onclick = function(){
			document.body.removeChild(modalBackground);
			document.body.removeChild(modalWindow)
		};
		
	}
}