﻿var currentTOCElement;
var NTstrHide = 'Bezár';
var NTstrShow = 'Mutat';
var scourl = document.location.search;
if (!scormID){
	if (scourl.indexOf("a=") >= 0){
				scormID = ""+scourl.match(/a=[0-9]*/)
	} else {
		scormID = Math.ceil(1000*Math.random());
	}
}

function scormCookieHide(id, NTstrShow, NTstrHide) {
    var obj  = document.getElementById(id);
    var cook = new cookie('hide:' + scormID + obj.id).read();
    if(cook != null && cook == 0) {
		scormToggleHide(obj, false, function(el) {return document.getElementById('toctree'); }, NTstrShow, NTstrHide, document.getElementById('scormbox'), document.getElementById('hide-show-input'));
    }
	return cook;
}

function scormToggleHide(el, persistent, elementFinder, NTstrShow, NTstrHide, scormel, inputel) {
    if(!elementFinder) {
        var obj = el;  //el:container
        el = document.getElementById('togglehide_'+obj.id);
    }
    else {
        var obj = elementFinder(el);  //el:button.
    }
	
    if(obj.style.display != 'none') {
		obj.style.display = 'none';
		document.getElementById("tocbox").style.width = "100%";
		document.getElementById("scormbox").style.width = "100%";
		document.getElementById("scormbox").style.top = "30px";
		if (inputel.value) {
            inputel.value = NTstrShow;
        }
        var shown = 0;
    }
    else {
		obj.style.display = 'block';
		document.getElementById("tocbox").style.width = "24%";
		scormel.style.width = "74%";
		scormel.style.top = "0px";
        if (inputel.value) {
            inputel.value = NTstrHide;
        }
        var shown = 1;
    }

    if(persistent == true) {
		//alert((shown ? -1 : 356))
        new cookie('hide:' + scormID + obj.id, shown, 356, '/').set();
    }
	
} // function scormToggleHide

if (document.getElementById("mod-scorm-player")){

		if (document.getElementById("toctree")){
			if (document.forms["tochead"]){
				document.forms["tochead"].innerHTML = document.forms["tochead"].innerHTML + " " + '<input type="button" onclick="scormToggleHide(this, true, function(el) {return document.getElementById(\'toctree\'); }, \'Mutat\', \'Bezár\', document.getElementById(\'scormbox\'), document.getElementById(\'hide-show-input\')); this.blur(); return false;" value="Bezár" name="NT-stclose" id="hide-show-input"/>';
			}
			
			if (scormCookieHide('toctree','Mutat','Bezár') == null){
				if (scormstartHide == true ){
					scormToggleHide(document.getElementById('toctree'), false, function(el) {return document.getElementById('toctree'); }, NTstrShow, NTstrHide, document.getElementById('scormbox'), document.getElementById('hide-show-input'));
				}
			}
			
			
			if (scourl.indexOf("scoid") >= 0){
				var scoid = ""+scourl.match(/scoid=[0-9]*/)
				var treeobj = document.getElementById("toctree");
				var links = treeobj.getElementsByTagName("a");
				var i = 0;
				var iteration = false;
				while (!iteration){
					if (i<links.length){
						var lhref = links[i].href;
						if (lhref.indexOf(scoid) >= 0){
							if (lhref.indexOf(scoid) + scoid.length >= lhref.length){
								links[i].className ? links[i].className = links[i].className + " NT-actual" : links[i].className = "NT-actual";	
								j = i;
								if (i > 1) j--;
								links[j].scrollIntoView(true);
								window.scrollTo(0,0);
								currentTOCElement = links[i];
								iteration = true;
							} else {
								ns = lhref.substr(lhref.indexOf(scoid) + scoid.length ,1);
								if (ns.match(/[0-9]{1}/)){
								} else {
									links[i].className ? links[i].className = links[i].className + " NT-actual" : links[i].className = "NT-actual";	
									j = i;
									if (i > 1) j--;
									links[j].scrollIntoView(true);
									window.scrollTo(0,0);
									currentTOCElement = links[i];
									iteration = true;
								}
							}
						}
					} else {
						iteration = true;
					}
					i++;
				}
			}
		} // if toctree
} //if mod-scorm-player
	

