if (typeof (av_sRootFolder) == "undefined") var av_sRootFolder = "http://publique.radio-canada.ca/audio-video/";
if (typeof (av_sPageRootFolder) == "undefined") var av_sPageRootFolder = "http://www.radio-canada.ca/audio-video/";
//var av_sRootFolder = "http://localhost/audio-video/";
var av_sVersion = "1.2";
var isLight = false;
var av_lang;
var av_sMainJs = av_sRootFolder + "main/2.0/classInstance.js";

var sLoadError = "Impossible de charger la console audio-vidéo de Radio-Canada.ca pour le moment. Réessayer plus tard. Merci";
var srcAV_aInstancesId = new Array();
var srcAV_aInstances = new Array();
//var av_isDev = (av_sRootFolder == "http://publique.radio-canada.dev/audio-video/");
var av_isDev = (av_sRootFolder == "http://publique.radio-canada.ca/audio-video/");

// tout les script sont loader
if (typeof (avSrc_isLoad) == "undefined") var avSrc_isLoad = false;
if (typeof (avSrc_isLoading) == "undefined") var avSrc_isLoading = false;
function srcAV_loadGlobal(_instId) {
    document.getElementById('srcAV_inst' + _instId + '_container').innerHTML = srcAv_getLoading(srcAV_aInstancesId[_instId]);
    if (typeof (isStaticGlobalJs) == "undefined") {
        var _script = document.createElement("script");
        _script.type = "text/javascript"; _script.language = "javascript"; _script.src = "http://static.src.ca/v3/js/global_1.5.0.js";
        if (typeof (aStaticGlobalJs) == "undefined") { aStaticGlobalJs = new Array(); } aStaticGlobalJs.push("srcAV_loadMain(" + _instId + ")");
        document.getElementsByTagName("HEAD")[0].appendChild(_script);
    } else { srcAV_loadMain(_instId); }
}
function srcAV_loadMain(_instId) {
    if (typeof (noNeedToLoadMain) != "undefined") { srcAV_loopLoad(_instId); return; }
    if (avSrc_isLoad || avSrc_isLoading) {
        srcAV_loopLoad(_instId);
    } else {
        avSrc_isLoading = true;
        var _aDiv = document.getElements('div[class=srcAv_container]');
        oSrc.crossDomainAjax(
				av_sRootFolder + "main/2.0/index.asp" + (av_isDev || true ? "?rnd=" + Math.random() : ''),
				{
				    onSucceed: "srcAV_loadMainCallBack",
				    onFailed: "srcAV_loadMainCallBackError",
				    oParam: { instId: _instId }
				}
			);
    }
}
function srcAV_loadMainCallBack(_s, _oParam) {
    if (avSrc_isLoad) return;
    avSrc_isLoad = true;

    if (typeof (_oParam) == "string") _oParam = JSON.decode(_oParam);
    if (typeof (_oParam.instId) != "undefined") {
        test("loadMainCallBack  -> " + _oParam.instId);
        srcAV_loopLoad(_oParam.instId);
    } else {
        oSrc.alert("cav-error","loadMainCallBack  ->  undefined");
    }

}
function srcAV_loadMainCallBackError(_s, _oParam) {
    var _aDiv = document.getElements('div[class=srcAv_container]');
    for (var i = 0; i < _aDiv.length; i++) {
        _aDiv[i].getChildren('div')[0].innerHTML = srcAv_getError();
    }
}
function srcAV_write(_oCavParam) {
    document.writeln(srcAV_startAV(_oCavParam));
}
function srcAV_get(_oCavParam) {
    return srcAV_startAV(_oCavParam);
}
function srcAV_startAV(_oCavParam) {
    srcAV_aInstancesId.push(_oCavParam);
    var _lastInstId = srcAV_aInstancesId.length - 1;
    if (typeof (srcAV_aInstancesId[_lastInstId].GUI) == "undefined") srcAV_aInstancesId[_lastInstId].GUI = "embedSrc";
    srcAV_aInstancesId[_lastInstId].isLightLoad = (
		typeof (_oCavParam.urlTeaser) != "undefined" && (typeof (_oCavParam.autoStart) != "undefined" && _oCavParam.autoStart == false && 	typeof (_oCavParam.isLight) && _oCavParam.isLight == true	)	);
    srcAV_aInstancesId[_lastInstId].switchAutoStart = srcAV_aInstancesId[_lastInstId].isLightLoad ? true : false;
    var _s = '';
	var _isMini=_oCavParam.GUI.toLowerCase().indexOf("mini") != -1;
    _s += '<div id="srcAV_inst' + _lastInstId + '_container" class="'+(_isMini?'embedSrcMini':'embedSrc')+'" style="' ;
	_s += 'width:' + (_isMini ? '240' : '480') + 'px;' ;
	_s += 'height:' + (_isMini ? '135' : '270') + 'px;' ;
	_s += '">';
    _s += (srcAV_aInstancesId[_lastInstId].isLightLoad) ? srcAV_getTeaserHtml(_lastInstId, _oCavParam) : srcAv_getLoading(_oCavParam);
    _s += '</div>';
    var _tmp = srcAV_aInstancesId[_lastInstId].isLightLoad ? '' : setTimeout("srcAV_loadGlobal(" + _lastInstId + ")", 200);
    return _s;
}
function srcAV_getTeaserHtml(_lastInstId, _oCavParam) {
    var _s = '<div style="background:url(' + _oCavParam.urlTeaser + ') no-repeat center center;">' ;
		_s +='<a href="#" style="' ;
		_s +='display:block;' ;
		_s +='position:relative;';
		_s +='width:' + (_oCavParam.GUI.toLowerCase().indexOf("mini") != -1 ? '240' : '480') + 'px;' ;
		_s +='height:' + (_oCavParam.GUI.toLowerCase().indexOf("mini") != -1 ? '135' : '270') + 'px;' ;
		_s +='background:' ;
		_s +='url(' + av_sRootFolder + 'GUI/_player/1.0/img/play.gif) no-repeat ' ;
		_s +=	(_oCavParam.GUI.toLowerCase().indexOf("mini") != -1 ? '180px' : '425px') + ' ' ;
		_s +=	(_oCavParam.GUI.toLowerCase().indexOf("mini") != -1 ? '95px' : '230px') + ';' ;
		_s +='" onclick="srcAV_loadGlobal(' + _lastInstId + ');return false;"></a>' ;
		_s +='</div>';
		return _s;
}
function srcAv_getLoading(_oCavParam) {
    var _s = '<div style="' ;
	_s += 'background:#3c3c3c url(http://publique.radio-canada.ca/audio-video/lib/img/ajax-loader.gif) no-repeat center center;' ;
	_s +='width:' + (_oCavParam.GUI.toLowerCase().indexOf("mini") != -1 ? 240 : 480) + 'px;' ;
	_s +='height:' + (_oCavParam.GUI.toLowerCase().indexOf("mini") != -1 ? 135 : 270) + 'px;' ;
	_s +='display:block;' ;
	_s +='"></div>';
	return _s;
}
function srcAv_getError() {
     var _s= '<div class="srcAV_error" style="background:red;width:100%;height:100%;display:block;">' ;
	 _s += 'Erreur de chargement de la console. Cliquez <a href="#" onclick="srcAV_loadMain();return false;">ici</a> pour réessayer.' ;
	 _s +=	'</div>';
	return _s;
}
function srcAV_next(_instId) {
    for (var i = _instId + 1; srcAV_aInstancesId.length; i++) {
        if (!srcAV_aInstancesId[i].isLoad) {
            document.write(srcAV_startAV(srcAV_aInstancesId[i]));
        }
    }
}
var timeoutRT = 0;
function srcAV_loopLoad(_instId) {
	//test(" -- srcAV_loopLoad(is_load="+avSrc_isLoad+")");
    if (!avSrc_isLoad) { setTimeout("srcAV_loopLoad(" + _instId + ")", 500); return; }

    if (srcAV_aInstancesId[_instId].switchAutoStart) srcAV_aInstancesId[_instId].autoStart = true;
    $('srcAV_inst' + _instId + '_container').style.width = "auto";
    $('srcAV_inst' + _instId + '_container').style.height = "auto";

    srcAV_initAV(_instId);
    return;
}
function srcAV_initAV(_instId) {
    srcAV_aInstances[_instId] = new srcAV_classInstance();
    srcAV_aInstances[_instId].init(_instId, srcAV_aInstancesId[_instId]);
}

