	
	
			

//GET CONTENT FIELDS | The DMN Forecast: Cool Morning, Warm Afternoon -->
// GET CONTENT FIELDS | http://www.nbcdfw.com/video/#!/weather/dmn-forecast/The-DMN-Forecast_-Cool-Morning,-Warm-Afternoon/332322662 -->
// GET CONTENT FIELDS | http://media.nbcdfw.com/images/300*169/WX+Expert+Forecast+Thumb.jpg -->
// GET CONTENT FIELDS | http://www.nbcdfw.com/video/#!/weather/dmn-forecast/The-DMN-Forecast_-Cool-Morning,-Warm-Afternoon/332322662 -->

// CONTENT DATA | 332322662 -->
// CONTENT DATA | RWHl7dnXCx87 -->




/**
 * NBC Player Maker
 * A Javascript widget that will dynamically create an iframe pointing to
 * our video player
 * 
 * Created by: Rob Sable
 * Date created: 11/19/2013
 * 
 * Last edited by: Rob Sable
 * Last modified: 01/03/2014
 */

/**
 * Usage:
 * <script type="text/javascript" charset="UTF-8" defer="true" src="/some/path/will/be/here/?vrid=123456789&tpid=sOm3keyb0ardM4sh"></script>
 * 
 * WARNING: DO NOT CALL .JS FILE DIRECTLY, THE TEMPLATE CODE WILL FAIL. REFERENCE IT VIA THE PATH ONLY, AS ILLUSTRATED ABOVE.
 */

if(typeof console == "undefined") {

	console = {};
	console.log = function(msg) {
	// fail silently
	}
	
	console.warn = function(msg) {
	// fail silently
	}
	
	console.error = function(msg) {
	// fail silently
	}

}

