
var titrage = function(){
	$('#question').hide();	
	
 	var titreOk = currentImageBox.find('.titre').html();
	$('#legend').empty().append(titreOk);
	if (titreOk != '') {
		$('#question').show();	
	}
};

var nextImg = function(){
			$('#legend').hide();
			$('#question').hide();
	


	if (currentImageBox.next().length==0){
		nextImageBox =	$('#bgImages div:nth-child(1)');

	}
	else{
		nextImageBox = currentImageBox.next();
	}
	// alert(nextImageBox.attr('id'));	

	currentImageBox.hide();
	nextImageBox.show();
	currentImageBox = nextImageBox;
	titrage();
};

var prevImg = function(){
	
		$('#legend').hide();
		$('#question').hide();

		if (currentImageBox.prev().length==0){
			prevImageBox =	$('#bgImages div:last-child');

		}
		else{
			prevImageBox = currentImageBox.prev();
		}
		// alert(nextImageBox.attr('id'));	

		currentImageBox.hide();
		prevImageBox.show();
		currentImageBox = prevImageBox;
		titrage();
		
	
};

var currentImageBox;

var background = function(){
	

var backUrl = $('#background').html();
if (backUrl != ''){
$('body').css('background','url('+backUrl+') fixed');
}
};

$(document).ready(function (){
	$('img.bigImage').hide();
$.loader({content:''});
	currentImageBox = $('#bgImages div:nth-child(1)');

});

$(window).load(function(){

	$.loader("close"); 

	$('img.bigImage').fadeIn(400);

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

     $(function() {
            $(this).bind("contextmenu", function(e) {
                e.preventDefault();
            });
        });  
        
$(function(){
	$.extend($.fn.disableTextSelect = function() {
		return this.each(function(){
			if($.browser.mozilla){//Firefox
				$(this).css('MozUserSelect','none');
			}else if($.browser.msie){//IE
				$(this).bind('selectstart',function(){return false;});
			}else{//Opera, etc.
				$(this).mousedown(function(){return false;});
			}
		});
	});
	$('.nav').disableTextSelect();//No text selection on elements with a class of 'noSelect'
	$('.pagenav').disableTextSelect();//No text selection on elements with a class of 'noSelect'
	$('.page_item').disableTextSelect();//No text selection on elements with a class of 'noSelect'

});

	// toggle du bloc de texte          		
	$('#realContent').show();
	$('#contentBox').find('h2').click(function(){
		$('#realContent').toggle();
	});  


	titrage();
	
	background();
	//on click next
	
	$('#next').click(nextImg);
	
	$(document).keydown(function(e){
	if (e.keyCode=='39'){
		e.preventDefault();
		nextImg();
		
	}	
	});



	//on click prev
	$('#prev').click(prevImg);
	
	$(document).keydown(function(e){
	if (e.keyCode=='37'){
		e.preventDefault();
		prevImg();
		
	}	
	});



	// légende on/off 
	
	$('.titre').hide();
	$('#legend').hide();
	$('#question').click(function(){
	

	$('#legend').toggle();
	
	});
	//pouf
	$('#pouf').click(function(){
		$('.boxes').toggle();
	});
	
		

	// toggle des menus         		
	$('#menu ul li ul').hide();


	$('.boxes').children('ul').children('li').children('h2').click(function(){
		$(this).next().toggle();
		return false;
		
		});
	$('.boxes').children('ul').children('li').children('ul').children('li').children('ul').parent().children('a').click(function(){
			$(this).next().toggle();
			return false;

			});
	
	// show where you are 
			
	$('li.current_page_item').parent('ul').show();
		$('li.current_page_item').prepend('<img id="star" src="http://www.juliemenuge.com/web/wp-content/themes/juliemenuge/scriptnico/star.png"/>');

	$('li.current_page_ancestor').parent('ul').show();
	
	//vire les fleches en cas d'image seule
	var boxy = $('#bgImages div:nth-child(1)');
 	if (boxy.next().length==0){
		$('#prev').hide();
		$('#next').hide();
	} 
}); 