// Wrapper
function srcAV_wrapper(_nInstId, _oParam) {
    if (typeof (_oParam) != 'undefined' && typeof (_oParam.urlMedia) != 'undefined') {
		for (var _s in _oParam){
			srcAV_aInstancesId[_nInstId][_s] = _oParam[_s];
		}
        //srcAV_aInstancesId[_nInstId].urlMedia = _oParam.urlMedia;
        srcAV_loadGlobal(_nInstId);
    }
}
function callFromObj(_nInstId, _sCallerId, _sEventType, _oParam) {
    if (!avSrc_isLoad) {
        for (var i = 0; i < srcAV_aInstancesId.length; i++) {
            if (typeof (srcAV_aInstancesId[i].idExt) != "undefined" && srcAV_aInstancesId[i].idExt == _nInstId) {
                srcAV_wrapper(i, _oParam);
                return;
            }
        }
        srcAV_wrapper((Number(_nInstId) && _nInstId < srcAV_aInstancesId.length) ? _nInstId : 0, _oParam);
    }
    else {
        for (var i = 0; i < srcAV_aInstances.length; i++) {
            if (srcAV_aInstances[i].idExt == _nInstId) {
                return callFromObjIntern(i, _sCallerId, _sEventType, _oParam);
            }
        }
        callFromObjIntern((Number(_nInstId) && _nInstId < srcAV_aInstances.length) ? _nInstId : 0, _sCallerId, _sEventType, _oParam);
    }
}

