/*
           ,---------------------------------------------------------.
          /  tsrkit library functions. All the JavaScript functions   )
         /   and objects are in this file.                           /
        /                                                           /
       (            Ioan Sameli, 04.2006 - 09.2006                 /
        `--\   /--------------------------------------------------´
           |  /
            \|
             `
           (")-''-(").___,.~-´'^`-._
            \O_ O  )   `-.  (     ).`-.__.´)
            (_Y_.)/  ._   )  `._ `. `´-..-´
          _,.`--´_,.-_/  /~-`_.´ ,´
         (il).-'´  (li).´  ((!.-´

             _________________________________________________
    ________|                                                 |_______
    \       |   For more informations about all this, check   |      /
     \      |   the official documentation !                  |     /
     /      |_________________________________________________|     \
    /__________)                                            (________\




Recent updates
--------------
	22.09.2006 11:12	Created a new separated distribution with all the code in one sngle file
	19.10.2006 09:35	Added crossdomain support to Ajax object, using JSON
	01.11.2006 09:45	Changed the project's name, "tsrvod" to "tsrkit"
	28.02.2007 18:35	Included prototype.js, and simplified a couple of things with it


Code convention used in this project: http://javascript.crockford.com/code.html

TODO: an invalid xml ajax answer seems to give "no result" instead of an error

TODO: replace innerHTML with nodeValue, it's better because it's less worse (and it's valid)

TODO1: Since this won't only be used for videos, replace all the occurences to "video" by "item",
       and "playlist" by "search", or something like this
	   
TODO firstly : translate the doc in french, for the french developpers of the TSR

*/


  /********************************/
 /***   tsrkit configuration   ***/
