//fisier de inclus in fiecare pagina de continut!
var pageLoaded = false; //variabila ce indica daca pagina s-a incarcat; la onload se modifica in true!
//var leftsideWidth = 165; //latime frame stanga
var cols = parent.getCols(); //=> de ex '161,*'
var leftsideWidth = parseInt(cols.substring(0, cols.indexOf(','))); //=> 161 ; foloseste la functia changeMenusLeftOffsets!
//var leftsideWidth =  document.all ? parent.leftside.document.body.clientWidth : document.getElementById ? parent.leftside.window.innerWidth : 165; //165 = val default
  //definire meniuri: ypSlideOutMenu(prefixNume, directie, initLeft, initTop, initWidth, initHeight)
  var menus = [ //left initial nu conteaza pentru ca se re-calculeaza cand se incarca meniul principal
		new ypSlideOutMenu("sciteam", "down", 30, 0, 100, 93),
		new ypSlideOutMenu("acttasks", "down", 190, 0, 250, 156),
		new ypSlideOutMenu("results", "down", 220, 0, 170, 133)
		//new ypSlideOutMenu("cont", "down", 250, 0, 100, 38)
		//new ypSlideOutMenu("ang", "down", 280, 0, 95, 38),		
	]

//functii pentru determinarea offsetului left - necesar pentru submeniuri :
function getObj(idName) {
 var obj = document.all ? document.all[idName] : document.getElementById ? document.getElementById(idName) : null;
 return obj;
}
function getElemProperty(elemId,propName) { //ex: getElemProperty('stiri','top');
var elemObj = getObj(elemId);
var prop=propName.substring(0,1).toUpperCase()+propName.substring(1,propName.length); //capitalize 1st letter of propName: left => Left
prop = 'offset'+prop; //proprietatea se numeste de ex offsetLeft
var elemProp =  eval('elemObj.'+prop);
return elemProp;
// document.defaultView.getComputedStyle(elemObj, "").getPropertyValue(propName)
}
function showProp(elemId) { //afishare left, top pentru un element dat prin ID
 var elemL = getElemProperty(elemId,'left');
 var elemT = getElemProperty(elemId,'top');
 var elemH = getElemProperty(elemId,'height');
 var elemW = getElemProperty(elemId,'width');
 alert('The "'+elemId+'" element has:\n Left='+elemL+'\n Top='+elemT+'\n Width='+elemW+'\n Height='+elemH);
}
//functii pentru foooter:
function setElemProperty(elemId, propName, newValue, isStr) { //ex: setElemProperty('top','height','36', false); 
 var elemObj = getObj(elemId); //isStr arata daca e nevoie ca newValue sa fie considerat string; ex:"hidden" - e pus intre ""
 var newVal = isStr ? '"'+newValue+'"' : newValue; //daca newVal e string (ca la "visible") => se pune intre ghilimele
 //alert('Parametrul newVal='+newVal);
 var evalString = 'elemObj.style.'+propName+'='+newVal;
 eval(evalString);
}

function getWindowHeight() { //returneaza inaltime frame continut, pt ca e apelata din frame-ul content
 var wndH; //window height
 wndH = document.all ? document.body.clientHeight : document.getElementById ? window.innerHeight : 673;  //673 = 768 (inaltime de la 1024x768)- 95 (inaltime frame top)
 return wndH;
}

function getWindowWidth() { //returneaza latime frame continut, pt ca e apelata din frame-ul content
 var wndW; //window width
 wndW = document.all ? document.body.clientWidth : document.getElementById ? window.innerWidth : 612;  //612 = 800 - (20+168) ...20 de la scrollbars...in IE!
 return wndW;
}

function putFooter() {
  var windH = getWindowHeight(); //
  var footerH = getElemProperty('footer','height');//
  var containerH = getElemProperty('container','height');//
	var containerT = getElemProperty('container','top');
  //var bodyH = getElemProperty('body','height');
	//alert('Inainte, de pozitionare DIV, footer are H='+footerH+'\n containerH='+containerH); 
	var footerT = windH - footerH ;//
	footerT = (footerT < (containerH + containerT + 10) ) ? containerH + containerT + 10 : footerT ;//
  setElemProperty('footer','top', footerT.toString(), false);//
	//setElemProperty('footer','left', tableL.toString(), false);//
	setElemProperty('footer','visibility', 'visible', true);//
}

var menuNamesArray = new Array('sciteam','acttasks','results'); //array nume meniuri
//var menuOffset = new Array();

//var menubarLeftOffset = parent.menu.getElemProperty('menubar','left'); //offset left al barei de meniuri