///////////////////////////////////////////////////////////////////////////////
//
//  Silverlight.js (2.0 Preview)	version 1.0   
//
//  This file is provided by Microsoft as a helper file for websites that
//  incorporate Silverlight Objects. This file is provided under the Silverlight 
//  SDK 1.1 license available at http://go.microsoft.com/fwlink/?linkid=94243.  
//  You may not use or distribute this file or the code in this file except as 
//  expressly permitted under that license.
// 
//  Copyright (c) 2007 Microsoft Corporation. All rights reserved.
//
///////////////////////////////////////////////////////////////////////////////



if (!window.Silverlight) {
    window.Silverlight = {};
}

// Silverlight control instance counter for memory mgt
Silverlight._silverlightCount = 0;
Silverlight.fwlinkRoot = 'http://go2.microsoft.com/fwlink/?LinkID=';
Silverlight.onGetSilverlight = null;
Silverlight.onSilverlightInstalled = function() { window.location.reload(false); };


Silverlight.isInstalled = function(version) {
    var isVersionSupported = false;
    var container = null;

    try {
        var control = null;

        try {
            control = new ActiveXObject('AgControl.AgControl');
            if (version == null) {
                isVersionSupported = true;
            }
            else if (control.IsVersionSupported(version)) {
                isVersionSupported = true;
            }
            control = null;
        }
        catch (e) {
            var plugin = navigator.plugins["Silverlight Plug-In"];
            if (plugin) {
                if (version === null) {
                    isVersionSupported = true;
                }
                else {
                    var actualVer = plugin.description;
                    if (actualVer === "1.0.30226.2")
                        actualVer = "2.0.30226.2";
                    var actualVerArray = actualVer.split(".");
                    while (actualVerArray.length > 3) {
                        actualVerArray.pop();
                    }
                    while (actualVerArray.length < 4) {
                        actualVerArray.push(0);
                    }
                    var reqVerArray = version.split(".");
                    while (reqVerArray.length > 4) {
                        reqVerArray.pop();
                    }

                    var requiredVersionPart,actualVersionPart, index = 0;


                    do {
                        requiredVersionPart = parseInt(reqVerArray[index]);
                        actualVersionPart = parseInt(actualVerArray[index]);
                        index++;
                    }
                    while (index < reqVerArray.length && requiredVersionPart === actualVersionPart);

                    if (requiredVersionPart <= actualVersionPart && !isNaN(requiredVersionPart)) {
                        isVersionSupported = true;
                    }
                }
            }
        }
    }
    catch (e) {
        isVersionSupported = false;
    }
    if (container) {
        document.body.removeChild(container);
    }

    return isVersionSupported;
}
Silverlight.WaitForInstallCompletion = function() {
    if (!Silverlight.isBrowserRestartRequired && Silverlight.onSilverlightInstalled) {
        try {
            navigator.plugins.refresh();
        }
        catch (e) {
        }
        if (Silverlight.isInstalled(null)) {
            Silverlight.onSilverlightInstalled();
        }
        else {
            setTimeout(Silverlight.WaitForInstallCompletion, 3000);
        }
    }
}
Silverlight.__startup = function() {
    Silverlight.isBrowserRestartRequired = Silverlight.isInstalled(null); 
    if (!Silverlight.isBrowserRestartRequired) {
        Silverlight.WaitForInstallCompletion();
    }
    if (window.removeEventListener) {
        window.removeEventListener('load', Silverlight.__startup, false);
    }
    else {
        window.detachEvent('onload', Silverlight.__startup);
    }
}

