window.onload = function() {
	if (document.getElementById) {
		if (document.getElementById("textContainer")) {
			initTicker();
		}
		if (typeof(initScrolls) != 'undefined') {
			initScrolls();
		}
		if (typeof(initTickerIf) != 'undefined') {
			initTickerIf();
		}
	}
	setText();
	loadHoraireXML();
}

//=============================================================
//	----------	Racourci code		----------
//=============================================================

var d = document;
function $id() {
  var elements = new Array();

  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);

    if (arguments.length == 1)
      return element;

    elements.push(element);
  }

  return elements;
}
var $url = document.location.toString().toLowerCase();

function setClass(obj, strClass) {
	if (obj) {
		if (obj.className != "") obj.className += " ";
		obj.className += strClass;
	}
}

//=============================================================
//	----------	Function webtrends		----------
//=============================================================

function callWebtrends(strA, strB) {
	ClicTrack('dcsuri',strB,'clic_action',strB,'clic_contenu',strB,'WT.ti',strB,'WT.clic',strA);
}

function CT(strClicEmplacement) {
	//alert("CT('" + strClicEmplacement + "')");
	var strProfil
	var strUrl = $url;

	if ((strUrl.indexOf("/nouvelles/index.shtml") != -1) || (strUrl.indexOf("/nouvelles/") == strUrl.length - 11) || (strUrl.indexOf("/lib/v1/inc/ticker/nouvelles.html") != -1)) {
		strProfil = "PA_nouvelles";
	} else if((strUrl.indexOf("/sports/index.shtml") != -1) || (strUrl.indexOf("/sports/") == strUrl.length - 8) || (strUrl.indexOf("/lib/v1/inc/ticker/sports.html") != -1)) {
		strProfil = "PA_sport";
	} else if((strUrl.indexOf("/arts-spectacles/index.shtml") != -1) || (strUrl.indexOf("/arts-spectacles/") == strUrl.length - 17) || (strUrl.indexOf("/lib/v1/inc/ticker/arts-spectacles.html") != -1)) {
		strProfil = "PA_arts";
	} else {
		return;
	}
	ClicTrack('dcsuri',strUrl ,'clic_action',strClicEmplacement, 'WT.ti',strClicEmplacement, 'WT.clic',strProfil);
	//alert("'dcsuri',"+strUrl+" ,'clic_action',"+strClicEmplacement+", 'WT.ti',"+strClicEmplacement+", 'WT.clic',"+strProfil+"");
}
//=============================================================
//	----------	Function Zap			----------
//=============================================================

function callMediaPlayer(urlMedia, numMenu) {
	if (numMenu == null || numMenu == "") numMenu = 1;
	window.open('http://www.radio-canada.ca/audio-video/pop.shtml#urlMedia=' + urlMedia + '&epr=true', 'audioVideo','toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,history=no,resizable=yes,width=1,height=1');
}
function showMediaPlayer(_sUrlMedia, _sDescription, _sImgTeaser, _sGUI) {
	var _domain = (_sUrlMedia.indexOf("http://")!=-1) ?  "" : "http://"+document.domain;
	if(document.location.href.indexOf("test")!=-1){
		//alert(_domain + " $$ " + _sUrlMedia)
	}
	
	_domain = "";/// temp fix
	
	srcAV_write(
		{
			urlMedia : _domain + _sUrlMedia, 
			txtTeaser : _sDescription, 
			urlTeaser : _sImgTeaser, 
			data : false, 
			autoStart : false, 
			updateHistory : false, 
			showTeaserFin : false, 
			GUI : ((_sGUI!=undefined && _sGUI!=null)?_sGUI:"embedSrcMini")
		}
	);
}
//=============================================================
//	----------	Gestion des CSS		----------
//=============================================================

function setActiveStyleSheet(title) {
	if (document.getElementsByTagName) {
		var i, a, main;
		for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("alternate stylesheet") != -1 && !(a.getAttribute("id"))) {
				a.disabled = true;
			if(a.getAttribute("title") == title	) {
					a.disabled = false;
				}
			}
		}
	}
}

