// JavaScript Document
// <meta http-equiv="Content-Type" content="text/html; charset=windows-1251">

isNS = (navigator.appName == 'Netscape');
isIE = (navigator.appName.indexOf('Microsoft') != -1);
isOP = (navigator.appName == 'Opera');
ns4 = (document.layers);
ie4 = (document.all && !document.getElementById);
ie5 = (document.all && document.getElementById);
ns6 = (!document.all && document.getElementById);

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

// main menu stuff ===================================================================
var vMenu = new Object();
vMenu.IDs = ['100', '200', '201', '202', '203', '204', '300', '301', '302', '303', '304', '305', '306', '400', '401', '402', '403', '404', '1900', '1901', '1902', '1903', '1904', '1905', '1908', '1909', '1910', '1911', '500', '501', '502', '503', '504', '600', '601', '602', '603', '700', '800', '801', '802', '803', '804', '805', '807', '808', '809', '900', '901', '902', '903', '904', '1000', '1100', '1200', '1300', '1400', '1401', '1402', '1403', '1800', '1500', '1600'];
vMenu.URIs = ['index.php : _self',
							'#',
							'bg/dryanovo/mestopolojenie.htm : sredna',
							'#',
							'#' ,
							'#',
							'#',
							'bg/obst_syvet/funkcii.htm : sredna',
							'bg/obst_syvet/syvetnici.htm : sredna',
							'bg/obst_syvet/komisii.htm : sredna',
							'bg/obst_syvet/protokoli.php : sredna',
							'bg/obst_syvet/naredbi.php : sredna',
							'http://www.obs-dryanovo.com/ : blank_',
							'#',
							'bg/kmetove/rykovodstvo.htm : sredna',
							'bg/kmetove/kmetove.htm : sredna',
							'bg/kmetove/obsta_administracia.htm : sredna',
							'bg/kmetove/sp_administracia.htm : sredna',
							'#',
							'bg/upravlenie/upravlenie.php?kat_id=1 : sredna',
							'bg/upravlenie/upravlenie.php?kat_id=2 : sredna',
							'bg/upravlenie/upravlenie.php?kat_id=3 : sredna',
							'bg/upravlenie/upravlenie.php?kat_id=4 : sredna',
							'bg/upravlenie/upravlenie.php?kat_id=5 : sredna',
							'bg/upravlenie/upravlenie.php?kat_id=8 : sredna',							
							'bg/upravlenie/upravlenie.php?kat_id=9 : sredna',		
							'bg/upravlenie/upravlenie.php?kat_id=11 : sredna',		
							'bg/upravlenie/upravlenie.php?kat_id=22 : sredna',									
							'#',
							'bg/uslugi/admin.htm : sredna',
							'bg/uslugi/tehn.htm : sredna',
							'bg/uslugi/tsu.htm : sredna',
							'bg/uslugi/mestni.htm : sredna',
							'#',
							'bg/infrastruktura/transport.htm : sredna',
							'#',
							'bg/infrastruktura/energo.htm : sredna',
							'#',
							'#',
							'bg/kultura/muzei.htm : sredna',
							'bg/kultura/chitalista.htm : sredna',
							'bg/kultura/hramove.htm : sredna',
							'bg/kultura/pametnici_na_kulturata.htm : sredna',
							'bg/kultura/kulturni_marshruti.htm : sredna',
							'bg/kultura/tradicii_folklor.htm : sredna',
							'download/Kulturen-kalendar-2011.doc : blank_',
							'bg/upravlenie/upravlenie.php?kat_id=10 : sredna',							
							'#',
							'bg/turizym/hoteli.htm : sredna',
							'bg/turizym/hranene.htm : sredna',
							'bg/turizym/marshruti.htm : sredna',
							'bg/turizym/obekti.htm : sredna',
							'bg/obrazovanie/index.htm : sredna',
							'bg/zdrave/zdrave.htm : sredna',
							'bg/mladejki/mladejki.htm : sredna',
							'bg/socialni/socialni.htm : sredna',
							'#',
							'bg/sport/sport_clubs.htm : sredna',
							'bg/sport/sport_baza.htm : sredna',
							'download/sporten_kalendar_2011.doc : blank_',									
							'bg/komisiq/komisiq.htm : sredna',
							'bg/npo.htm : sredna',
							'bg/kontakti/kontakti.htm : sredna'];

