// JavaScript Document
//FadeIn();

AddMenu();

var currentLink;

function FadeIn(event) {
	var href = this.firstChild.href;
		
	if(!$.browser.opera && href != undefined) {
		if(event.preventDefault) {
			event.preventDefault();
		} else {
			event.returnValue = false;
		}		
		currentLink = href;		
		
		if(currentLink.indexOf('#') == -1) {
			$("body").animate({
				opacity : "hide"
			}, "slow", "", ChangeLocation);
		}
	}	
	event.stopPropagation();
}

function ChangeLocation() {
	window.location = currentLink;
}

function AddMenu() {
	var li = new Array();

	li.push(document.createElement('li'));
	li[0].appendChild(CreateAnchor("Главная", "index.html"));

	li.push(document.createElement('li'));
	li[1].appendChild(CreateAnchor("Обучение", "training.html"));

	li.push(document.createElement('li'));
	li[2].appendChild(CreateAnchor("Новости Клуба", "#"));

	var liNews = new Array();
	liNews.push(document.createElement('li'));
	liNews[0].appendChild(CreateAnchor("Планируемые приключения", "plans.html"));
	liNews.push(document.createElement('li'));
	liNews[1].appendChild(CreateAnchor("Отчеты о погружениях", "reports.php"));
	li[2].appendChild(AddSimpleList(liNews));

	li.push(document.createElement('li'));
	li[3].appendChild(CreateAnchor("о Клубе", "about.html"));

	li.push(document.createElement('li'));
	li[4].appendChild(CreateAnchor("Контакты", "contacts.html"));		
	
	var menu = document.getElementById("menu");	
	menu.appendChild(AddSimpleList(li));
	
	var allLi = menu.getElementsByTagName('li');	
	for(var i = 0; i < allLi.length; i++) {
		allLi[i].onclick = FadeIn;
	}
}

function CreateAnchor(text, href) {
	var a = document.createElement('a');
	
	a.href = href;	
	//a.onclick = FadeIn;
	a.innerHTML = text;
	return a;
}

function AddSimpleList(items) {
	var ul = document.createElement('ul');

	for(var i = 0; i < items.length; i++) {
		ul.appendChild(items[i]);
	}
	return ul;
}
