$(document).ready( function() {

	$("#news").fadeIn("slow");

	$("#logo").click( function() {
		var url = "index.php";
		$(location).attr('href', url);
		return false;
	});

	// modification de langue
		$("#langue_switch").click( function() {
			var lang = $('#lang').val();
			var url = "index.php";
			if (lang == "EN") {
				url = "indexGR.php";
				$('body').data('lang', "GR");
			} else {
				$('body').data('lang', "EN");
			}
			$(location).attr('href', url);
			return false;
		});

		function menu(el) {
			$("#menu_media").slideUp("fast");
			$("#menu_copyright").slideUp("fast");
			$("#menu_contact").slideUp("fast");
			$("#menu_ressources").slideUp("fast");
			$("#menu_itc").slideUp("fast");
			el.slideDown("slow");
		}

		// menu de droite
		
		$("#copyright").click( function() {
			var cible = $("#menu_copyright");
			menu(cible);

			return false;
		});

		$("#itc").click( function() {
			var cible = $("#menu_itc");
			menu(cible);
			return false;
		});

		$("#media").click( function() {
			var cible = $("#menu_media");
			menu(cible);
			return false;
		});

		$("#contact").click( function() {
			var cible = $("#menu_contact");
			menu(cible);
			return false;
		});

		$("#ressources").click( function() {
			var cible = $("#menu_ressources");
			menu(cible);
			return false;
		});

		// fin menu

		// les liens profonds
		$(".liens").live("click", function() {
			var nom_lien = $(this).attr("id");
			var lang = $('#lang').val();
			if (lang == "EN") {
				var lien = "./data/" + nom_lien + ".php";
			} else {
				var lien = "./data/" + nom_lien + "GR.php";
			}
			$('#content').hide().load(lien, function() {
				// + effets de tabs
				if (nom_lien == "report" || nom_lien == "thesis") {
					$(".tab_content").hide(); //Hide all content
					$("ul.tabs li:first").addClass("active").show(); //Activate first tab
					$(".tab_content:first").show(); //Show first tab content
				}	
			}).fadeIn("slow");
			
			$("#news").hide();
			$("#menuguest").hide();
			
			return false;
		});
		
		
		// tabs
		$("ul.tabs li").live("click", function() {
			$("ul.tabs li").removeClass("active"); //Remove any "active" class
			$(this).addClass("active"); //Add "active" class to selected tab
			$(".tab_content").hide(); //Hide all tab content

			var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
			$(activeTab).fadeIn(); //Fade in the active ID content
			return false;
		});
		
		// liens des news
		$(".choix_news").click( function() {
			var nomlien = $(this).attr("id");
			var reg = new RegExp("[_]+", "g");
			var tableau = nomlien.split(reg);
			var numlien = tableau[1];
			$.post("ajaxnews.php", {
				idnews : numlien
			}, function(data) {
				$("#firstnews").hide().fadeIn("slow").html(data);
			});
		});
		

	});