function changeText() {
	var size = getCookieText("srcTailleTexte");
	//alert(getCookieText("srcTailleTexte"));
	switch (size) {
		case null:
			setSizeStyleSheet("T1");
			break;
		case "0":
			setSizeStyleSheet("T1");
			break;
		case "T1":
			setSizeStyleSheet("T2");
			break;
		case "T2":
			setSizeStyleSheet("0");
			break;
	}
}

//nouvelle version mise en place pour la nouvelle barre partager pour nouvelles (mise en place le 18 juillet 2008)
function changeTextPlusMoins(p_taille) {
	var size = getCookieText("srcTailleTexte");
						
	switch (size) {
	  case null:
		if (p_taille=='plus'){
			setSizeStyleSheet("T1");
		}
		break;
	  case "0":
		if (p_taille=='plus'){
			setSizeStyleSheet("T1");
		}
		break;
	  case "T1":
		if (p_taille=='plus'){
			setSizeStyleSheet("T2");
		}else{
			setSizeStyleSheet("0");
		}
		break;
	  case "T2":
		if (p_taille=='moins'){
			setSizeStyleSheet("T1");
		}
		break;
	  default:;
	}
}


function setSizeStyleSheet(size) {
	//alert("setSizeStyleSheet("+size+")");
	if (document.getElementById) {
		if (document.getElementById("tailleText")) {

			if (size == "0") {
					document.getElementById("T1").disabled = true;
					document.getElementById("T2").disabled = true;
					document.getElementById("tailleText").setAttribute("className", "tailleText typo1");
					document.getElementById("tailleText").setAttribute("class", "tailleText typo1");
			} else if(size == "T1") {
					document.getElementById("T1").disabled = false;
					document.getElementById("T2").disabled = true;
					document.getElementById("tailleText").setAttribute("className", "tailleText typo2");
					document.getElementById("tailleText").setAttribute("class", "tailleText typo2");
			} else if(size == "T2") {
					document.getElementById("T1").disabled = true;
					document.getElementById("T2").disabled = false;
					document.getElementById("tailleText").setAttribute("className", "tailleText typo3");
					document.getElementById("tailleText").setAttribute("class", "tailleText typo3");
			}
			setCookieText("srcTailleTexte", size, 365) ;
		}
	}
}


function setText() {
	var size = getCookieText("srcTailleTexte") ;
	if (size == null) {
		setSizeStyleSheet("0");
	} else {
		setSizeStyleSheet(size);
	}
}


//=============================================================
//	----------	Cookie		----------
//=============================================================
function setCookieText(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	} else {
		var expires = "";
	}
	document.cookie = name+"="+value+expires+"; path=/";
}