function changeMenusLeftOffsets() { //functia este declansata cand se incarca meniul principal, si trebuie sa actioneze numai dupa ce pagina actuala s-a incarcat (???oare???)
 //alert('Functia \"changeMenusLeftOffsets\" arata ca:\nleftsideWidth='+leftsideWidth);
 menubarLeftOffset = parent.menu.getElemProperty('menubar','left'); //offset left al barei de meniuri
 wndW = getWindowWidth(); //latime frame content
 if (parent.menu.menuOffsetsCalculated) {  
  for (var i=0; i < menuNamesArray.length ; i++) {
	  var crtContainerId = menuNamesArray[i] + 'Container';
		var crtContainerObj = getObj(crtContainerId);
		var isLowRes = ((screen.width<=800)&&(screen.height<=600)); //test rezolutie joasa
		if (menuNamesArray[i] == 'sciteam') { //singurul care se potriveste asa cum este, adica nu depaseste latimea ferestrei la 800x600
		   crtContainerObj.style.left = parent.menu.menuOffset[i]+menubarLeftOffset-leftsideWidth; //leftsideWidth = latimea frame-ului "left" ; e definita ca valoare mai sus
		}
		else { //e unul din celelalte doua divuri care depasesc latimea admisa la rezolutie joasa
		  if (isLowRes) {
			  var crtContainerWidth = getElemProperty(crtContainerId,'width');
				crtContainerObj.style.left = wndW - crtContainerWidth - 20 ; // latime continut - latime container - 20  (20 = marja scrollbars)...
			}
			else { //se calculeaza ca si restul, daca nu e rezolutie joasa
			  crtContainerObj.style.left = parent.menu.menuOffset[i]+menubarLeftOffset-leftsideWidth; //leftsideWidth = latimea frame-ului "left" ; e definita ca valoare mai sus
			}
		}	 
	}
 }
 else {
  setTimeout('changeMenusLeftOffsets()',333);
 }
}

/// functie de schimbare a pozitiei submeniurilor in caz de scroll sus/jos si/sau stanga/dreapta
function changeMenusLeftOffsetsOnScroll(deltaX, deltaY) {
  var isLowRes = ((screen.width<=800)&&(screen.height<=600)); //test rezolutie joasa
  for (var i=0; i < menuNamesArray.length ; i++) {
	  var crtContainerId = menuNamesArray[i] + 'Container';
		var crtContainerObj = getObj(crtContainerId);
		if (!isLowRes) {
		    crtContainerObj.style.left = parent.menu.menuOffset[i]+menubarLeftOffset-leftsideWidth + deltaX;
		}
		else {
		    var crtContainerWidth = getElemProperty(crtContainerId,'width');
				if (menuNamesArray[i] != 'sciteam'){ //pt cele doua submeniuri care depasesc largimea
				   crtContainerObj.style.left = wndW - crtContainerWidth - 20 + deltaX;
				}
				else { //meniu sciteam!!!
				   crtContainerObj.style.left = parent.menu.menuOffset[i]+menubarLeftOffset-leftsideWidth + deltaX;
				}  
		}			
		crtContainerObj.style.top = deltaY; //pt ca initial top=0 pt fiecare submeniu...
	}  
}

function changeLeftOption() {
 if (parent.left.pageLoaded) {
    parent.left.changeOption(optionIndex); //schimbare optiune curenta in meniul de navigare rapida
 }
 else {
     setTimeout('changeLeftOption()',333);
 }
}

function finish() { 
 changeMenusLeftOffsets(); //schimbare offset left ale submeniurilor
 //changeLeftOption(); //schimbare optiune curenta in meniul de navigare rapida in pagina leftside_lr/hr.html
 //parent.left.changeOption(optionIndex); //schimbare optiune curenta in meniul de navigare rapida
}

function writeMenuDivs() { //functie ce trebuie apelata in fiecare pagina de continut pentru a scrie layerele submeniurilor in pagina repsectiva  
	document.write('<DIV id="sciteamContainer"><DIV class="menu" id="sciteamContent"><DIV class="options"><A href="nihwm.html">NIHWM</A><A href="nimh.html">NAM</A><A href="wdsiret.html">WD SIRET</A><A href="upmc.html">UPMC</A><A href="naar.html">NAAR</A></DIV></DIV></DIV>');
	//document.write('<DIV id="distrContainer"><DIV class="menu" id="distrContent"><DIV class="options"><A href="distribuitori.html">In tara</A><A href="ofdistr.html">Oferta</A></DIV></DIV></DIV>');
	document.write('<DIV id="acttasksContainer"><DIV class="menu" id="acttasksContent"><DIV class="options"><A href="data.html">Data Collection &amp; Surveying</A><A href="modelintegration.html">Integration of models towards Open-GIS</A><A href="iointegration.html">Integration of the inputs/outputs into the Open-GIS On-line</A><A HREF="envcosts.html">Environmental costs assessements</A><A HREF="opensys.html">Open systems for the dissemination of the management assessments</A><A HREF="management.html">Management</A><A HREF="dissemination.html">Dissemination</A></DIV></DIV></DIV>');
	document.write('<DIV id="resultsContainer"><DIV class="menu" id="resultsContent"><DIV class="options"><A href="campaigns.html">Measurement campaigns</A><A href="monwork.html">Monitoring work</A><A href="mathmodels.html">Mathematical models</A><A href="regmodeling.html">Regional modeling</A><A HREF="maps.html">Maps GIS</A><A HREF="onlgis.html">On-line GIS systems</A></DIV></DIV></DIV>');
	//document.write('<DIV id="contContainer"><DIV class="menu" id="contContent"><DIV class="options"><A href="/_/sed.html">Sediu</A><A href="/_/mag.html">Magazin</A></DIV></DIV></DIV>');
  //document.write('<DIV id="angContainer"><DIV class="menu" id="angContent"><DIV class="options"><A href="/_/cv.html">Trimitere CV</A><A href="/_/ofertejob.html">Oferte</A></DIV></DIV></DIV>');
}

function initSpy() { // se pune inainte de cod footer al fiecarei pagini de content pentru a initia spy la scroll, la intervale regulate...
 var S = new scrollSpy(changeMenusLeftOffsetsOnScroll); //creare nou obiect scrollSpy si atasare de functia parametru respectiva 
 S.start();
}
