//Pour cacher les sous-menu au survol d'une catégorie sans sous-menu
$(document).ready(function() {
	$("ul#topnav > li").not(".actif").hover(function() { //Les elements li parent sans la classe actif
		$("ul#topnav > li.actif > ul.subnav").hide() //hide the subnav
	}, function() { //on hover out...
		$("ul.subnav").show(); //Show the subnav
	});
});

//Diaporama photo
$(window).load(function() {
	$('#slider').nivoSlider({
		effect:'sliceDown', //Specify sets like:'sliceDown sliceDownLeft sliceUp sliceUpLeft sliceUpDown sliceUpDownLeft fold fade random'
		slices:25,
		animSpeed:400,
		pauseTime:6000
	});
});

//Permettre l'effet hover sur ie6
function sfHover() {
	var sfEls = document.getElementById("menu").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
	}
	if (window.attachEvent) window.attachEvent("onload", sfHover);
	
//Les news
$(document).ready(function() {
	$("#news").jCarouselLite({
	vertical: true,
	hoverPause:true,
	visible: 3,
	auto:3000,
	speed:1000,
	btnNext: ".next",
   	btnPrev: ".prev"
	});		
});

//Pop-up highslide
$(document).ready(function() {
	$("a.news-highslide").click(function() { //Les elements a avec classe highslide
		return hs.htmlExpand(this, {objectType: 'ajax',
							 		anchor: 'left',
									targetX: 'news 90px',
									dimmingOpacity: 0,
									outlineType:'rounded-white', 
									fadeInOut:true
									}); 
	});
	$("a.agenda-highslide").click(function() { //Les elements a avec classe highslide
		return hs.htmlExpand(this, {objectType: 'ajax',
							 		align: 'center',
									width: 450,
									targetY: 'agenda 30px',
									outlineType:'rounded-white', 
									fadeInOut:true
									}); 
	});
});

//La carte interactive
function change_carte(region) {
 var ShowItem = document.getElementById("area_image");
 ShowItem.style.backgroundImage = 'url(../images/carte_' + region + '.gif)';
 return true;
}
function hide_carte(region) {
 var ShowItem = document.getElementById("area_image");
 ShowItem.style.backgroundImage = 'url(../images/carte_tranparent.gif)';
 return true;
}

//Recherche
if (!sitesearch) var sitesearch = {};
sitesearch.onChange = function (fldID, btnID) {
    var fld = document.getElementById(fldID);
    var btn = document.getElementById(btnID);
    if (fld.value.length > 0 && !this.clearBtn) {
        btn.style.display = 'block';
        btn.fldID = fldID;
        btn.onclick = this.clearBtnClick;
        this.clearBtn = true;
    } else if (fld.value.length == 0 && this.clearBtn) {
        btn.style.display = 'none';
        btn.onclick = null;
        this.clearBtn = false;
    }
}
sitesearch.clearFld = function (fldID, btnID) {
    var fld = document.getElementById(fldID);
    fld.value = "";
    this.onChange(fldID, btnID);
}
sitesearch.clearBtnClick = function () {
    sitesearch.clearFld(this.fldID, this.id);
};

//Accordeon
function initDocMenu() {
    var theMenu = $('.accordion');
    theMenu.find('li').click(function () {
        window.location = $(this).find('a').attr('href');
        return false;
    }).find('span.cross_show').click(function () {
        $('li > ul', theMenu).slideUp('normal');
        if ($(this).parents('li').hasClass('expand')) {
            $(this).parents('li').removeClass('expand');
        }
        else {
			$('li', theMenu).removeClass('expand')
            $(this).parents('li').addClass('expand').find('ul').slideDown('normal');
        }
        return false;
	}).end().not('.expand').find('ul').hide();
}

$(document).ready(function() {initDocMenu();});
