function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

var format = "ft";
var offre = "ot";
var duree = "dt";
var zone = "zt";
var profil = "pt";
var offre_abo = $("#abo li:hidden").size(); 
$(function(){
    getUrlVars();
	var uriCourant = document.location.pathname.replace('/content/2_', '');
	var uriCourant = uriCourant.replace('/content/', '');
	var uriCourant = uriCourant.replace('/index/2_', '');
	var uriCourant = uriCourant.replace('/listweb', '');
	var uriCourant = uriCourant.replace('/article', '');
	var uriCourant = uriCourant.replace('/numero', '');
	var uriCourant = uriCourant.replace('/html/aide/', '');
	var uriCourant = uriCourant.replace('/html/', '');
	var uriCourant = uriCourant.replace('.jsp', '');
    var topicId='';
    var typeContenu=' contenu';
	var menuCourant='vide';
	var sousMenuCourant='vide';
	if(uriCourant=="/user/disconnect"){document.location.href="http://www.magazine-litteraire.com";}
	if(uriCourant=="/"){                   menuCourant='actualite'; sousMenuCourant='accueil';topicId='17909';typeContenu='e actualit&eacute;';}
	if(uriCourant=="homepage"){            menuCourant='actualite'; sousMenuCourant='accueil';}
	if(uriCourant=="breves"){              menuCourant='actualite'; sousMenuCourant='fildeslettres';topicId='17908';typeContenu='e br&egrave;ve';}
	if(uriCourant=="critique-fiction"){    menuCourant='critique';  sousMenuCourant='fiction';topicId='17899';typeContenu='e critique de fiction';}
	if(uriCourant=="critique-non-fiction"){menuCourant='critique';  sousMenuCourant='nonfiction';topicId='17900';typeContenu='e critique non-fiction';}
	if(uriCourant=="critique-poesie"){     menuCourant='critique';  sousMenuCourant='poesie';topicId='17901';typeContenu='e critique de po&eacute;sie';}
	if(uriCourant=="critique-polar"){      menuCourant='critique';  sousMenuCourant='polar';topicId='17902';typeContenu='e critique de polar';}
	if(uriCourant=="agenda-exposition"){   menuCourant='agenda';    sousMenuCourant='exposition';topicId='17906';typeContenu='e exposition';}
	if(uriCourant=="agenda-rencontre"){    menuCourant='agenda';    sousMenuCourant='rencontre';topicId='17905';typeContenu='e rencontre';}
	if(uriCourant=="agenda-festival"){     menuCourant='agenda';    sousMenuCourant='festival';topicId='17903';typeContenu=' festival';}
	if(uriCourant=="agenda-colloque"){     menuCourant='agenda';    sousMenuCourant='colloque';topicId='17904';typeContenu=' colloque';}
	if(uriCourant=="agenda-theatre"){     menuCourant='agenda';    sousMenuCourant='theatre';topicId='17904';typeContenu=' theatre';}
	if(uriCourant=="editorial"){           menuCourant='autre';     sousMenuCourant='editorial';}
	if(uriCourant=="blog"){                menuCourant='autre';     sousMenuCourant='blog';topicId='17917';typeContenu=' blog';}
	if(uriCourant=="dossiers"){           menuCourant='dossiers'; sousMenuCourant='dossiers';}
	if(uriCourant=="ecrivains"){           menuCourant='ecrivains'; sousMenuCourant='ecrivains';}
	if(uriCourant=="communaute"){           menuCourant='communaute'; sousMenuCourant='communaute';}
	if(uriCourant=="/pool/show_results" || uriCourant=="pool/new_vote?idReponse=30&idSondage=13"){
		                                   menuCourant='autre';     sousMenuCourant='sondage';topicId='17918';typeContenu=' sondage';}     
	if(uriCourant=="/search/"||uriCourant=="/search/recherche/"){
		                                   menuCourant='autre';     sousMenuCourant='glossaire';topicId='17940';typeContenu=' mot cl&eacute;';
		var rtype = getUrlVars()["type"];
		if(rtype=="auteur"){                                        sousMenuCourant='auteur';topicId='17942';typeContenu=' auteur';}
		if(rtype=="med"){                                           sousMenuCourant='med';topicId='17941';typeContenu='e maison d\'&eacute;dition';}
	}
	if(uriCourant=="/search/Recherche/resultats"||uriCourant=="/search/recherche.php"){
		                                   menuCourant='autre';     sousMenuCourant='recherche';}
	
	if(uriCourant=="/EdNum/mens/"){menuCourant='autre';sousMenuCourant='ednum';}
	
	var hostCourant= document.location.hostname.replace('.magazine-litteraire.com','');
	if(hostCourant=="numerique"){menuCourant='ednum';sousMenuCourant='ednum';}
	if(hostCourant=="newsletters"){menuCourant='';sousMenuCourant='newsletter';} 
	
	if(uriCourant=="/inscription/"||uriCourant=="/desinscription/"){menuCourant='autre';sousMenuCourant='newsletter';}
	if(uriCourant=="/store/window/ViewWindow"){
		var id = getUrlVars()["id"];if(id>=9){menuCourant='boutique'; sousMenuCourant='mensuel';}
		var id = getUrlVars()["id"];if(id==6){menuCourant='boutique'; sousMenuCourant='pack';}
		var id = getUrlVars()["id"];if(id==30){menuCourant='boutique'; sousMenuCourant='horserie';}
		var id = getUrlVars()["id"];if(id==32){menuCourant='boutique'; sousMenuCourant='essentiel';}
		var id = getUrlVars()["id"];if(id==1){menuCourant='boutique'; sousMenuCourant='ecrin';}
		var id = getUrlVars()["id"];if(id==2){menuCourant='abonnement'; sousMenuCourant='abo';}
    }
	if(uriCourant=="/contact/add_contact"){menuCourant='contact';
		var theme = getUrlVars()["theme"];
		var from = getUrlVars()["from"];
		if(theme=="Redaction"){sousMenuCourant='redaction';if(from=="web"){sousMenuCourant='redacweb';}}
		if(theme=="Webmaster"){sousMenuCourant='web';}
		if(theme=="Pub"){sousMenuCourant='publicite';}
		if(theme=="Abonnements"){sousMenuCourant='abo';}
		if(theme=="VPC"){sousMenuCourant='vpc';}
	}
	
	if(uriCourant=="numero.php" || uriCourant=="index.php" || uriCourant=="recherche" || uriCourant=="/search/recherche/resultats" || uriCourant=="/index/" || uriCourant=="/index/2_numero.php"){menuCourant='autre';sousMenuCourant='recherche';}
	
	if(uriCourant=="/store/window/ViewWindow?id=2"){menuCourant='abonnement';}
	if(uriCourant=="/contact/add_contact" || uriCourant=="/contact/list"){menuCourant='contact';}
	
	$("#nav ."+menuCourant).show();
	$("#nav ."+menuCourant+" a").addClass("actif");
	$("#nav2 ."+menuCourant).show();
	$("#nav2 ."+sousMenuCourant+" a").addClass("actif");

	if($('.slickbox').length){
		$(".slickbox").hide();
		$(".slickshow").show();
		$(".slickshow").click(function(){
			$(".slickbox").toggle();
		});
	}

	if($('a#comment').length){
		$("a#comment").click(function(){
			$("#commentaires").show();
		});
	}

	if($('.radio').length){
		$('.radio').click(function() {
			if ($(".radio").is(":checked")) {
				$(".btn_vote").removeAttr("disabled");
			} else {
				$(".btn_vote").attr("disabled", true);
			}
		});
	}
	
	if($('.critiques').length){
	   	$(".critiques a.fiction").hover(function(){
			$("ul.critiques").hide();
			$("ul#fiction").show();
		});
		$(".box.critiques a.nonfiction").hover(function(){
			$("ul.critiques").hide();
			$("ul#nonfiction").show();
		});
		$(".box.critiques a.poesie").hover(function(){
			$("ul.critiques").hide();
			$("ul#poesie").show();
		});
		$(".box.critiques a.polar").hover(function(){
			$("ul.critiques").hide();
			$("ul#polar").show();
		});
	}
	
    /*$(".accordion").accordion();*/
	if($('#commentary').length){
		$('#commentary').wysiwyg({
		    controls: {
		      strikeThrough : { visible : true },
		      underline     : { visible : true },
		      
		      separator00 : { visible : false },
		      
		      justifyLeft   : { visible : false },
		      justifyCenter : { visible : false },
		      justifyRight  : { visible : false },
		      justifyFull   : { visible : false },
		      
		      separator01 : { visible : false },
		      
		      indent  : { visible : false },
		      outdent : { visible : false },
		      
		      separator02 : { visible : false },
		      
		      subscript   : { visible : false },
		      superscript : { visible : false },
		      
		      separator03 : { visible : false },
		      
		      image : { visible : false },
		      undo : { visible : false },
		      redo : { visible : false },
		      
		      separator04 : { visible : false },
		      
		      insertOrderedList    : { visible : false },
		      insertUnorderedList  : { visible : false },
		      insertHorizontalRule : { visible : false },
		      
		      h1mozilla : { visible : false },
		      h2mozilla : { visible : false },
		      h3mozilla : { visible : false },
		      h4mozilla : { visible : false && $.browser.mozilla, className : 'h4', command : 'heading', arguments : ['h4'], tags : ['h4'], tooltip : "Header 4" },
		      h5mozilla : { visible : false && $.browser.mozilla, className : 'h5', command : 'heading', arguments : ['h5'], tags : ['h5'], tooltip : "Header 5" },
		      h6mozilla : { visible : false && $.browser.mozilla, className : 'h6', command : 'heading', arguments : ['h6'], tags : ['h6'], tooltip : "Header 6" },
		
		      h1 : { visible : false },
		      h2 : { visible : false },
		      h3 : { visible : false },
		      h4 : { visible : false && !( $.browser.mozilla ), className : 'h4', command : 'formatBlock', arguments : ['<H4>'], tags : ['h4'], tooltip : "Header 4" },
		      h5 : { visible : false && !( $.browser.mozilla ), className : 'h5', command : 'formatBlock', arguments : ['<H5>'], tags : ['h5'], tooltip : "Header 5" },
		      h6 : { visible : false && !( $.browser.mozilla ), className : 'h6', command : 'formatBlock', arguments : ['<H6>'], tags : ['h6'], tooltip : "Header 6" },
		      
		      separator05 : { visible : false },
		      
		      cut   : { visible : false },
		      copy  : { visible : false },
		      paste : { visible : false },
		      separator06 : { visible : false },
		      removeFormat: { visible : false },
		      insertImage:  { visible : false }
		    }
		  });
		  $('.wysiwyg').css('width','445px');
	}
	if($('#abo').length){
		$("#abo li").hide();
	    $("#abo li."+format+"."+offre+"."+duree+"."+zone+"."+profil).show();
		
	    $('.format').each(function() {
	        $(this).click(function() {
				format = $(this).val();
				$("#abo li").hide();
				if ( $(".profil").is(':checked')) {
	                profil="pt";
					$("#abo li."+format+"."+offre+"."+duree+"."+zone+"."+profil).show();
	            } else {
	                profil="pa";
					$("#abo li."+format+"."+offre+"."+duree+"."+zone+"."+profil).show();
	            }
				offre_abo = $("#abo li:hidden").size();
	            if($("#abo li").size()-offre_abo<1){
	                $("#abo li.not").show();
	            }else{
	                $("#abo li.not").hide();
	            }
	        })
	    });
		$('.zone').each(function() {
	        $(this).click(function() {
				zone = $(this).val();
				$("#abo li").hide();
				if ( $(".profil").is(':checked')) {
	                profil="pt";
					$("#abo li."+format+"."+offre+"."+duree+"."+zone+"."+profil).show();
	            } else {
	                profil="pa";
					$("#abo li."+format+"."+offre+"."+duree+"."+zone+"."+profil).show();
	            }
				offre_abo = $("#abo li:hidden").size();
	            if($("#abo li").size()-offre_abo<1){
	                $("#abo li.not").show();
	            }else{
	                $("#abo li.not").hide();
	            }
	        })
	    });
		$('.offre').each(function() {
	        $(this).click(function() {
				offre = $(this).val();
				$("#abo li").hide();
				if ( $(".profil").is(':checked')) {
	                profil="pt";
					$("#abo li."+format+"."+offre+"."+duree+"."+zone+"."+profil).show();
	            } else {
	                profil="pa";
					$("#abo li."+format+"."+offre+"."+duree+"."+zone+"."+profil).show();
	            }
				offre_abo = $("#abo li:hidden").size();
	            if($("#abo li").size()-offre_abo<1){
	                $("#abo li.not").show();
	            }else{
	                $("#abo li.not").hide();
	            }
	        })
	    });
		$('.duree').each(function() {
	        $(this).click(function() {
				duree = $(this).val();
				$("#abo li").hide();
				if ( $(".profil").is(':checked')) {
	                profil="pt";
					$("#abo li."+format+"."+offre+"."+duree+"."+zone+"."+profil).show();
	            } else {
	                profil="pa";
					$("#abo li."+format+"."+offre+"."+duree+"."+zone+"."+profil).show();
	            }
				offre_abo = $("#abo li:hidden").size();
	            if($("#abo li").size()-offre_abo<1){
	                $("#abo li.not").show();
	            }else{
	                $("#abo li.not").hide();
	            }
	        })
	    });
		$('.profil').each(function() {
	        $(this).click(function() {
				
				$("#abo li").hide();
				if ( $(".profil").is(':checked')) {
	                profil="pt";
					$("#abo li."+format+"."+offre+"."+duree+"."+zone+"."+profil).show();
	            } else {
	                profil="pa";
					$("#abo li."+format+"."+offre+"."+duree+"."+zone+"."+profil).show();
	            }
				offre_abo = $("#abo li:hidden").size();
	            if($("#abo li").size()-offre_abo<1){
	                $("#abo li.not").show();
	            }else{
	                $("#abo li.not").hide();
	            }
	        })
	    });
	}
});

