// Right Video Player JavaScript Document
var theSponsor
function addScriptTag(id, url, callback) {
	var scriptTag = document.createElement("script");
	var noCacheIE = '&noCacheIE=' + (new Date()).getTime(); 
	var head = document.getElementsByTagName("head").item(0);  
	   // Add script object attributes
	   scriptTag.setAttribute("type", "text/javascript");
	   scriptTag.setAttribute("charset", "utf-8");
	   scriptTag.setAttribute("src", url + "&callback=" + callback + noCacheIE);
	   scriptTag.setAttribute("id", id);	
	head.appendChild(scriptTag);	
}
function getRelatedVideos(vidID) {
	addScriptTag("relatedVideos", "http://api.brightcove.com/services/library?command=find_related_videos&fields=name,id,thumbnailURL,linkURL,linkText,shortDescription&video_id="+vidID+"&page_size=4&token=LNhEv4aIEct6RtuKAJFXk6wzm9j5gd-9yyyPc6Iug9w.", "response");
	
	addScriptTag("videoInfo", "http://api.brightcove.com/services/library?command=find_videos_by_ids&fields=name,playsTotal,id,thumbnailURL,shortDescription,linkURL,linkText,tags,referenceId,customFields&video_ids="+vidID+"&token=LNhEv4aIEct6RtuKAJFXk6wzm9j5gd-9yyyPc6Iug9w.", "response2");
}


function response(jsonData) {
	// display the results
	var resp = document.getElementById("resp");
	resp.innerHTML = "";
var artStr =""	
var str = " <span class=\"section\">Related Videos</span><table cellpadding=\"2\" cellspacing=\"0\"><tr>";
	for (var i=0; i<jsonData["items"].length; i++) {
		var title = jsonData["items"][i];		
		str += "<td class=\"relatedVid\" >"
		str += "<a href='javascript:inplayVid("+ title.id +")'><img src='"+ title.thumbnailURL +"'  /></a>"
		str += "<p class=\"smallName\">" +title.name; +"</p></td>"	
			}

	str += "</tr></table>"
	resp.innerHTML += str;
}	
function response2(jsonData) {
	var videoInfo = document.getElementById("vidInfo");
	videoInfo.innerHTML = "";
	var strInfo =""
	for (var j=0; j<jsonData["items"].length; j++) {
	var title2 = jsonData["items"][j];		
		
		strInfo +="<h1>"+title2.name;
		strInfo +="</h1>"+title2.shortDescription;
		if (title2.linkURL != null) {	
	strInfo +="<br/><strong>Related Story: </strong> <a href=\""+title2.linkURL;
	strInfo +="\">"+title2.linkText+"</a>";
	}		
strInfo +="<br/><strong>Perma-Link:</strong> <a href=\"http://www.itbusiness.ca/video.asp?vid="+title2.id;
strInfo +=" \" > http://www.itbusiness.ca/video.asp?vid="+title2.id+"</a><br/>";
strInfo +="<a href=\"http://twitter.com/home/?status=http://www.itbusiness.ca/video.asp?vid="+title2.id+"\">  <img src=\"http://www.itworldcanada.com/arca/img_new/bTwitter.gif\" alt=\"Follow this article on Twitter\" title=\"Tweet This Article\">      </a>  <a href=\"http://delicious.com/save?url=http://www.itbusiness.ca/video.asp?vid="+title2.id+"\" ><img src=\"http://www.itworldcanada.com/arca/img_new/bDelicious.gif\" alt=\"del.ico.us bookmark\" title=\"Add as a Delicious Bookmark\">   </a><a href=\"http://digg.com/submit?phase=2&amp;amp;url=http://www.itbusiness.ca/video.asp?vid="+title2.id+"\"><img src=\"http://www.itworldcanada.com/arca/img_new/bDigg.gif\" alt=\"Digg this!\" title=\"Add to Digg\">  </a>        <a href=\"http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http://www.itbusiness.ca/video.asp?vid="+title2.id+"\">   <img src=\"http://www.itworldcanada.com/arca/img_new/bGoogle.gif\" alt=\"Google Bookmark\" title=\"Add to Google bookmarks\"> </a>  <a href=\"http://technorati.com/faves?add=http://www.itbusiness.ca/video.asp?vid="+title2.id+"\">  <img src=\"http://www.itworldcanada.com/arca/img_new/bTechnorati.gif\" alt=\"Technorati\" title=\"Add to Technorati\"></a> <a href=\"http://www.facebook.com/share.php?u=http://www.itbusiness.ca/video.asp?vid="+title2.id+"\" >  <img src=\"http://www.itworldcanada.com/arca/img_new/bFacebook.gif\" alt=\"Facebook\" title=\"Add to Facebook\">     </a>    <a href=\"http://myweb2.search.yahoo.com/myresults/bookmarklet?t=&amp;u=http://www.itbusiness.ca/video.asp?vid="+title2.id+"\">        <img src=\"http://www.itworldcanada.com/arca/img_new/bYahoo.gif\" alt=\"Yahoo!\" title=\"Add to Yahoo!\">        </a> <a href=\"http://slashdot.org/slashdot-it.pl?op=basic&amp;url=http://www.itbusiness.ca/video.asp?vid="+title2.id+"\" >    <img src=\"http://www.itworldcanada.com/arca/img_new/bSlashdot.gif\" alt=\"Slashdot\" title=\"Add to Slashdot\">        </a>        <a  href=\"http://www.stumbleupon.com/submit?url=http://www.itbusiness.ca/video.asp?vid="+title2.id+"\"> <img src=\"http://www.itworldcanada.com/arca/img_new/bStumbleupon.gif\" alt=\"StumbleUpon\" title=\"Add to StumbleUpon\"></a>";
if (title2.customFields != null && title2.customFields.sponsor != null ) {	
    theSponsor = title2.customFields.sponsor;
	fireCompanion(theSponsor); 
}
else
{	
	theSponsor = "itbusiness/video";
    fireCompanion(theSponsor); 
}			
videoInfo.innerHTML += strInfo;
	}
}