if (window.addEventListener) {
    window.addEventListener('load', Silverlight.__startup, false);
}
else {
    window.attachEvent('onload', Silverlight.__startup);
}



Silverlight.createObject = function(source, parentElement, id, properties, events, initParams, userContext) {
    var slPluginHelper = new Object();
    var slProperties = properties;
    var slEvents = events;

    slPluginHelper.version = slProperties.version;
    slProperties.source = source;
    slPluginHelper.alt = slProperties.alt;

    if (initParams)
        slProperties.initParams = initParams;
    if (slProperties.isWindowless && !slProperties.windowless)
        slProperties.windowless = slProperties.isWindowless;
    if (slProperties.framerate && !slProperties.maxFramerate)
        slProperties.maxFramerate = slProperties.framerate;
    if (id && !slProperties.id)
        slProperties.id = id;

    delete slProperties.ignoreBrowserVer;
    delete slProperties.inplaceInstallPrompt;
    delete slProperties.version;
    delete slProperties.isWindowless;
    delete slProperties.framerate;
    delete slProperties.data;
    delete slProperties.src;
    delete slProperties.alt;



    if (Silverlight.isInstalled(slPluginHelper.version)) {
        for (var name in slEvents) {
            if (slEvents[name]) {
                if (name == "onLoad" && typeof slEvents[name] == "function" && slEvents[name].length != 1) {
                    var onLoadHandler = slEvents[name];
                    slEvents[name] = function(sender) { return onLoadHandler(document.getElementById(id), userContext, sender) };
                }
                var handlerName = Silverlight.__getHandlerName(slEvents[name]);
                if (handlerName != null) {
                    slProperties[name] = handlerName;
                    slEvents[name] = null;
                }
                else {
                    throw "typeof events." + name + " must be 'function' or 'string'";
                }
            }
        }
        slPluginHTML = Silverlight.buildHTML(slProperties);
    }
    else {
        slPluginHTML = Silverlight.buildPromptHTML(slPluginHelper);
    }

    if (parentElement) {
        parentElement.innerHTML = slPluginHTML;
    }
    else {
        return slPluginHTML;
    }

}

Silverlight.buildHTML = function(slProperties) {
    var htmlBuilder = [];

    htmlBuilder.push('<object type=\"application/x-silverlight\" data="data:application/x-silverlight,"');
    if (slProperties.id != null) {
        htmlBuilder.push(' id="' + slProperties.id + '"');
    }
    if (slProperties.width != null) {
        htmlBuilder.push(' width="' + slProperties.width + '"');
    }
    if (slProperties.height != null) {
        htmlBuilder.push(' height="' + slProperties.height + '"');
    }
    htmlBuilder.push(' >');

    delete slProperties.id;
    delete slProperties.width;
    delete slProperties.height;

    for (var name in slProperties) {
        if (slProperties[name]) {
            htmlBuilder.push('<param name="' + Silverlight.HtmlAttributeEncode(name) + '" value="' + Silverlight.HtmlAttributeEncode(slProperties[name]) + '" />');
        }
    }
    htmlBuilder.push('<\/object>');
    return htmlBuilder.join('');
}



// createObjectEx, takes a single parameter of all createObject parameters enclosed in {}
Silverlight.createObjectEx = function(params) {
    var parameters = params;
    var html = Silverlight.createObject(parameters.source, parameters.parentElement, parameters.id, parameters.properties, parameters.events, parameters.initParams, parameters.context);
    if (parameters.parentElement == null) {
        return html;
    }
}