/********************************/

	if (!fileExtension) var fileExtension = '/scripts/tsrkit_extension.js?d=200808250933';

	// Disable the drop down menu, so it won't be behind the video if opened
	var enableDropDownMenu = 0;

	// The delay after wich a JSON request is considered as timed out, in milliseconds
	var delayTimeoutJSON = 10000;
	var delayTimeoutAjax = 10000;

	// The default video element's width (the height will be 3/4 of this)
	// Can be overridden with a new value from the webpage.
	// TODO: these are not used anymore i think, and should be properties of the player object anyway
	var defaultVideoWidth = 440;
	var originalVideoWidth = 440;
	var videoAspectRation = 3/4;

	// The minimum flash version we want to detect
	var minFlashVersion = 8;

	// Default HTML template for the playlists (ajax)
	var defaultSearchResultTemplate = '<li class="line$line">'
		 + '<a href="#" name="$id" rel="video" onclick="return $player.playVideo(this.name);">'
		 + '$img<span class="title">$title</span></a></li>';

	// The title of a video, basically it's just the title, but the date or other details could eventually be added here
	var titleTemplate = '$title'

	// ID of the default target HTML element for the results of Data loading (Ajax)
	var defaultSearchTarget = null;

	// ID of the default target HTML element for the video Playback
	var defaultVideoTarget = null;

	// The URL template for the search
	var searchTemplateURL = 'index.html?descending=true&siteSect=500202&language = fre&searchNow=true&searchString=$s';

	// Ajax waiting signs, put whatever you want here
	var ajaxWaitingSign = '<div class="ajaxLoading">Chargement en cours...</div>';
	var ajaxLoadingSign = '<h1>NOT USED !</h1>';
	var ajaxErrorSign = '<div class="errMsg">Erreur au chargement des informations (format XML non valide)</div>';
	var ajaxEmptySign = '<div class="errMsg">La recherche n\'a donné aucun résultat</div>';
	var requestTimeoutSign = '<div style="font-weight:bold;">Problèmes réseaux temporaires.<br/><br/>Veuillez réessayer plus tard.</div>';

	// Used when the playback of a video fails because no compatible file has been found
	var noAvailableFile = '<div class="errMsg">No compatible file :(</div>';

	// Icons, used for the configuration panel
	var okayIcon = '<img src="/images/icons/icon_16-okay.gif" alt="" />';
	var troubleIcon = '<img src="/images/icons/icon_16-trouble.gif" alt="" />';
	var warningIcon = '<img src="/images/icons/icon_16-warning.gif" alt="" />';

	// Maybe this will be useful, but i don't know yet. It's the files to test bandwidth
	var staticDataSize1 = '/download/static/test-data-64k.html';
	var staticDataSize2 = '/download/static/test-data-128k.html';
	var staticDataSize4 = '/download/static/test-data-256k.html';
	var staticDataSize8 = '/download/static/test-data-512k.html';
	var staticDataSize16 = '/download/static/test-data-1024k.html';	// I guess this one shouldn't be used too much since it uses too much ram for the client

	// Cookie names that store detection result
	var cookieWM = 'windowsMedia';      // Windows Media detection result
	var cookieRP = 'realMedia';        // Real Player detection result
	var cookieMF = 'flash';           // Macromedia Flash detection result
	var cookieBW = 'testBandWidth';  // BandWidth detection result

	// Maximum age of the cookies containing the test results
	var resultCookiesLife=30;

	// The style of the dialog panel (stored here so we don't have to add it to all the CSS files)
	var displayPanelStyle = 'opacity: .75;filter:Alpha(opacity=75);position:absolute;width:33%;'
		 + 'left:33%;top:33%;border:1px solid red;font-size:14px;font-weight:bold;'
		 + 'background:url(/images/interactif/player/searching.gif) no-repeat left #FFFFFF;'
		 + '-moz-border-radius:16px;padding:32px;padding-left:48px;';

	// The HTML code of this display panel
	var displayPanelCode = '<div id="displayPanel" style="' + displayPanelStyle + '">$msg</div>';

	// The HTML code for embed videos, for different codecs: Real, WindowsMedia, Flash, and jpeg
	var playerCodeReal = '<embed id="embedVideo" name="embedVideo" title="realMedia" type="audio/x-pn-realaudio-plugin" '
		+ 'codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" '
		+ 'autostart="true" src="$file" controls="ImageWindow" console="radio" '
		+ 'nojava="false" width="$width" height="$height" maintainaspect="true"/>'
		//+ '<br/><embed width="$width" height="26" type="audio/x-pn-realaudio-plugin" name="controls" id="realControls" '
		+ '<embed width="$width" height="26" type="audio/x-pn-realaudio-plugin" name="controls" id="realControls" '
		+ 'nojava="true" controls="ControlPanel" console="radio"/>';

	var playerCodeWindowsMedia = '<div onmouseover="debugVideoWM();" id="videoEmbedWindowsMedia">'
		+ '<object classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" width="$width" height="$height" '
		+ 'id="embedVideo" standby="chargement..." type="application/x-oleobject">\n'
		+ '<param name="URL" value="$asx_file">\n'
		+ '<param name="AutoStart" value="True"><param name="stretchToFit" value="true">\n'
		+ '<param name="showDisplay" value="True"><param name="showStatusBar" value="True">\n'
		+ '<param name="showControls" value="True"><param name="fullScreen" value="False">\n'
		+ '<param name="uiMode" value="full"><param name="enableContextMenu" value="1">\n'
		+ '<embed type="application/x-mplayer2" '
		+ 'pluginspage="http://microsoft.com/windows/mediaplayer/en/download/" '
		+ 'src="$asx_file" id="embedVideo" standby="chargement..." name="player" '
		+ 'width="$width" height="$height" title="windowsMedia" '	
		+ 'displaysize="4" autosize="-1" showcontrols="true" showtracker="1" showdisplay="0" '	
		+ 'autostart="true" stretchToFit="true" showcontrols="true" fullscreen="false" showdisply="true" '
		+ 'uimode="full" enablecontextmenu="1" showstatusbar="true"></embed></object></div>';

	var playerCodeFlashSwf = '<object title="flash" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" '
		+ 'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" '
		+ 'height="$height" width="$wid