$(document).ready(function(){
	$('.content').hide();
	$('#content_vv').show();
	$('#header span').each(function(index){
		$(this).click(function(){
			if (!$('#return').hasClass("open")){
				$('#header').animate({
					height: '+=50',
				},{
					duration: 500,
					complete: function(){
						$('#return').fadeIn();
						$('#return').addClass("open");
					}
				});
			}
			$('.content').fadeOut(500).delay(500);
			$('#'+$(this).attr('rel')).fadeIn(500);
		});
	});
	$('#return').click(function(){
		$(this).fadeOut();
		$('.content').fadeOut(500);
		$('#header').animate({
			height: '-=50',
		},{
			duration: 500,
			complete: function(){
				$('#content_vv').fadeIn(500);	
				$('#return').removeClass("open");
			}
		});
	});
	$(".lieu, #header span").hover(function(){
		if (!$(this).hasClass("open")){
			$(this).css('background','none repeat scroll 0 0 #271c6c').css('color','#fff');
		}
	},function(){
		$(this).css('background','none repeat scroll 0 0 #fff').css('color','#333');
	});
	$(".lieu .titre").click(function(){
		$(this).parent(".lieu").css('background','none repeat scroll 0 0 #fff').css('color','#333');
		if ($(this).parent(".lieu").hasClass("open"))
			$(this).next(".lieu_content").hide("slow").parent(".lieu").removeClass("open");
		else{
			$(".lieu_content").hide("slow").parent(".lieu").removeClass("open");
			$(this).next(".lieu_content").show("slow").parent(".lieu").addClass("open");
		}
	});

	/* MODAL PLAYER */
	function chargerModal(media){
		var url = media.attr('rel');
		if(media.hasClass('video')){
			$('#mediaplayer_wrapper').attr('id','mediaplayer');
			$('#mediaplayer').html("");					
			$('#modal').removeClass("modalSon").addClass("modalVideo");
			jwplayer("mediaplayer").setup({
                skin: "/includes/js/jwplayer/skins/glow.zip",
				autostart: true,
				flashplayer: "includes/js/jwplayer/player.swf",
				file: url,
				image: media.attr('alt')
			});
		} else {
			$('#modal').removeClass("modalVideo").addClass("modalSon");
			$('#mediaplayer').css({height:'25px', width: '160px'}).html('<object type="application/x-shockwave-flash" data="includes/flash/dewplayer-mini.swf?mp3='+url+'" width="160" height="25" id="dewplayer-mini"><param name="wmode" value="transparent" /><param name="movie" value="dewplayer-mini.swf?mp3=sons/'+url+'" /><param name="flashvars" value="mp3='+url+'&amp;autostart=1" /></object>');
		}				
		$('#mask, #modal').fadeIn('slow');
	}
	$("td.media").click(function(){
		chargerModal($(this));
	});
	$('#mask').click(function(){
		$('#mask, #modal').fadeOut('slow');
		$('#mediaplayer_wrapper').attr('id','mediaplayer').html("");		
	});
});