var nWait = new Number();

function findCmd(ID) {
	var i = 0;
	for (i in vMenu.IDs) {
		if (vMenu.IDs[i] == ID) return i;
	}
	return i;
}

function menuCmd(ID, p) {
	var _cmd = findCmd(ID);
	var _tStr = vMenu.URIs[_cmd];
	var _parseURI = _tStr.split(' : ');
	var _url = (_parseURI[0] == '#') ? '#' : _parseURI[0];
	var _targ = (_parseURI[1] == undefined) ? '' : _parseURI[1];
//	var _path = (p == undefined) ? '' : './';
	var tmp = ' href="' + _url + '" target="' + _targ +'"';
	return tmp;
}

function content(ID, what) { // layer id and content
	if (ie5 || ns6 || isOP) document.getElementById(ID).innerHTML = what;  
} 

function addItem(ID) {
	var tmp = '';
	var id = Number(ID);
	if (id%100 == 0) {
		tmp = '<div class="vmenu-nav"><a '+menuCmd(ID)+' onMouseDown="doIt('+ID+'); this.blur(); return false"><img src="./images/butoni/but_'+ID+'.png" width="156" height="23" border="0"></a></div>';
	} else {
		tmp = '<div class="vmenu-sub"><a '+menuCmd(ID)+' onClick="this.blur()"><img src="./images/butoni/but_'+ID+'.png" width="156" height="23" border="0"></a></div>';
	}
	return tmp;
}

//function addSubMenus(ID) {
function addSubMenus() {
	var ID = this.active;
	var tmp = '';
	var id = Number(ID);
	var i = 0;
	var iTmp = 0;

	//clearTimeout(nWait);
	window.clearTimeout(this.timerId);	
	for (i in vMenu.IDs) {
		if (id/100 == Math.floor(Number(vMenu.IDs[i])/100)) {
			tmp += addItem(vMenu.IDs[i]);
		} else {
			if (Number(vMenu.IDs[i])%100 == 0) tmp += addItem(vMenu.IDs[i]);
		}
	}
	content('vmenu', tmp);
	
	o++;
}

var o = 0;
function doIt(ID) {
	this.active = ID;
	if (this.timerId != undefined) {
		window.clearTimeout(this.timerId);
	}
	this.timerId = window.setTimeout("addSubMenus()", 200);
}

var imageList=new Array(); 

function initMenu () {
	var tmp = '';
	var id = 0;
	var i = 0;
	var images=new Array(); 
	for (i in vMenu.IDs) {
		id = Number(vMenu.IDs[i]);
		if (id%100 == 0) tmp += addItem(id);
		images[i] = './images/butoni/but_'+id+'.png';
	}
	for (i in images) {  // preloading imgs
  	imageList[i]=new Image(); 
  	imageList[i].src=images[i]; 
  } 
	content('vmenu', tmp);
	
}

// end of main menu stuff ==============================================================
function swap_img(img_src, img_txt) {
  var obj = document.getElementById('snimka');
  var obj2 = document.getElementById('img_tåxt');
	obj.src = img_src;
	obj2.innerHTML = img_txt; 
}

function crawler() {
	if (window.name!='sredna' && !((self.innerHeight == 0) && (self.innerWidth == 0))) top.location.replace('/index.php');
}
function calcHeight_admin(koi) {
	var the_height=document.body.scrollHeight;
	var obj = parent.document.getElementById(koi);
	obj.style.height = (!isNS && !isOP) ? the_height : the_height+'px';
}

function calcHeight(koi) {
	crawler();
	var the_height = document.body.scrollHeight;
	var obj = parent.document.getElementById(koi);
	obj.style.height = the_height + 'px';
	obj.style.height = (!isNS && !isOP) ? the_height : the_height+'px';
}

function sh_div(what) {
	 var i=0;
	 var coll = [];
	 while (document.getElementById('d'+ i)) {
	  coll[i] = document.getElementById('d'+ i);
		i++;
	 }
 obj = document.getElementById(what);
 var i=0;
 if (obj.className == 'off') {
	 while (coll[i]) {
		coll[i].className = 'off';
		i++;
		} 
	obj.className = 'on';
 } else {
	obj.className = 'off';
 }
 calcHeight('sredna');
}


