function initialize_video_page () {
	var q = '';
	// Process what is being called
	var regex = new RegExp( "[?](.*)$" );
	var results = regex.exec( window.location.href );
	if (results){
		if (results.length == 2) q = results[1];
	}
	// default
	if (q == '') return;
	
	// q is a video
	if (q.match(/[0-9][0-9][0-9][0-9]\/[0-9][0-9]\/[0-9][0-9]/)) {
		if (!q.match(/^\/video/)) q = '/video/'+q;
		removeDuplicateVideos(q);
	}
}

//ensure that duplicate videos are not in the playlist
function removeDuplicateVideos(qVideo) {
	var len = playlist.length;
	
	for(var i=0; i<=len-1; i++) {
		var pVideo = playlist[i].url;
		
		if(qVideo.indexOf(pVideo) >= 0) {	//if the query video is already in the playlist
			playlist.splice(i, 1);	//remove it
			break;
		}
	}
	
	playlist.unshift({url: qVideo});	//add query video to the front of the playlist
}

function videoLoaded(_videoMetaData) {
	videoMetaRenderer.update(_videoMetaData);
}

var videoMetaRenderer;
function VideoMetaRenderer(_videoPanel) {
	var oVideoPanelDOMRef;
	var headline;
	var description;
	var source;
	var oVideo;
	
	init();
	
	function init() {
		try {
			oVideoPanelDOMRef = document.getElementById(_videoPanel);
		} catch (e) {
			oVideoPanelDOMRef = null;
		}
	}
	
	this.update = function(_oVideo) {
		if (_oVideo) {
			oVideo = _oVideo;
		}
		
		if (oVideo == null || oVideoPanelDOMRef == null) {
			return false;
		}
		
		setHeadline(oVideo.headline);
		setDescription(oVideo.description);
		setSource(oVideo.source);
		
		render();
		return true;
	}
	
	function render() {
		var nodeHeadlineText;
		var nodeDescriptionText;
		var nodeSourceText;
		var eH3;
		var eP;
		var eBR;
		var eContainer;
		
		eDataContainer = document.createElement("div");
		
		eH3 = document.createElement("h3");
		nodeHeadlineText = document.createTextNode(getHeadline());
		eH3.appendChild(nodeHeadlineText);
		eDataContainer.appendChild(eH3);
		
		eP = document.createElement("p");
		nodeSummaryText = document.createTextNode(getDescription());
		eP.appendChild(nodeSummaryText);
		eDataContainer.appendChild(eP);
		
		if (getSource() != null || getSource() != "") {
			eBR = document.createElement("br");
			eDataContainer.appendChild(eBR);
			
			eP = document.createElement("p");
			nodeSourceText = document.createTextNode(getSource())
			eP.appendChild(nodeSourceText);
			eDataContainer.appendChild(eP);
		}
		
		try {
			eReplaceableDIV = oVideoPanelDOMRef.getElementsByTagName('div')[0];
			oVideoPanelDOMRef.replaceChild(eDataContainer, eReplaceableDIV);
		} catch(e) { }
	}
	
	function setHeadline(_headline) {
		headline = _headline;
	}
	
	function getHeadline() {
		return headline;
	}
	
	function setDescription(_description) {
		description = _description;
	}
	
	function getDescription() {
		return description;
	}
	
	function setSource(_source) {
		if (_source) {
			source = "Credit: " + _source;
		}
	}
	
	function getSource() {
		return source;
	}
}