// Toutes les lignes qui contiennent '.maxMin' ont été rajoutées pour que les modifications de '.maxMin0' leurs soient appliquees.
// maxMin intervient sur le bouton + et - appelé maxMinBtn.jpg
// maxMin0 a été rejouté (vide) au fichier style.css 
// 			.maxMin0 {}
// et un lien a été inséré dans index php
//			<a href= "#<?php echo $cat->slug?>" class="maxMin0"> <?php echo $cat->cat_name?>.<br /></a>
//
// Manuel Bekhor 02/2010


jQuery(function($) { 
	
	$(document).ready(function() {
		$('.gallery a').click(function() {
			return false;
		});
	});
	
	var active = '#'+jQuery.url.attr("anchor");
	var activeCookie = jQuery.url.attr("anchor");
	
	
	$('.toggleMainCategory').each(function() {
		if($.cookie($(this).prev('.mainCategory').attr('id')) == 'collapsed' || $.cookie($(this).prev('.mainCategory').attr('id')) == null) {
			$(this).hide();
			$(this).prev('.mainCategory').children('.maxMin0').removeClass('active');
			$(this).prev('.mainCategory').children('.maxMin').removeClass('active');
		};
		
		if($.cookie($(this).prev('.mainCategory').attr('id')) == 'expanded') {
			$(this).prev('.mainCategory').children('.maxMin0').addClass('active');
			$(this).prev('.mainCategory').children('.maxMin').addClass('active');
		};
	});
	if ($(active).children('.maxMin0').hasClass('active')) {
		$.scrollTo(active, 500, {offset: {top:-20} });
	} else {
		$(active).children('.maxMin0').addClass('active');
		$(active).children('.maxMin').addClass('active');
		$.cookie(activeCookie, 'expanded', { path: '/', expires: null });
		$(active).next('.toggleMainCategory').slideToggle(500, function () {
			$.scrollTo(active, 500, {offset: {top:-20} });
		});
	}		
	$('.maxMin0').click(function(){
		if ($(this).hasClass('active')) {
			$.cookie($(this).parent().attr('id'), 'collapsed', { path: '/', expires: null });
		 	$(this).removeClass('active');
		 	$(this).parent().children('.maxMin').removeClass('active');
			$(this).parent().next('.toggleMainCategory').slideToggle(500);
		} else  {
			var whereTo = this;
			$(this).addClass('active');
		 	$(this).parent().children('.maxMin').addClass('active');
			$.cookie($(this).parent().attr('id'), 'expanded', { path: '/', expires: null });
			$(this).parent().next('.toggleMainCategory').slideToggle(500, function () {
				$.scrollTo(whereTo, 500, {offset: {top:-20} });
			});
		}
		return false;
	});
	$('.menu a').click(function(){
		if ($(this.hash).children('.maxMin0').hasClass('active') ) {
			$.scrollTo( this.hash, 500, {offset: {top:-20} });
		} else  {
			var whereTo = this.hash;
			$(this.hash).children('.maxMin0').addClass('active');
			$(this.hash).children('.maxMin').addClass('active');
			$.cookie($(this.hash).attr('id'), 'expanded', { path: '/', expires: null });
			$(this.hash).next('.toggleMainCategory').slideToggle(500, function () {
				$.scrollTo(whereTo, 500, {offset: {top:-20} });
			});
		}
		return false;
	});
	
	$('.mainCategory').click(function(){
		if ($(this.hash).children('.maxMin0').hasClass('active') ) {
			$.scrollTo( this.hash, 500, {offset: {top:-20} });
		} else  {
			var whereTo = this.hash;
			$(this.hash).children('.maxMin0').addClass('active');
			$(this.hash).children('.maxMin').addClass('active');
			$.cookie($(this.hash).attr('id'), 'expanded', { path: '/', expires: null });
			$(this.hash).next('.toggleMainCategory').slideToggle(500, function () {
				$.scrollTo(whereTo, 500, {offset: {top:-20} });
			});
		}
		return false;
	});



// Toutes les lignes qui suivantes ont été ajoutées pour avoir deux activations du scrolling.
// Inversement '.maxMin0' ont été rajoutées pour que les modifications de '.maxMin' leurs soient appliquees.
// Manuel Bekhor 02/2010

	$('.toggleMainCategory').each(function() {
		if($.cookie($(this).prev('.mainCategory').attr('id')) == 'collapsed' || $.cookie($(this).prev('.mainCategory').attr('id')) == null) {
			$(this).hide();
			$(this).prev('.mainCategory').children('.maxMin').removeClass('active');
			$(this).prev('.mainCategory').children('.maxMin0').removeClass('active');
		};
		
		if($.cookie($(this).prev('.mainCategory').attr('id')) == 'expanded') {
			$(this).prev('.mainCategory').children('.maxMin').addClass('active');
			$(this).prev('.mainCategory').children('.maxMin0').addClass('active');
		};
	});
	if ($(active).children('.maxMin').hasClass('active')) {
		$.scrollTo(active, 500, {offset: {top:-20} });
	} else {
		$(active).children('.maxMin').addClass('active');
		$(active).children('.maxMin0').addClass('active');
		$.cookie(activeCookie, 'expanded', { path: '/', expires: null });
		$(active).next('.toggleMainCategory').slideToggle(500, function () {
			$.scrollTo(active, 500, {offset: {top:-20} });
		});
	}		
	$('.maxMin').click(function(){
		if ($(this).hasClass('active')) {
			$.cookie($(this).parent().attr('id'), 'collapsed', { path: '/', expires: null });
		 	$(this).removeClass('active');
		 	$('.maxMin0').removeClass('active');
			$(this).parent().next('.toggleMainCategory').slideToggle(500);
		} else  {
			var whereTo = this;
			$(this).addClass('active');
			$('.maxMin0').addClass('active');
			$.cookie($(this).parent().attr('id'), 'expanded', { path: '/', expires: null });
			$(this).parent().next('.toggleMainCategory').slideToggle(500, function () {
				$.scrollTo(whereTo, 500, {offset: {top:-20} });
			});
		}
		return false;
	});
	$('.menu a').click(function(){
		if ($(this.hash).children('.maxMin').hasClass('active') ) {
			$.scrollTo( this.hash, 500, {offset: {top:-20} });
		} else  {
			var whereTo = this.hash;
			$(this.hash).children('.maxMin').addClass('active');
			$(this.hash).children('.maxMin0').addClass('active');
			$.cookie($(this.hash).attr('id'), 'expanded', { path: '/', expires: null });
			$(this.hash).next('.toggleMainCategory').slideToggle(500, function () {
				$.scrollTo(whereTo, 500, {offset: {top:-20} });
			});
		}
		return false;
	});
	
	$('.mainCategory').click(function(){
		if ($(this.hash).children('.maxMin').hasClass('active') ) {
			$.scrollTo( this.hash, 500, {offset: {top:-20} });
		} else  {
			var whereTo = this.hash;
			$(this.hash).children('.maxMin').addClass('active');
			$(this.hash).children('.maxMin0').addClass('active');
			$.cookie($(this.hash).attr('id'), 'expanded', { path: '/', expires: null });
			$(this.hash).next('.toggleMainCategory').slideToggle(500, function () {
				$.scrollTo(whereTo, 500, {offset: {top:-20} });
			});
		}
		return false;
	});

	
});
