var version_number= "3.22";
var strIdentifier = "gopas";
var urlLearnLRN   = "imsmanifest.xml";
var syllabus_path = "viewer/syllabus.htm";
var cscheme_path  = "viewer/themes/";
var cscheme       = "modern";

window.API = new LMSAPI(strIdentifier, false);

if (document.readyState)
{
	if (document.readyState == "complete") InitContentPlayer();
  else if (document.readyState == "interactive") setTimeout('InitContentPlayer()',100); // Opera 9.5
  else if (document.readyState == "loading") setTimeout('InitContentPlayer()',100); // Chrome
  else document.onreadystatechange = evt_ReadyStateChange;
} else window.onload = InitContentPlayer; // Init pro Mozillu
	
window.onunload = UnLoadRoutine;

function evt_ReadyStateChange()
{
  if (document.readyState != 'complete') return;
  InitContentPlayer();
}
  
function InitContentPlayer()
{
  try
  {
    if(window.API != null)
    {
      // Inicializace Vieweru
      window.API.LRNInitialize("g_oDefaultUserData", "", urlLearnLRN, cscheme_path+cscheme+"/cpitem.xsl");
      window.API.LRNListenForEvents(mf_EventHandler);
      window.API.LMSInitialize(""); // Inicializace LSM musi byt provedena az pote, co je inicializovan Viewer

      // Nahlaseni TITULNIMu panelu, ze doslo k inicializaci
      if ((typeof(banner) != "undefined") && (typeof(banner.RegisterEvents) != "undefined")) banner.RegisterEvents();
    }
  }
  catch(e)
  {
    document.write("<h2><font face='Tahoma,Verdana,Arial'><center><b>Došlo k selhání načítání Gopas přehrávače, nejspíše nemáte povoleny ActiveX prvky</b></center></font></h2>"+e.message);
  }
}

function UnLoadRoutine()
{
  if (window.API != null)
  {
    saveCMI();
    window.API.LRNUnListenForEvents(mf_EventHandler);
    window.API.LRNTerminate();
  }
}

function ChangeCScheme(hodnota)
{
  try
  {
    document.getElementById('ss').href = "viewer/themes/"+hodnota+"/"+hodnota+'.css';
  } catch(err)
  {
    return;
  }
  if (typeof(banner.ChangeCScheme) != "undefined")  banner.ChangeCScheme(cscheme);
  if (typeof(__idTOCFrame.ChangeCScheme) != "undefined") __idTOCFrame.ChangeCScheme(hodnota);
}

function saveCMI()
{
  if (window.API!=null) window.API.SavePersXML();
}

function mf_EventHandler(obj)
{
  switch(obj.type)
  {
    case 3:
    {
    	mf_EventHandlerTO();
      break;
    }
  }
}

function mf_EventHandlerTO()
{
	if (typeof(__idTOCFrame) == "undefined") setTimeout('mf_EventHandlerTO()',100);
	else __idTOCFrame.location.href = syllabus_path;
}

function MM_GetUserName(url) {
  var prms="", tmpp, pos;

  pos=url.indexOf("#");
  if (pos==-1) pos=url.indexOf("?")
  if (pos>-1) prms=url.substring(pos+1,url.length)
  tmpp=prms.toUpperCase()

  MM_USER='';
  if ((pos=tmpp.indexOf("USER"))>-1) {
    MM_USER=prms.substring(pos+5,prms.length)
    if (MM_USER.indexOf("&")>0)
        MM_USER=unescape(MM_USER.substring(0,MM_USER.indexOf("&")))
  }

  myStr='';
  for (i=0;i<MM_USER.length;i++) {
    if ((MM_USER.charCodeAt(i)>='a'.charCodeAt(0)) && (MM_USER.charCodeAt(i)<='z'.charCodeAt(0))) {
      if ((MM_USER.charCodeAt(i)-7)<'a'.charCodeAt(0))
        myStr+=String.fromCharCode(MM_USER.charCodeAt(i)-7+'z'.charCodeAt(0)-'a'.charCodeAt(0)+1);
      else
        myStr+=String.fromCharCode(MM_USER.charCodeAt(i)-7);
    } else
    if ((MM_USER.charCodeAt(i)>='A'.charCodeAt(0)) && (MM_USER.charCodeAt(i)<='Z'.charCodeAt(0))) {
      if ((MM_USER.charCodeAt(i)-7)<'A'.charCodeAt(0))
        myStr+=String.fromCharCode(MM_USER.charCodeAt(i)-7+'Z'.charCodeAt(0)-'A'.charCodeAt(0)+1);
      else
        myStr+=String.fromCharCode(MM_USER.charCodeAt(i)-7);
    } else {
        myStr+=MM_USER.charAt(i);
    }
  }
  MM_USER=myStr; if (MM_USER=='') MM_USER='Student';
  
  return MM_USER;
}