(function() {
	
	//console.log("/////////////////////////////////////////");
	//console.log("/// NBC PLAYER MAKER ////////////////////");
	//console.log("/////////////////////////////////////////");
	
	// Gather the scripts on the page.
	window['nbcLMP4428'] = {};
	
	// Parameter parsing
	window['nbcLMP4428'].scriptTagsOnPage = document.getElementsByTagName('script');
	window['nbcLMP4428'].thisScriptName = 'dmn-forecast';
	window['nbcLMP4428'].thisScriptSource = null;
	window['nbcLMP4428'].activeEmbeds = new Array();
	window['nbcLMP4428'].usedEmbeds = new Array();
	window['nbcLMP4428'].scriptSplit = null;
	window['nbcLMP4428'].scriptParams = null;
	window['nbcLMP4428'].discreteParams = null;
	window['nbcLMP4428'].useThisAsParent = null;
	window['nbcLMP4428'].encodedURI = encodeURIComponent(location.origin+location.pathname);
	window['nbcLMP4428'].encodedHost = encodeURIComponent(location.origin);
	window['nbcLMP4428'].origin = null;
	window['nbcLMP4428'].videoThumbPath = '"http://media.nbcdfw.com/images/300*169/WX+Expert+Forecast+Thumb.jpg';
	
	
	
	
	// Comb the scripts!
	for(var a=0; a<window['nbcLMP4428'].scriptTagsOnPage.length; a++) {
		//console.log("/// NBC PLAYER MAKER IS SEARCHING FOR ITSELF (How zen...) | " + window['nbcLMP4428'].scriptTagsOnPage[a].src);
			if(window['nbcLMP4428'].scriptTagsOnPage[a].src.match(window['nbcLMP4428'].thisScriptName)) {
				
				
				window['nbcLMP4428'].thisScriptSource = window['nbcLMP4428'].scriptTagsOnPage[a].src;
				window['nbcLMP4428'].activeEmbeds.push(window['nbcLMP4428'].scriptTagsOnPage[a].src);
				
				//console.log("/// NBC PLAYER MAKER | " + window['nbcLMP4428'].scriptTagsOnPage[a].parentNode.id);
				window['nbcLMP4428'].useThisAsParent = window['nbcLMP4428'].scriptTagsOnPage[a].parentNode;
				
			}
	};
	

	// Do some splits...
	//window['nbcLMP4428'].scriptSplit = window['nbcLMP4428'].thisScriptSource.split('/weather/dmn-forecast/');
	//window['nbcLMP4428'].scriptParams = window['nbcLMP4428'].scriptSplit[1].split('?');
	//window['nbcLMP4428'].discreteParams = window['nbcLMP4428'].scriptParams[1].split('&');
	
	// Now dig through the parameters for the origin
	
	function getParams(requestedParam) {
	for(var q=0; q<window['nbcLMP4428'].discreteParams.length; q++) {
		if(window['nbcLMP4428'].discreteParams[q].match(requestedParam)) {
			var parsedParam = window['nbcLMP4428'].discreteParams[q].split('=');
			break;
		}
	}
	return parsedParam[1];
	}
	
	//window['nbcLMP4428'].origin = getParams('origin');
	
	//console.log("/// NBC PLAYER MAKER PARAMETERS | "+ window['nbcLMP4428'].scriptParams[1]);
	//console.log('/// NBC PLAYER MAKER IFRAME PREVIEW... | <iframe id="window['nbcLMP4428']layer" width="X" height="Y" src="http://www.'+ window['nbcLMP4428'].origin + '/templates/nbc_partner_player?'+window['nbcLMP4428'].scriptParams[1] + "&turl="+location.origin+location.pathname+'"></iframe>');
	
	
	// DOM element creation - THUMBNAIL/PLAY BUTTON
	window['nbcLMP4428'].thumbnailContainer = document.createElement('div'); // Container with background image as thumbnail
	window['nbcLMP4428'].playButton = document.createElement('img'); // Absolutely positioned.
	window['nbcLMP4428'].thumbnailContainer.id = 'nbcdmnplayer';
	window['nbcLMP4428'].thumbnailContainer.style.width = '300px';
	window['nbcLMP4428'].thumbnailContainer.style.height = '169px';
	window['nbcLMP4428'].thumbnailContainer.style.position = 'relative';
	window['nbcLMP4428'].thumbnailContainer.style.backgroundImage="url('http://media.nbcdfw.com/images/300*169/WX+Expert+Forecast+Thumb.jpg')";
	
	window['nbcLMP4428'].playButton.src = 'http://media.nbcdfw.com/designimages/solo_sprite_hp_play_video.png';
	window['nbcLMP4428'].playButton.width = 55;
	window['nbcLMP4428'].playButton.height = 41;
	window['nbcLMP4428'].playButton.style.position = 'absolute';
	window['nbcLMP4428'].playButton.style.top = "68px";
	window['nbcLMP4428'].playButton.style.left = "127px";
	
	window['nbcLMP4428'].playButton.onclick=function(){createVideoFrame()};
	
	window['nbcLMP4428'].thumbnailContainer.appendChild(window['nbcLMP4428'].playButton);
	window['nbcLMP4428'].useThisAsParent.appendChild(window['nbcLMP4428'].thumbnailContainer);
	window['nbcLMP4428'].noteTheDOMPos = window['nbcLMP4428'].useThisAsParent.lastChild;
	
	
	// DOM element creation - IFRAME
	
	
	function createVideoFrame () {
	window['nbcLMP4428'].useThisAsParent.removeChild(window['nbcLMP4428'].noteTheDOMPos);
	
	window['nbcLMP4428'].videoframe = document.createElement('iframe');
	window['nbcLMP4428'].videoframe.style.border = 'none';
	window['nbcLMP4428'].videoframe.width = 300;
	window['nbcLMP4428'].videoframe.height = 169;
	window['nbcLMP4428'].videoframe.scrolling = "no";
	window['nbcLMP4428'].videoframe.src = "http://www.nbcdfw.com/templates/nbc_partner_player?cmsID=332322662&videoID=RWHl7dnXCx87&autoplay=true&origin=nbcdfw.com&sec=news&subsec=weather&width=300&height=169&rand=4428&turl="+window['nbcLMP4428'].encodedURI + "&ourl=" + window['nbcLMP4428'].encodedHost + "&lp=1";
	
	window['nbcLMP4428'].useThisAsParent.appendChild(window['nbcLMP4428'].videoframe);
	}
	
})();


