/**
 * Funkcje obsługujące menu rozwijane informatora/mapy
 * @author Alfred Broda
 */

/**
 * Funkcja (ro)zwijająca Listę obiektów
 * @param {Number} id
 * @param {String} url
 * @param {Object} effect
 */
function toggleList(id, get_url, list_url) {
	if (navigator.appName == "Microsoft Internet Explorer") {
		var listName = document.getElementById('name_'+id); 
		if (listName.className == 'menu_level_sub') {
			var ikat = document.getElementById('ikat_'+id);
			if(ikat!=null){
			new Ajax.Updater('ikat_' + id, list_url, {
				onComplete: function(){
					if (typeof(showCat)=='function') showCat(get_url);
				}, 
				onSuccess: function(ret){
					if (ret.status == 200) {
						listName.className =  'menu_level_sub_selected';
						Element.show('ikat_'+id);
					}
				},
				onFailure: function(){return false}
				})
			}
		} else {
			listName.className = 'menu_level_sub';
			document.getElementById('ikat_' + id).innerHTML = '';
			if (hideCat) hideCat(id);
			Element.hide('ikat_'+id);
		}
	} else {
		var listName = $('name_'+id);
		//var wait = $('wait_'+id);
		if (!listName) {
			if (showCat) showCat(get_url);
		} else if ((listName.getAttribute('class') == 'menu_level_sub')&&listName) {
			if (showCat) showCat(get_url);
			if($('ikat_'+id)){
				new Ajax.Request(list_url, {
				onComplete: function(){
					//wait.setAttribute('class', 'point_level2');
					foldList('ikat_'+id);
				},
				onSuccess: function(ret){
					if (ret.status == 200) {
						document.getElementById('ikat_' + id).innerHTML = ret.responseText;
						listName.setAttribute('class', 'menu_level_sub_selected');
					}
				},
				onFailure: function(){return false}/*,
				onLoading: wait.setAttribute('class', 'wait') */
				})
			}
		} else if(listName) {
			listName.setAttribute('class', 'menu_level_sub');
			if (hideCat) hideCat(id);
			foldList('ikat_'+id);
		} else if (hideCat) hideCat(id);	
	}
} 

function foldList(name) {
	ShowHideMenuItems(name);
}

/**
 * Funkcja uruchamiająca funkcję dodania do ulubionych przeglądarki
 * @param {String} title
 * @author Bartosz "BTM" Szczeciński
 * @author Przemysław Wesołowski
 * @author Alfred Broda
 * 
 */
function ulubione(obj)
{
	var title = document.title;
	var url = document.location;
	if (window.sidebar)
	{
		window.sidebar.addPanel(title, url,"");
		obj.href="#";
		return false;
	}
	else if (window.external)
	{
		window.external.AddFavorite(url, title);
		obj.href="#"; 
		return false;
	}
	else if (window.opera && window.print)
	{
		obj.rel = 'sidebar';
		obj.title = title;
		obj.href = url;
		return true;
	}
	return false;
}
