//$Header: /home/cvs/projects/cdn/cdnlite/ajax_dynamic/common2/Attic/cdm-detect.js,v 1.1.2.2 2006/11/28 14:50:56 toms Exp $

//This is the (only) file that you should need to edit in order to change
//how links to videos and slides/thumbnails are handled
//
//This is also the right place to set a logUrl if you want to use one


//uncomment this line to set a logUrl which will be used to record when
//the user plays a video
//  var logUrl = '../../log.aspx';

//default initial value - do not edit
var cdmEnvironment = 5;

function mungeHttpLink(url)
{
	//this is intended to work with a cdn httplinkstring of simply %realdocumentpath%
	
	var oldurl = url;

	if(redirected){
		url = rootUrl + 'redir.aspx/' + redirPort + '/' + url.replace('%26', '@@@A').replace('%25', '@@@P');
	} else {
		url = rootUrl + url;
	}

    return url;
}

function discoverRedirectionEnvironment()
{
	//called from init()

	//defaults for all optional variables (from custom.js)
	if(!window.skinName){
		alert("skinName must be set in custom.js");
		return;
	}
	if(!window.linkSkin){
		window.linkSkin = window.skinName;
	}
	
	var path = unescape(location.pathname);

	window.rootUrl = path.substring(0, path.indexOf(window.skinName));
	if(rootUrl.indexOf('local/') != -1){
		rootUrl = rootUrl.substring(0, rootUrl.indexOf('local/'));
	}
	window.redirected = window.rootUrl != '/';

	if(window.useAdminToc)
	{
        if(redirected){
			//admin interface is not supposed to be seen through redirection
			alert('The admin interface can only be viewed locally');
			window.tocUrl = 'INVALID'
		} else {
			window.tocUrl = rootUrl + '_1.2/toc-admin.xml';
		}
	} else {
		if(redirected){
			window.tocUrl = rootUrl + 'toc3.aspx?port=' + redirPort;
		} else {
			window.tocUrl = rootUrl + 'toc3.xml';
		}
	}
    
	if(redirected){
		window.liveUrl = rootUrl + 'liveStatus.aspx?port=' + redirPort;
	} else{
		window.liveUrl = rootUrl + '_1.2/liveslides/';
	}

	debug(tocUrl);

	//try to load a test image to see whether we can access a CDM v5
	var testImg = new Image(1,1);
	testImg.onerror = function() {debug('CDM v5 not found: moving over to CDM v4'); cdmEnvironment = 4;}
	testImg.onload = function() {debug('CDM v5 found: will use for video urls'); cdmEnvironment = 5;}
	testImg.onabort = function() {debug('CDM v5 not found: moving over to CDM v4'); cdmEnvironment = 4;}
    //testImg.src='http://10.92.48.143/CTV/MediaLibrary/Corporate/thumbnail.jpg';	  
	testImg.src='http://file.corporate.intranet.local/CTV/v5check.gif';
}

///////////////////////////////////////////////////////////////////////////////
// Edit this function to change the urls used for videos
///////////////////////////////////////////////////////////////////////////////
function setVideoMMSLinks(vid)
{
	var oldurl = vid.url;

	//take off local/content
    var url = vid.directMMSLink.replace(/(\/)?local\/content\//, '/'); 

	var v4ciscourl = 'http://10.88.143.1/Cisco/00b0d0fc656b/MediaLibrary';
	vid.vFourUrl = v4ciscourl + url.replace(/%20/g, '_');
	vid.vFourUrl = vid.vFourUrl.replace(/wmv$/, 'wmvx');
    
	var v5ciscourl = 'http://file.corporate.intranet.local/CTV/MediaLibrary';
	vid.vFiveUrl = v5ciscourl + url.replace(/%20/g, ' ');	
}


