//******************************************************************************
//These 2 functions are used for diff page list widget implementation
//Function names MUST stay the same or else embed code changes must be made in SB CMS
function get_url_param(name)
{
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regexS = "[\\?&]"+name+"=([^&#]*)";
    var regex = new RegExp( regexS );
    var results = regex.exec( window.location.href );
    if( results == null )
    return "sb_error_code";
    else
    return results[1];
}

function sb_play_video()
{
    if(get_url_param('sb_video_id')!= 'sb_error_code' && get_url_param('sb_partner_id')!= 'sb_error_code') {
    sbvideoid = get_url_param('sb_video_id');
    sbpartnerid = get_url_param('sb_partner_id');
    getVideoContent(sbvideoid, sbpartnerid);
    } else {
    //alert('error');
    }
}

function runHtml5Fallback(sbElementId, additionaAttributes, jsonFeed)
{
	sbhtml.createSpringboards(sbElementId, additionaAttributes, jsonFeed);
}

if(sbhtml==undefined)
{
	var sbhtml = {};
}
if(externalCounter==undefined)
{
    var externalCounter = 0;
}
if (sbhtml.springboards == undefined)
{
	sbhtml.videoObj = null;                                                     //main video object
	sbhtml.autoStart = 0;                                                       //autoplay setting
	sbhtml.paramNameArray= new Array('flashvars','movie');                      //chek if old or new embed code is to be parsed
	sbhtml.currentItem = 0;                                                     //current item
	sbhtml.springboards = {};                                                   //springboards object
	sbhtml.springboardVideoObjects={};                                          //springboard video object
	sbhtml.externalCounter = 0;                                                 //number of objects counter
	sbhtml.analyticsPostUrl = 'http://analytics.stg.springboardvideo.com/index.php';        //analytics url
	sbhtml.sbElementId = null;                                                  //object code id
	sbhtml.debug = true;                                                        //debug mode true/false
	sbhtml.uagent = navigator.userAgent.toLowerCase();                          //user agent
	sbhtml.detectMobileArray = ['iphone', 'ipad', 'ipod', 'android', 'blackberry'];     //array of mobile supported devices
	sbhtml.cookieValue = 'sbanalytics';                                         //value of cookie
	sbhtml.check = false;                                                       //used for list widgets on search not to refresh first video
	sbhtml.jsonFeed = null;                                                     //json feed/direct url
	sbhtml.allowedExternalConfigAttributes = ['continuousPlay'];                //continuous play add. param that list widgets send
	sbhtml.teaserId = null;                                                     //list widget id
	
		
	sbhtml.createSpringboards=function(sbElementId, additionaAttributes, jsonFeed)
	{
		if (sbhtml.detectSmartphone())
		{
			sbhtml.check = true;
			//List widget sent his own jsonFeed
			if(jsonFeed!=null)
			{	
				sbhtml.jsonFeed = jsonFeed;
			}
            if (sbElementId!=undefined)
            {
                if (sbElementId.indexOf("teaserWidget")  != -1)
                {
                    sbhtml.teaserId = sbElementId;
                }
            }
			if(sbhtml.debug)
			{ 
				console.log('Passed id is: '+sbElementId);
			}
			var htmlEmbedObjects = [];
			
			if (sbElementId != null)
			{
				if(sbhtml.debug) console.log('Only one html5 on id: '+sbElementId);
				sbhtml.sbElementId = sbElementId;
				htmlEmbedObjects.push(document.getElementById(sbElementId));
			}
			else
			{
				//Fill with all SB flash objects
				if(sbhtml.debug) console.log('Array of html5 embeds');
				htmlEmbedObjects = sbhtml.collectSbObjects();
			}
			var numObjects = htmlEmbedObjects.length;
			console.log('Number of video objects is '+numObjects);
			for (var counter = 0; counter < numObjects; counter++)
			{
				vidObject = htmlEmbedObjects[counter];
				vidObject.playlist = {};
				vidObject.playlist.currentItem = 0;
				if(sbhtml.springboards[sbhtml.teaserId]!=null)
				{
					vidObject.currentItem = sbhtml.springboards[sbhtml.teaserId].currentItem;
				}
				else
				{
					vidObject.currentItem = externalCounter;
				}
				console.log('Video current item'+vidObject.currentItem);
				if(additionaAttributes !=null && additionaAttributes[vidObject.playlist.currentItem]!=null)
				{
					vidObject.additionaAttributes = additionaAttributes[vidObject.playlist.currentItem];
				}
				if(sbhtml.debug)
				{
					console.log('Going for:'+vidObject.id+', with the counter:'+counter);
				}
				vidObject = sbhtml.getValuesForVidObject(vidObject);
				
				sbhtml.runHtml5(vidObject);
				
				if(sbhtml.debug)
				{
					console.log('Finishing:'+vidObject.id+', with the counter:'+counter);
				}
					externalCounter++;
			}
		}
		else
			return;
	}
		
	sbhtml.collectSbObjects=function()
	{
		var flashObjects = [];
		var allObjects = document.getElementsByTagName('object');
		for (var i = 0; i < allObjects.length; i++)
		{
			if (/\bSpringboardSwitcher\b/.test(allObjects[i].className))
			{
				flashObjects.push(allObjects[i]);
			}
		}
		return flashObjects;

	}
	
	sbhtml.getValuesForVidObject=function(vidObj)
	{
		//these are the children nodes of the given object in the DOM
		var childrenNodes = vidObj.childNodes;
		var tagName;
		var returnValue = null;
		if (!vidObj.params) vidObj.params = {};
		if (!vidObj.flashVars) vidObj.flashVars = {};
		//loop through all children of the video object, searching for <param> tags.
		for (var i = 0; i < childrenNodes.length; i++)
		{
			if (childrenNodes[i].nodeType != 1)
			{
				continue;
			}
			tagName = childrenNodes[i].tagName.toLowerCase();
			if (tagName == "param")
			{
				//PARAM VALUES
				vidObj.params[childrenNodes[i].name] = childrenNodes[i].value;
				
				//FLAHS VARS
				//We need the id of the widget in use for analytics purposes
				if(childrenNodes[i].name=='movie' || childrenNodes[i].name=='flashvars')
				{
					var fv = childrenNodes[i].value.split("&");
					var fvl = fv.length;
				
					for(j=0;j<fvl;j++)
					{
						if (fv[j].indexOf("pid=")  != -1)
						{
							var wId = fv[j].split("?");
							vidObj.flashVars['widgetId'] = wId[1]!=undefined ? wId[1].substring(4) : fv[j].substring(4);
						}
						//extract file url variable (can be either a playlist or a single file)
						if (fv[j].indexOf("file=")  != -1)
						{
							vidObj.flashVars['jsonUrl'] = fv[j].substring(5);
							if (fv[j].indexOf("xml_feeds_advanced") != -1)
							{                
								vidObj.flashVars['jsonUrl'] = fv[j].substring(5).replace("index","html52");
							}
						}
						//Catch snapshot param value if it exists
						if (fv[j].indexOf("snapshot=") != -1)
						{
							vidObj.flashVars['snapshot'] = fv[j].substring(9);
						}
						//Catch autostart value
						if (fv[j].indexOf("autostart=")  != -1)
						{
							vidObj.flashVars['autoStart'] = fv[j].substring(10);
						}
					}
				}
			}
		}
		return vidObj;
	}
	
	sbhtml.ajaxRequest=function()
	{
		var activexModes=["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"] //activeX versions to check for in IE
		if (window.ActiveXObject)
		{ //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
			for (var i=0; i<activexModes.length; i++)
			{
				try
				{
					return new ActiveXObject(activexModes[i])
				}
				catch(e)
				{
					//suppress error
				}
			}
		}
		else if (window.XMLHttpRequest) // if Mozilla, Safari etc
			return new XMLHttpRequest()
		else
			return false
	}
	
	sbhtml.runHtml5=function(vidObject)
	{
        var thisExt = vidObject.flashVars['jsonUrl'].substr(vidObject.flashVars['jsonUrl'].lastIndexOf('.'));
        if (thisExt.toLowerCase() == ".mp4" || thisExt.toLowerCase() == ".flv")
        {
            //here we parse sbhtml.Id to get the site id used for analytics call when a user puts a direct url to our player
            var splitForSiteId = vidObject.id.split("_");
            //Set site id
            vidObject.siteId = splitForSiteId[3];
        }
		 
		//create videoTag - html <video> tag
		var videoTag = sbhtml.formVideoTagFromInfo(vidObject);
			
		vidObject.videoElement = videoTag;
		//Continuous play and such
		vidObject.videoElement.additionaConfigValues = {};
		//Override values
		sbhtml.overrideValuesFunction(vidObject);
		//vidObject is video object <embed> contains flashVars, params
		sbhtml.springboardVideoObjects[vidObject.currentItem] = vidObject;
		
		//List widget search solution
		sbhtml.springboards[vidObject.id] = vidObject;
		//Replace <embed> with <video>
		vidObject.parentNode.replaceChild(videoTag, vidObject);
		
		if (thisExt.toLowerCase() == ".mp4" || thisExt.toLowerCase() == ".flv" || (sbhtml.overrideValues!=null && sbhtml.overrideValues[sbhtml.currentItem]!=null && sbhtml.overrideValues[sbhtml.currentItem]['src']!=null))
		{
			sbhtml.embedVideoForUrl(vidObject, vidObject.currentItem)
		}
		else
		{
			//If custom JSON is NOT sent
			if(sbhtml.jsonFeed==null)
			{
				sbhtml.addScriptTag(vidObject); //Make the API call, specifying the unique callback method for this request
			}
			else
			{	
				//Custom JSON Feed provided
				sbhtml.handleVideoResponse(sbhtml.jsonFeed,vidObject.currentItem, sbhtml.teaserId);
				//kill json feed value not to effect other players on page
				sbhtml.jsonFeed=null;
			}
		}	
	}
		
	sbhtml.embedVideoForUrl=function(JSONResponse,inArray)
	{
		console.log('CURRENT ITEM IS:'+inArray);
		if(JSONResponse!='')
		{
			var vidObj = sbhtml.springboardVideoObjects[inArray];

			//Create video info object, fill it with, volume, length, duration, title
			vidObj.videoElement.videoInfo = {};
			var thisExt = JSONResponse.flashVars['jsonUrl'].substr(JSONResponse.flashVars['jsonUrl'].lastIndexOf('.'));
			if (thisExt.toLowerCase() == ".mp4")
			{
				sbhtml.attachAnalyticsEvents(vidObj);
			}
			
			// Refresh <video> data from json
			sbhtml.refreshVideoData(vidObj);			
		}
	}
		
	sbhtml.addScriptTag=function(vidObject)
	{
		var url = vidObject.flashVars['jsonUrl']+"handleVideoResponse/vid_"+vidObject.id+"/"+vidObject.id+"/"+vidObject.width+"/"+vidObject.height+"/"+vidObject.flashVars['autoStart']+"/"+vidObject.flashVars['widgetId']+"/"+vidObject.currentItem;
		var scriptTag = document.createElement("script");
		scriptTag.type = 'text/javascript';
		scriptTag.src = url;
		scriptTag.async = true;
		scriptTag.charset = 'utf-8';
		var head = document.getElementsByTagName("head").item(0);	
		head.appendChild(scriptTag);
	}
		
	sbhtml.handleVideoResponse=function(JSONResponse, inArray)
	{
		if(JSONResponse!='')
		{
			var vidObj = sbhtml.springboardVideoObjects[inArray];
			vidObj.jsonResponse = JSONResponse
			vidObj.playlist.playlistLength = vidObj.jsonResponse.length;
			
			//Create video info object, fill it with, volume, length, duration, title
			vidObj.videoElement.videoInfo = {};
				
			//Refresh <video> data from json
			sbhtml.refreshVideoData(vidObj);
			//Start analytics
			sbhtml.attachAnalyticsEvents(vidObj);
		}
	}

	//Refresh video data for the widget player by video Object id (e.g. sbp_sova014_pid_170_sova014_pl_483)
	sbhtml.refreshVideoDataWidget=function(videoId, currentItem)
	{
        sbhtml.listWidgetCheck = true;  //added a check so analytics knows to reset triggers when a new item is clicked
		for(videoObjectKey in sbhtml.springboardVideoObjects)
		{
			if(sbhtml.springboardVideoObjects[videoObjectKey].id==videoId)
			{
				sbhtml.refreshVideoData(sbhtml.springboardVideoObjects[videoObjectKey], currentItem);
                sbhtml.springboardVideoObjects[videoObjectKey].videoElement.load();
				break;
			}
		}
	}
	sbhtml.refreshVideoData=function(vidObject, currentItem)
	{
		if(vidObject!=null)
		{
			//Playlist in json format
			if (vidObject.jsonResponse!=null && vidObject.jsonResponse!='')
			{
				//If in multiple file playlist mode set autoplay to true (must have for cont. play to work)
				if(vidObject.jsonResponse.length > 1)
				{
					vidObject.videoElement.autoplay = true;
					
				}
				//Set manually current item
				vidObject.playlist.currentItem = (currentItem!=null) ? currentItem : vidObject.playlist.currentItem;
				
				vidObject.videoElement.title = vidObject.videoElement.videoInfo.videoTitle = vidObject.jsonResponse[vidObject.playlist.currentItem].Video.title;
				if (vidObject.flashVars['snapshot'] != undefined)
				{
					vidObject.videoElement.poster = vidObject.flashVars['snapshot'];
				}
				else if (vidObject.jsonResponse[vidObject.playlist.currentItem].Video.snapshot != null && vidObject.jsonResponse[vidObject.playlist.currentItem].Video.snapshot!='')
				{
					vidObject.videoElement.poster = vidObject.jsonResponse[vidObject.playlist.currentItem].Video.snapshot;
				}
				vidObject.videoElement.src = vidObject.jsonResponse[vidObject.playlist.currentItem].Video.url;	
				vidObject.videoElement.id = vidObject.id;
				vidObject.videoElement.videoInfo.partnerId = vidObject.jsonResponse[vidObject.playlist.currentItem].Video.site_id;
				vidObject.videoElement.videoInfo.videoId = vidObject.jsonResponse[vidObject.playlist.currentItem].Video.id;
			}
			//File
			else
			{
				if (vidObject.flashVars['snapshot'] != undefined)
				{
					vidObject.videoElement.poster = vidObject.flashVars['snapshot'];
				}
				vidObject.videoElement.src = vidObject.flashVars['jsonUrl'];
				vidObject.videoElement.title = vidObject.videoElement.videoInfo.videoTitle = "-- No-META-Data --";
			}
		}
		if(vidObject.videoElement.overrideValues!=null && vidObject.videoElement.overrideValues[vidObject.playlist.currentItem]!=null)
		{
			for (var propertyName in vidObject.videoElement.overrideValues[vidObject.playlist.currentItem])
			{
				vidObject.videoElement.setAttribute(propertyName, vidObject.videoElement.overrideValues[vidObject.playlist.currentItem][propertyName]);
			}
		}
	}
	
	sbhtml.overrideValuesFunction=function(vidObject)
	{
		if(sbhtml.debug) {
			console.log('OVERRIDE');
		}
		//If additional attributes are set, override existing ones and apply additional att
		if(vidObject.additionaAttributes!=null && typeof vidObject.additionaAttributes === 'object')
		{
			vidObject.videoElement.overrideValues =[];
			vidObject.videoElement.overrideValues[vidObject.playlist.currentItem] = [];
			for(var onePropertyInObject in vidObject.additionaAttributes)
			{
				if(vidObject.additionaAttributes.hasOwnProperty(onePropertyInObject))
				{
					//Special external config attributes (e.g continuousPlay)
					if(sbhtml.allowedExternalConfigAttributes.indexOf(onePropertyInObject)!=-1)
					{
						vidObject.videoElement.additionaConfigValues[onePropertyInObject] = vidObject.additionaAttributes[onePropertyInObject];
					}
					vidObject.videoElement.overrideValues[vidObject.playlist.currentItem][onePropertyInObject] = vidObject.additionaAttributes[onePropertyInObject];
				}
			}
		}
	}
	
	sbhtml.attachAnalyticsEvents=function(vidObject)
	{
		var started = false; //needed as triggers so if a user scrubs back it doesnt send a new request.
		var done_25 = false;
		var done_50 = false;
		var done_75 = false;
		var done = false;
	
		vidObject.videoElement.addEventListener('play', function startPlay() 
		{
            //If source is flv do not start analytics
            var thisExt = vidObject.videoElement.src.substr(vidObject.videoElement.src.lastIndexOf('.'));
            if (thisExt.toLowerCase() == ".flv")
            {
                return;
            }
			// This part is in case play is pressed when a flv file is passed to the html5 player
			vidObject.videoElement.videoInfo.videoLength = String(this.duration) == "NaN" ? 0 : this.duration.toFixed();
			
			if (started == false || sbhtml.listWidgetCheck == true)
			{
				vidObject.videoElement.videoInfo.volume = (this.volume*100).toFixed();
				vidObject.videoElement.videoInfo.timePlayed = 0;
				vidObject.videoElement.videoInfo.videoAction = "VP_START";
				sbhtml.populateAnalyticsRequest(vidObject);
                sbhtml.listWidgetCheck = false;
				started = true;
                done_25 = false;
                done_50 = false;
                done_75 = false;
                done = false;
			}
		}, false);
			
		vidObject.videoElement.addEventListener('timeupdate', function playing() 
		{
			var quarter = (this.duration/4).toFixed();
			if (this.currentTime.toFixed() == quarter && done_25 == false) 
			{
				vidObject.videoElement.videoInfo.volume = (this.volume*100).toFixed();
				vidObject.videoElement.videoInfo.timePlayed = this.currentTime.toFixed();
				vidObject.videoElement.videoInfo.videoAction = "VP_25";
				sbhtml.populateAnalyticsRequest(vidObject);
                sbhtml.listWidgetCheck = false;
				done_25 = true;
			}
			if (this.currentTime.toFixed() == quarter*2 && done_50 == false)
			{
				vidObject.videoElement.videoInfo.volume = (this.volume*100).toFixed();
				vidObject.videoElement.videoInfo.timePlayed = this.currentTime.toFixed();
				vidObject.videoElement.videoInfo.videoAction = "VP_50";
				sbhtml.populateAnalyticsRequest(vidObject);
				done_50 = true;
			}
			if (this.currentTime.toFixed() == quarter*3 && done_75 == false)
			{
				vidObject.videoElement.videoInfo.volume = (this.volume*100).toFixed();
				vidObject.videoElement.videoInfo.timePlayed = this.currentTime.toFixed();
				vidObject.videoElement.videoInfo.videoAction = "VP_75";
				sbhtml.populateAnalyticsRequest(vidObject);
				done_75 = true;
			}
		}, false);
		 
		vidObject.videoElement.addEventListener('ended', function end()
		{
			if (done == false)
			{
				vidObject.videoElement.videoInfo.volume = (this.volume*100).toFixed();
				vidObject.videoElement.videoInfo.timePlayed = this.duration.toFixed();
				vidObject.videoElement.videoInfo.videoAction = "VP_END";
				sbhtml.populateAnalyticsRequest(vidObject);
				done = true;
			}
			//If direct url situation get out
			if (vidObject.jsonResponse == undefined)
			{
				return;
			}
			if ((vidObject!=null && vidObject.jsonResponse!='') && (vidObject.playlist.currentItem < vidObject.jsonResponse.length-1 ))
			{
				started = false; 
				done_25 = false;
				done_50 = false;
				done_75 = false;
				done = false;
				//By default continious play is ON, so if it is not set to 0 or it is not set at all, make it continuous
				if(vidObject.videoElement.additionaConfigValues['continuousPlay']==null || vidObject.videoElement.additionaConfigValues['continuousPlay']==1)
				{
					vidObject.playlist.currentItem++;
					sbhtml.refreshVideoData(vidObject);
					this.load();
				}
			}
		}, false);
	}
	
	sbhtml.populateAnalyticsRequest=function(vidObject)
	{
		var analyticsPost = new sbhtml.ajaxRequest();
		var host = window.location.protocol + "//" + window.location.host;
		var videoInfo = vidObject.videoElement.videoInfo;
		var sendArray = [];
		sendArray['sbct'] = sbhtml.time();
		sendArray['sbvol'] = videoInfo.volume;
		sendArray['sbva'] = videoInfo.videoAction;
		sendArray['sbvt'] = escape(videoInfo.videoTitle);
		sendArray['sbhn'] = host;
		sendArray['sbtp'] = videoInfo.timePlayed;
		sendArray['sbvlen'] = videoInfo.videoLength;
		sendArray['sbuv'] = sbhtml.getUnique(vidObject);
		sendArray['sbpid'] = ((videoInfo.partnerId==undefined) ? vidObject.siteId : videoInfo.partnerId);
		sendArray['sbvid'] = ((videoInfo.videoId==undefined) ? 0 : videoInfo.videoId);
		sendArray['sbpl'] = vidObject.flashVars['widgetId'];
		sendArray['sbaty'] = 'c';
		sendArray['sbmob'] = 1;
		var sA = [];
		for(var val in sendArray)
		{
			if(sbhtml.debug) console.log(val+"="+sendArray[val]);	
			sA.push(val+"="+sendArray[val]);
		}
		analyticsPost.open("GET", sbhtml.analyticsPostUrl+"?"+sA.join("&"), true);
		analyticsPost.setRequestHeader("Accept-Sb", "sb")
		analyticsPost.send(null);  
	}
		
	sbhtml.formVideoTagFromInfo=function(vidObj)
	{
		var videoTag = document.createElement("video");
		//Must have "==" sign
		if (vidObj.flashVars['autoStart'] == true)
		{
			videoTag.autoplay = true;
		}
		else
		{
			videoTag.autoplay = false;
		}
		videoTag.width = vidObj.width;
		videoTag.height = vidObj.height;
		videoTag.controls = true;  
		videoTag.setAttribute('counter',vidObj.currentItem);

		//if this device is an ANDROID device, then add an onclick handler to the
		//video since this does not exist by default.
		if (sbhtml.detectAndroid()){
				sbhtml.addClickHandlerToVid(videoTag);
		}
		return videoTag;
	}
		
	sbhtml.detectSmartphone=function()
	{
		var foundAgent = false;
		for(var i=0; i<sbhtml.detectMobileArray.length; i++)
		{
		if (sbhtml.uagent.search(sbhtml.detectMobileArray[i]) != -1)
		{
			foundAgent = true;
			break;
		}
		foundAgent = false;
		}
		if (foundAgent)
			return true;
		else
			return false;
	}
		
	sbhtml.detectAndroid=function()
	{
		if (sbhtml.uagent.search("android") > -1)
			return true;
		else
			return false;
	}
	
	sbhtml.addClickHandlerToVid=function(obj)
	{
		obj.addEventListener('click', function(videoNode)
		{
			return function()
			{
				videoNode.play();
			};
		}(obj));
	}
		
	sbhtml.sbRemoveListeners=function()
	{
		if(sbhtml.debug) console.log('Removing listeners');
		document.removeEventListener('load', sbhtml.createSpringboards, false);
		if (typeof document.addEventListener != 'undefined')
		{
			document.removeEventListener('DOMContentLoaded', sbhtml.createSpringboard, false);
			document.removeEventListener('load', sbhtml.createSpringboards, false);
		}
		else if (typeof window.attachEvent != 'undefined')
		{
			window.detachEvent('onload', sbhtml.createSpringboards);
		}
	}
	
	sbhtml.time=function()
	{
		var currentTime = new Date()
		var time = currentTime.getTime() // sbct
		return time;
	}
	
	sbhtml.getUnique=function(vidObject)
	{
		if (sbhtml.readCookie(vidObject))
		{
		   return 0;
		}
		else
		{
			sbhtml.setCookie(vidObject);
			//We are doing a read cookie here in case the user has cookies disabled so we dont send multiple unique views "1"
			if (sbhtml.readCookie(vidObject))
			{
				return 1;
			}
			else
			{
				return 0;
			}
		}
	},
	
	sbhtml.setCookie=function(vidObject)
	{
        if (vidObject.videoElement.videoInfo.partnerId == undefined)
        {
            sbhtml.cookieName = "sbvideo_"+vidObject.siteId;
        }
        else
        {
            sbhtml.cookieName = "sbvideo_"+vidObject.videoElement.videoInfo.partnerId;
        }
		var today = new Date();
		var expire = new Date();
		expire.setTime(today.getTime() + 3600000*24);
		document.cookie = sbhtml.cookieName+"="+escape(sbhtml.cookieValue) + ";expires="+expire.toGMTString();
	}
	
	sbhtml.readCookie=function(vidObject)
	{
		if (vidObject.videoElement.videoInfo.partnerId == undefined)
        {
            sbhtml.cookieName = "sbvideo_"+vidObject.siteId;
        }
        else
        {
            sbhtml.cookieName = "sbvideo_"+vidObject.videoElement.videoInfo.partnerId;
        }
		var re = new RegExp('[; ]'+sbhtml.cookieName+'=([^\\s;]*)');
		var sMatch = (' '+document.cookie).match(re);
		if (sbhtml.cookieName && sMatch) return unescape(sMatch[1]);
		return '';
	}
	
	sbhtml.buildSbPlayersIntoHtml5AfterPageLoad=function()
	{
		if(sbhtml.sbElementId == null)
		{
			if(sbhtml.debug) console.log('Entering automatic conversion of all players (buildSbPlayersIntoHtml5AfterPageLoad) to HTML5 :'+sbhtml.sbElementId);
			sbhtml.sbRemoveListeners();
			sbhtml.createSpringboards();
		}
	}

	if (typeof document.addEventListener != 'undefined')
	{
		console.log('Entering add event listeners');
		document.addEventListener('load', sbhtml.buildSbPlayersIntoHtml5AfterPageLoad, false);
		document.addEventListener('DOMContentLoaded', sbhtml.buildSbPlayersIntoHtml5AfterPageLoad, false);
	}
	else if (typeof window.attachEvent != 'undefined')
	{
		window.attachEvent('onload', sbhtml.buildSbPlayersIntoHtml5AfterPageLoad);
	}
}
