
var _nav_ = jQuery('#left-nav');

jQuery(window).ready(function () {
	_nav_.find("li[id^='ncmd']").click(function (e) {
		var id = this.id.substring(4);
		// Compute css class to add.
		var                klass   = 'blue-on';   // 1 to 5
		if (id == 6)       klass   = 'orange-on';
		else if (id == 7)  klass   = 'brown-on';
		// Close all opened menu.
		_nav_.find("li[id^='nsub']").slideUp('slow');
		_nav_.find("li[id^='ncmd']").removeClass('blue-on').removeClass('orange-on').removeClass('brown-on');
		// Open the correct menu.
		_nav_.find('#ncmd' + id).addClass(klass);
		_nav_.find('#nsub' + id).slideDown('slow');
	});


	_nav_.find("li[id^='rub']").click(function (e) {
		var id = this.id;
		// Destect language.
		var lang = 'en';
		if (document.location.href.indexOf('/fr/') != -1)        lang = 'fr';
		else if (document.location.href.indexOf('/es/') != -1)   lang = 'es';
		// Base url.
		var base = '/public/cdwbv3/html/' + lang;
		if (id == 'rub0-srub0') {
			document.location.href = base + '/espace_formation/formation_medicale/pratiques/formations.php';
		}
		else if (id == 'rub13-srub1') {
			document.location.href = base + '/espace_formation/formation_medicale/cascliniques/cascliniques.php';
		}
		else if (id == 'rub14-srub2') {
			document.location.href = base + '/espace_formation/formation_medicale/diaporama/cours.php';
		}
		else if (id == 'rub15-srub3') {
			document.location.href = base + '/espace_formation/formation_medicale/fiche_dermato/index.php';
		}
		else if (id == 'rub1-srub0') {
			document.location.href = base + '/espace_formation/bdd/toxidermie/home.php';
		}
		else if (id == 'rub1-srub1') {
			document.location.href = base + '/espace_formation/bdd/dermatotherap/index.php';
		}
		else if (id == 'rub1-srub2') {
			document.location.href = 'http://www.therapeutique-dermatologique.org/listarticle.php';
		}
		else if (id == 'rub1-srub3') {
			document.location.href = 'http://www.ncbi.nlm.nih.gov/sites/entrez?db=pubmed';
		}
		else if (id == 'rub12-srub0') {
			document.location.href = base + '/espace_formation/actu_biblio/accueil.php';
		}
		else if (id == 'rub11-srub0') {
			document.location.href = base + '/espace_formation/utiles/site/home.php';
		}
		else if (id == 'rub11-srub1') {
			document.location.href = base + '/espace_formation/utiles/revue/home.php';
		}
		else if (id == 'rub2-srub1') {
			document.location.href = base + '/espace_formation/presse/home.php?page=dermofocus';
		}
		else if (id == 'rub2-srub2') {
			document.location.href = base + '/espace_formation/presse/home.php?page=keratin';
		}
		else if (id == 'rub2-srub3') {
			document.location.href = base + '/espace_formation/presse/home.php?page=ihn';
		}
		else if (id == 'rub2-srub4') {
			document.location.href = base + '/espace_formation/presse/home.php?page=laser';
		}
		else if (id == 'rub2-srub5') {
			document.location.href = base + '/espace_formation/presse/home.php?page=acne';
		}
		else if (id == 'rub2-srub6') {
			document.location.href = base + '/espace_formation/presse/home.php?page=ongle';
		}
		else if (id == 'rub2-srub7') {
			document.location.href = base + '/espace_formation/presse/home.php?page=hi-news';
		}
		else if (id == 'rub2-srub8') {
			document.location.href = base + '/espace_formation/presse/home.php?page=da-on-line';
		}
		else if (id == 'rub3-srub0') {
			document.location.href = base + '/espace_formation/congres_symposium/accueil_congres.php';
		}
		else if (id == 'rub3-srub1') {
			document.location.href = base + '/espace_formation/congres_symposium/symposia.php';
		}
		else if (id == 'rub4-srub0') {
			document.location.href = base + '/espace_formation/utiles/pdf/index.php';
		}
		else if (id == 'rub19-srub0') {
			document.location.href = '/public/cdwbv3/html/common/forum/index.php';
		}
		else if (id == 'rub16-srub0') {
			document.location.href = '/front/' + lang + '/communaute/quiz/cas-cliniques/index.html';
		}
		else if (id == 'rub17-srub0') {
			document.location.href = '/front/' + lang + '/communaute/quiz/dermatoscopie/index.html';
		}
		else if (id == 'rub6-srub0') {
			document.location.href = base + '/espace_communaute/annuaire/membres/detail.php';
		}
		else if (id == 'rub6-srub1') {
			document.location.href = base + '/espace_communaute/annuaire/experts/result.php';
		}
		else if (id == 'rub7-srub0') {
			document.location.href = base + '/espace_communaute/associations/index.php';
		}
		else if (id == 'rub8-srub0') {
			document.location.href = base + '/espace_communaute/dermanews/archives.php';
		}
		else if (id == 'rub9-srub0') {
			document.location.href = base + '/espace_culture/art_histoire/petites_histoires/accueil.php';
		}
	});
});

function setNavOn(rub, srub) {
	var li = _nav_.find('#rub' + rub + '-srub' + srub);
	var p = li.parents("li[id^='nsub']");
	if (p.length) {
		var k = p.attr('class');
		if (k == 'sub1') p.prev().addClass('blue-on');
		else if (k == 'sub2') p.prev().addClass('orange-on');
		else if (k == 'sub3') p.prev().addClass('brown-on');
		p.slideDown('slow');
	}
	else {
		var c = li.attr('class');
		if (c == 'blue')         li.addClass('blue-on');
		else if (c == 'orange')  li.addClass('orange-on');
		else if (c == 'brown')   li.addClass('brown');
	}
	li.addClass('on');
}