$(document).ready(function() {
	if($('.nav3').length){
		$(".nav3").hide();
		$(".nav3#connexion").show();
	    $(".nav31").click(function(){
	    	$(".nav3").hide();
	    	$(".nav3#recherche").show();
	    });
	    $(".nav32").click(function(){
	    	$(".nav3").hide();
	    	$(".nav3#connexion").show();
	    });
	    $(".form_con31").click(function(){
	    	$(".con").hide();
	    	$(".con31").show();
	    });
	    $(".form_con32").click(function(){
	    	$(".con").hide();
	    	$(".con32").show();
	    });
	    $(".form_con33").click(function(){
	    	$(".con").hide();
	    	$(".con33").show();
	    });
	    $(".nav33").click(function(){
	    	$(".nav3").hide();
	    	$(".nav3#aide").show();
	   	});
	}
   	
    if($('.accordion').length){
    	$(".accordion").accordion();
    }
    if($('#diaporama').length){
		$('#diaporama').anythingSlider({
			width : 464,
			autoPlay : false,
			resizeContents : false
		});
    }
	if(!$('.nopager').length){
		if($('#content .box').length){
	   		$('#content .box').pager('li').not('.banniere').not('.une');
		}
    }
    /*if (topicId != null && topicId!=""){
    	$("#content ul.box").append('<li><a id="comment" href="http://www.facebook.com/topic.php?uid=17405595782&topic='+topicId+'" target="_blank" rel="nofollow">Proposer un'+typeContenu+'</a></li>');
    }*/
});