function getVideoBox ( ) {
toggleLayer('greyOut');
toggleLayer('videoWrap');
}
//toggle layer visibility
function toggleLayer( whichLayer )
{
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichLayer );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichLayer];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}
function closeVid(){
	getVideoBox();
var entireBox = document.getElementById('outerVid');
entireBox.innerHTML='<div id="greyOut"><div id="videoWrap"><a href="javascript:closeVid()" class="close">Close X</a><div id="companion"></div><div id="Video"></div> <div class="clear"></div><div id="resp"></div><div id="vidInfo"></div></div></div>';}

function playVid (id) {
var vidBox = document.getElementById('Video');
vidBox.innerHTML='<object id="flashObj" width="600" height="350" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,47,0"><param name="movie" value="http://c.brightcove.com/services/viewer/federated_f9/82645592001?isVid=1&isUI=1" /><param name="bgcolor" value="#FFFFFF" /><param name="flashVars" value="@videoPlayer='+id+'&playerID=82645592001&domain=embed&dynamicStreaming=true&autoStart=true" /><param name="base" value="http://admin.brightcove.com" /><param name="seamlesstabbing" value="false" /><param name="videoSmoothing" value="true" /><param name="allowFullScreen" value="true" /><param name="swLiveConnect" value="true" /><param name="allowScriptAccess" value="always" /><embed src="http://c.brightcove.com/services/viewer/federated_f9/82645592001?isVid=1&isUI=1" bgcolor="#FFFFFF" flashVars="@videoPlayer='+id+'&playerID=82645592001&&domain=embed&dynamicStreaming=true&autoStart=true" base="http://admin.brightcove.com" name="flashObj" width="600" height="350" seamlesstabbing="false" type="application/x-shockwave-flash" allowFullScreen="true" videoSmoothing="true" allowScriptAccess="always" swLiveConnect="true" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></embed></object>';
getVideoBox();
getRelatedVideos(id);
}


function inplayVid (id) {
var vidBox = document.getElementById('Video');
vidBox.innerHTML='<object id="flashObj" width="600" height="350" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,47,0"><param name="movie" value="http://c.brightcove.com/services/viewer/federated_f9/82645592001?isVid=1&isUI=1" /><param name="bgcolor" value="#FFFFFF" /><param name="flashVars" value="@videoPlayer='+id+'&playerID=82645592001&domain=embed&dynamicStreaming=true&autoStart=true" /><param name="base" value="http://admin.brightcove.com" /><param name="seamlesstabbing" value="false" /><param name="allowFullScreen" value="true" /><param name="swLiveConnect" value="true" /><param name="allowScriptAccess" value="always" /><embed src="http://c.brightcove.com/services/viewer/federated_f9/82645592001?isVid=1&isUI=1" bgcolor="#FFFFFF" flashVars="@videoPlayer='+id+'&playerID=82645592001&&domain=embed&dynamicStreaming=true&autoStart=true" base="http://admin.brightcove.com" name="flashObj" width="600" height="350" seamlesstabbing="false" type="application/x-shockwave-flash" allowFullScreen="true" allowScriptAccess="always" swLiveConnect="true" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></embed></object>';
getRelatedVideos(id);
}


function fireCompanion(spons) {

function generateiFrame(iFrameid,srcTitle,srcWidth,srcHeight,srcPos,srcOdr,sponsor)
{  
        return "<iframe id=\""+iFrameid+"\" src=\"http://ad.ca.doubleclick.net/adi/idg.ca."+sponsor+";tile="+srcTitle+";pos="+srcPos+";sz="+srcWidth+"x"+srcHeight+";ord="+srcOdr+"?\" width=\""+srcWidth+"\" height=\""+srcHeight+"\" marginwidth=\"0\" marginheight=\"0\" hspace=\"0\" vspace=\"0\" frameborder=\"0\" scrolling=\"no\" borderCOLOR=\"#000000\"></iframe>"; 
}
 var getbigbox1=document.getElementById('companion');
 getbigbox1.innerHTML="";	
 var ord=Math.floor(Math.random()*9999999);
getbigbox1.innerHTML=generateiFrame("bigboxiframe1","8","300","250","bigboxros",ord,spons)
}