Silverlight.buildPromptHTML = function(slPluginHelper) {
    var slPluginHTML = "";
    var urlRoot = Silverlight.fwlinkRoot;
    var shortVer = slPluginHelper.version;
    if (slPluginHelper.alt) {
        slPluginHTML = slPluginHelper.alt;
    }
    else {
        if (!shortVer) {
            shortVer = "";
        }
        slPluginHTML = "<a href='javascript:Silverlight.getSilverlight(\"{1}\");' style='text-decoration: none;'><img src='{2}' alt='Get Microsoft Silverlight' style='border-style: none'/></a>";
        slPluginHTML = slPluginHTML.replace('{1}', shortVer);
        slPluginHTML = slPluginHTML.replace('{2}', urlRoot + '108181');
    }

    return slPluginHTML;
}

Silverlight.getSilverlight = function(version) {
    if (Silverlight.onGetSilverlight) {
        Silverlight.onGetSilverlight();
    }

    var shortVer = "";
    var reqVerArray = String(version).split(".");
    if (reqVerArray.length > 1) {
        var majorNum = parseInt(reqVerArray[0]);
        if (isNaN(majorNum) || majorNum < 2) {
            shortVer = "1.0";
        }
        else {
            shortVer = reqVerArray[0] + '.' + reqVerArray[1];
        }
    }

    var verArg = "";

    if (shortVer.match(/^\d+\056\d+$/)) {
        verArg = "&v=" + shortVer;
    }

    Silverlight.followFWLink("114576" + verArg);
}



Silverlight.followFWLink = function(linkid) {
    top.location = Silverlight.fwlinkRoot + String(linkid);
}

Silverlight.HtmlAttributeEncode = function(strInput) {
    var c;
    var retVal = '';

    if (strInput == null) {
        return null;
    }

    for (var cnt = 0; cnt < strInput.length; cnt++) {
        c = strInput.charCodeAt(cnt);

        if (((c > 96) && (c < 123)) ||
                  ((c > 64) && (c < 91)) ||
                  ((c > 43) && (c < 58) && (c != 47)) ||
                  (c == 95)) {
            retVal = retVal + String.fromCharCode(c);
        }
        else {
            retVal = retVal + '&#' + c + ';';
        }
    }

    return retVal;
}


Silverlight.default_error_handler = function(sender, args) {
    var iErrorCode;
    var errorType = args.ErrorType;

    iErrorCode = args.ErrorCode;

    var errMsg = "\nSilverlight error message     \n";

    errMsg += "ErrorCode: " + iErrorCode + "\n";


    errMsg += "ErrorType: " + errorType + "       \n";
    errMsg += "Message: " + args.ErrorMessage + "     \n";

    if (errorType == "ParserError") {
        errMsg += "XamlFile: " + args.xamlFile + "     \n";
        errMsg += "Line: " + args.lineNumber + "     \n";
        errMsg += "Position: " + args.charPosition + "     \n";
    }
    else if (errorType == "RuntimeError") {
        if (args.lineNumber != 0) {
            errMsg += "Line: " + args.lineNumber + "     \n";
            errMsg += "Position: " + args.charPosition + "     \n";
        }
        errMsg += "MethodName: " + args.methodName + "     \n";
    }
    alert(errMsg);
}


Silverlight.__cleanup = function() {
    for (var i = Silverlight._silverlightCount - 1; i >= 0; i--) {
        window['__slEvent' + i] = null;
    }
    Silverlight._silverlightCount = 0;
    if (window.removeEventListener) {
        window.removeEventListener('unload', Silverlight.__cleanup, false);
    }
    else {
        window.detachEvent('onunload', Silverlight.__cleanup);
    }
}

Silverlight.__getHandlerName = function(handler) {
    var handlerName = "";
    if (typeof handler == "string") {
        handlerName = handler;
    }
    else if (typeof handler == "function") {
        if (Silverlight._silverlightCount == 0) {
            if (window.addEventListener) {
                window.addEventListener('onunload', Silverlight.__cleanup, false);
            }
            else {
                window.attachEvent('onunload', Silverlight.__cleanup);
            }
        }
        var count = Silverlight._silverlightCount++;
        handlerName = "__slEvent" + count;

        window[handlerName] = handler;
    }
    else {
        handlerName = null;
    }
    return handlerName;
}