function getCookieText(name) {
	var nameEQ = name + "=";
	//alert(nameEQ);
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function deleteCookie(name) {
	setCookieText(name,"",-1);
}
//=============================================================
//	----------	Encode email		----------
//=============================================================

function Decode(msg){
	var DECRYPT = false;
	var ClearMessage="";
	ClearMessage += codeIt(msg);
	document.write(ClearMessage);
}

var key = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1029384756><#].";
function codeIt (_message) {
	var wTG;
	var mcH = key.length / 2;
	var _newString = "";
	var dv;
	for (var x = 0; x < _message.length; x++) {
		wTG = key.indexOf(_message.charAt(x));
		if (wTG > mcH) {
			dv = wTG - mcH;
			_newString += key.charAt(33 - dv);
		} else {
			if (key.indexOf(_message.charAt(x)) < 0) {
				_newString += _message.charAt(x);
			} else {
				dv = mcH - wTG;
				_newString += key.charAt(33 + dv);
			}
		}
	}
	return (_newString);
}

//=============================================================
//	----------	Autres fonctions		----------
//=============================================================


function pop(dest,largeur,hauteur,scroll) {
    jsURL=dest;
    jsNom='fenetre';
	jsParam='toolbar=no,directories=no,status=no,menubar=no,scrollbars=' + scroll + ',history=no,resizable=yes,width=' + largeur + ',height='+hauteur+',left=1,top=1';
	window.open(jsURL, jsNom, jsParam);
}

function popup(URL, Nom, Param) {
	window.open(URL, Nom, Param);
}

function pageAccueil(doc,url){
if(navigator.appVersion.charAt(navigator.appVersion.indexOf("MSIE") + 5) >= 5 && navigator.platform.indexOf("Win16") == -1 && navigator.platform.indexOf("Mac") == -1){
	doc.style.behavior='url(#default#homepage)';
	doc.setHomePage(document.location.hostname + url);
	doc.href="#";
	return true;
	}else{
	return false
	}
}	
function request(param) {
	/*	CC Martin Rancourt */
	/*	v 1.0	*/
	var strParam = param.toString().toLowerCase();
	var strQS = d.location.search.toString().toLowerCase().slice(1);//enlève le ?
	if (strQS.indexOf(strParam) != -1) {
		var arrQS = strQS.split("&");
		for(var i = 0; i < arrQS.length; i++) {
			if (arrQS[i].slice(0, arrQS[i].indexOf("=")) == strParam) return arrQS[i].slice(arrQS[i].indexOf("=")+1);
		}
	}
	return "";
}



//=============================================================
//	-------	START nouveau - fonctions "libGlobalv1_"  --------
//  ---------- BRovito - 19-03-2008 --------------------------
//=============================================================

var isSwfInstall=false;

/**
* libGlobalv1_getFlv
*
* afficher une FLV 
* exemple: libGlobalv1_getFlv('FlvVestiaire','/nouvelles/surLeWeb/lib/v1/swf/playerCamera', 'V_test.flv&amp;isPlay=0', 'swfVideoVestiare', 200, 150);
*
* Note: passer la valeur null au params non utilisés
*/
 function libGlobalv1_getFlv( _sDivId, _sSwfSource, _sFlashVars, _sSwfId, _nWidth, _nHeight, _sSwfWmode, _aFlashVersion /* [major,minor,revision]*/ ){

	// base path to FLVs
  		//var sPATH_TO_FLV="http://www.radio-canada.ca/medianet/";
   
   // flash player version required
  	 var _aVersion = ( (_aFlashVersion!=undefined) && (_aFlashVersion!=null)) ? _aFlashVersion : null;
   
   // embed swf WITH player detection
  	 if (_sDivId!=null){
  		   libGlobalv1_embedSwf (_sDivId, _sSwfSource, "flv="+_sFlashVars, _sSwfId, _nWidth, _nHeight, _sSwfWmode, _aVersion);
	 }else{	  	
		 return libGlobalv1_embedSwf (_sDivId, _sSwfSource, "flv="+_sFlashVars, _sSwfId, _nWidth, _nHeight, _sSwfWmode, _aVersion);
		 
	 }
};

/**
* libGlobalv1_getFlvZ
*
* afficher une FLV enregistrer avec Z
* exemple: libGlobalv1_getFlvZ('FlvVestiaire','/nouvelles/surLeWeb/lib/v1/swf/playerCamera', 'V_test.flv&amp;isPlay=0', 'swfVideoVestiare', 200, 150);
*
* Note: passer la valeur null au params non utilisés
*/
 function libGlobalv1_getFlvZ( _sDivId, _sSwfSource, _sFlashVars, _sSwfId, _nWidth, _nHeight, _sSwfWmode, _aFlashVersion /* [major,minor,revision]*/ ){

	// base path to FLVs
  		var sPATH_TO_FLV="http://www.radio-canada.ca/medianet/";
   
   // flash player version required
  	 var _aVersion = ( (_aFlashVersion!=undefined) && (_aFlashVersion!=null)) ? _aFlashVersion : null;
   
   // embed swf WITH player detection
  	 if (_sDivId!=null){
  		   libGlobalv1_embedSwf (_sDivId, _sSwfSource, "flv="+sPATH_TO_FLV+_sFlashVars, _sSwfId, _nWidth, _nHeight, _sSwfWmode, _aVersion);
	 }else{	  	
		 return libGlobalv1_embedSwf (_sDivId, _sSwfSource, "flv="+sPATH_TO_FLV+_sFlashVars, _sSwfId, _nWidth, _nHeight, _sSwfWmode, _aVersion);
		 
	 }
};

/**
* libGlobalv1_embedSwf
*
* DÉTECTER la version du flash player avant de faire un embed swf
*
* Note: passer la valeur null au params non utilisés 
*/
 function libGlobalv1_embedSwf( _sDivId, _sSwfSource, _sFlashVars, _sSwfId, _nWidth, _nHeight, _sSwfWmode, _aFlashVersion/* [major,minor,revision]*/ ){
	
	var _sSwf = (_sSwfSource==null) ? "" : _sSwfSource; // sans extension .swf
	var _sVars = (_sFlashVars==null) ? "" : _sFlashVars;
	var _sId = (_sSwfId==null)? "PlayerCamera" : _sSwfId;
	var _nW = (_nWidth==null)? 200 : _nWidth;
	var _nH = (_nHeight==null)? 150 : _nHeight;
	var _sWmode = (_sSwfWmode==null) ? "opaque" : _sSwfWmode;
		
	// Major version 
		var requiredMajorVersion = 	(_aFlashVersion!=null && _aFlashVersion!=undefined) ? _aFlashVersion[0] : 6; // 9
	// Minor version 
		var requiredMinorVersion = 	(_aFlashVersion!=null && _aFlashVersion!=undefined) ? _aFlashVersion[1] : 0; // 0
	// Minor version
		var requiredRevision = 		(_aFlashVersion!=null && _aFlashVersion!=undefined) ? _aFlashVersion[2] : 65; // 115
	// Version check for the Flash Player that has the ability to start Player Product Install (6.0r65)
		var hasProductInstall = DetectFlashVer(6, 0, 65);	
	// Version check based upon the values defined in globals
		var hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
	
	// alt content if flash not detected
		var alternateContent = "<div  style=\"background-color:#fff;border:1px grey solid;padding:3px;\"><p>Le plugiciel <b>« Flash "+requiredMajorVersion+"."+requiredMinorVersion+"."+requiredRevision+" »</b> n'est pas installé sur votre ordinateur.<br/><a href='http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash' target='_blank'>Cliquez ici pour le télécharger</a>.</p><p><b>Note pour les utilisateurs Macintosh:</b> Il se peut que vous deviez redémarrer votre ordinateur une fois l'installation terminée.</p></div>";
	
	// Check to see if a player with Flash Product Install is available and the version does not meet the requirements for playback
		if ( !hasRequestedVersion  && hasProductInstall) {
			
			/*// MMdoctitle is the stored document.title value used by the installation process to close the window that started the process
				 This is necessary in order to close browser windows that are still utilizing the older version of the player after installation has completed
				 DO NOT MODIFY THE FOLLOWING FOUR LINES
				 Location visited after installation is complete if installation is required 
			*/
				var MMPlayerType = (isIE == true) ? "ActiveX" : "PlugIn";
				var MMredirectURL = window.location;
				document.title = document.title.slice(0, 47) + " - Flash Player Installation";
				var MMdoctitle = document.title;
			
			
			if(!isSwfInstall){// only prompt install 1 time
				isSwfInstall=true;
				if (isIE){
					libGlobalv1_doEmbedSwf(_sDivId, "/lib/v1/swf/playerProductInstall", "MMredirectURL="+MMredirectURL+'&MMplayerType='+MMPlayerType+'&MMdoctitle='+MMdoctitle+"", "installFlashPlayer", _nWidth, _nHeight, _sSwfWmode);
				}else{
					if (_sDivId!=null){
						document.getElementById(_sDivId).innerHTML = alternateContent;
					}else{
						return alternateContent;
					}
				}
			}
		}else if (hasRequestedVersion) { // if we've detected an acceptable version
			if (_sDivId!=null){
				libGlobalv1_doEmbedSwf(_sDivId, _sSwfSource, _sFlashVars, _sSwfId, _nWidth, _nHeight, _sSwfWmode);
			}else{
				return libGlobalv1_doEmbedSwf(_sDivId, _sSwfSource, _sFlashVars, _sSwfId, _nWidth, _nHeight, _sSwfWmode);
			}
			// embed the Flash Content SWF when all tests are passed
			
		} else {  // flash is too old or we can't detect the plugin
			if (_sDivId!=null){
				document.getElementById(_sDivId).innerHTML = alternateContent;
			}else{
				return alternateContent;
			}
		}
	};


/**
* libGlobalv1_doEmbedSwf
*
* faire un embed swf SANS détection de version du flash player 
*
* Note: passer la valeur null au params non utilisés 
*/
 function libGlobalv1_doEmbedSwf( _sDivId, _sSwfSource, _sFlashVars, _sSwfId, _nWidth, _nHeight, _sSwfWmode ){
						
		var _sSwf = (_sSwfSource==null) ? "" : _sSwfSource; // sans extension .swf
		var _sVars = (_sFlashVars==null) ? "" : _sFlashVars;
		var _sId = (_sSwfId==null)? "PlayerCamera" : _sSwfId;
		var _nW = (_nWidth==null)? 200 : _nWidth;
		var _nH = (_nHeight==null)? 150 : _nHeight;
		var _sWmode = (_sSwfWmode==null) ? "opaque" : _sSwfWmode;
		var _sEmbedHtml = "";
		
		if (_sSwfSource != ""){
			if (AC_FL_GetContent == 0) {
				alert('This page requires AC_RunActiveContent.js. In Flash, run Apply Active Content Update in the Commands menu to copy AC_RunActiveContent.js to the HTML output folder.');
				} else {
					/* Safari bug fix: must write someting to innerHTML and then "+=" the other content ;See following innerHTML assignment*/
					_sEmbedHtml +=  "<span style='display:none'>Radio-Canada.ca</span>"; 
					_sEmbedHtml +=  AC_FL_GetContent(
						'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0',
						'width', _nW,
						'height', _nH,
						'src', _sSwf,
						'movie', _sSwf,
						'quality', 'high',
						'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
						'align', 'middle',
						'play', 'true',
						'loop', 'true',
						'scale', 'showall',
						'wmode', _sWmode,
						'devicefont', 'false',
						'id', _sId,
						'bgcolor', '#000000',
						'name', _sId,
						'menu', 'true',
						'allowScriptAccess','always',
						'salign', '',
						'FlashVars',  _sVars
						); //end AC code
					
					if (_sDivId!=null){
						document.getElementById(_sDivId).innerHTML = _sEmbedHtml;
					}else{
						return  _sEmbedHtml;
					}
				}
		}
	};
	

/**
* libGlobalv1_writeFlashEmbed
*
* à utiliser quand on veux écrire l'embed flash dans le document (donc la première var dans la fonction libGlobalv1_embedSwf() est mise à null)
*
* Exemple:   libGlobalv1_writeFlashEmbed(
										 libGlobalv1_embedSwf(null,"/nouvelles/enProfondeur/Societe/conversions-religieuses/lib/swf/webcam", _sFVars, "swfWebcam", 228, 430, "transparent", [9,0,0])
										 );
*/
	function libGlobalv1_writeFlashEmbed(_sEmbedhtml){
		document.write ( _sEmbedhtml  );
	};
	
//=============================================================
//	----------	END nouveau - fonctions "libGlobalv1_"  -------
//=============================================================

//=============================================================
//	----------	set event on the page  -------
//=============================================================
var SetTimerEvent;
function loadHoraireXML(){
try{	
 SetTimerEvent=new Class({
    initialize: function(_obj){
        this.finEvent=_obj.finEvent;
        this.debutEvent=_obj.debutEvent;
        this.debutTemps=new Date(_obj.debutTemps);
        this.finTemps=new Date(_obj.finTemps);
        this.now=new Date();
        if (this.now>=this.debutTemps && this.now<this.finTemps) this.event=this.debutEvent;
        if ( this.now>=this.finTemps)   this.event=this.finEvent;  
        if (this.event){
            switch (this.event.action){
                case "include_css":
                    this.include_css();
                break;
                case "set_css":
                    this.set_css();
                break;
            }
        };
    },
    include_css:  function(){
        if (this.isSection()){
            var _linkTemplate =new Element("link",{rel:"stylesheet",type:"text/css",href:this.event.url});
            $$("head")[0].appendChild(_linkTemplate);
        }	
   },
    set_css:function(){
        if (this.isSection()){
            var _seek=($defined(this.event.id) && (this.event.id.length>0) ?"#"+this.event.id:"")+ " " + ($defined(this.event.className) && (this.event.className.length>0)?"."+this.event.className:"");
            var _elem=$$(_seek)[0];
            if ($defined(_elem))
                for (var _att in this.event.css){
                    _elem.style[_att]=this.event.css[_att];
                }
        }
    },
    isSection:function(){
        if (this.event.regEx){
             var _regEx=new RegExp(this.event.section);
             return window.location.toString().search(_regEx)>=0;
        }else
        return (window.location.toString().contains(this.event.section));
    }
});	
    new Request({
        url:"/lib/v2/inc/horaire.xml",
        method:"get",
        async: true,
        onSuccess: function(text,doc){
        var _ohEvent=doc.getElementsByTagName("event");
        for (var i=0;i<_ohEvent.length;i++){
            var _oEvent=new Object();
            fillEvent(_ohEvent[i],_oEvent,"debutTemps","debutEvent");
            fillEvent(_ohEvent[i],_oEvent,"finTemps","finEvent");
            new SetTimerEvent(_oEvent); 
        }
        function fillEvent(_oh,_oEvent,_sTemps,_sName){
            var _elem=_oh.getElementsByTagName(_sName)[0];
            _oEvent[_sTemps]=_elem.getAttribute("temps");
            _oEvent[_sName]=new Object();
            var _action=_elem.getElementsByTagName("action");
            if (_action.length>0){
                _oEvent[_sName].action=textNode(_action[0]);
                var _nodeSection=_elem.getElementsByTagName("section");
                _oEvent[_sName].section=(_nodeSection.length>0)?textNode(_nodeSection[0]):"";
                _oEvent[_sName].regEx=(_nodeSection.length>0)?_nodeSection[0].getAttribute("regex"):false;
                switch (_oEvent[_sName].action){
                    case "include_css":
                        _oEvent[_sName].url=textNode(_elem.getElementsByTagName("url")[0]);
                    break;
                    case "set_css":
                        var _nodeId=_elem.getElementsByTagName("id");
                        if (_nodeId.length>0) textNode(_oEvent[_sName].id=_nodeId[0]);
                        var _nodeClassName=_elem.getElementsByTagName("className");
                        if (_nodeClassName.length>0) _oEvent[_sName].className=textNode(_nodeClassName[0]);
                        var _ohCss=_elem.getElementsByTagName("style");
                        _oEvent[_sName].css=new Object();
                        for (var i=0;i<_ohCss.length;i++){
                            _oEvent[_sName].css[_ohCss[i].getAttribute("name")]=_ohCss[i].getAttribute("value");
                        }
                    break;
                }
            }
            function textNode(_node){
                return $defined(_node.textContent)?_node.textContent:_node.text;
            }
        }
        }
    }).send();
}catch(e){}
};
//=============================================================
//	----------	Fin de block set event on the page  -------
//=============================================================

