// JavaScript Document

$(document).ready(function(){
	
	var previewHeight = 374;
	var previewMinHeight = 110;
	var currentNavOpened=null;
	var menuAnimationSpeed = 200;
	
	$('.post img').removeAttr('title');
	
	/* ----------------------------------- */
	/* NAVIGATION & SUB-NAVIGATION EFFECTS */
	/* ’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’ */
	/* author : mcaillet : 			   */
	/* date 20100511					   */
	/* ----------------------------------- */
	
	// split the main list in 4 columns
	// TODO : manage height ??
	$('.sousCat,.sousCatEvent').easyListSplitter({ colNumber: 4 });
	$('#subNav').hide(); // hide list
	$('li.subCat:first-child').css('margin-top','0'); // remove margin if sub-category is on the top of the list
	
	// manage click
	//var nv_dt_length = $('#navig dt').length;
	$('#navig dt:not(:last)').click(function(){
		var index = $('dt').index($(this)); // get item position (0 for works || 1 for event || 2 for the next main cat)
		
		if(currentNavOpened!=null){ // check if subnav is open 
			$('#subNav').slideUp(menuAnimationSpeed,function(){ // close menu
					$('#subNav div').hide().eq(index).show(); // hide all subCat and display the clicked one
		 			if(currentNavOpened!=index){ // if clicked is not the same 
		 				$("#subNav").slideDown(menuAnimationSpeed,function(){ // open menu
		 					currentNavOpened=index; // on finished update opened Var
		 				});
		 			}else{
		 			  currentNavOpened=null; // update opened Var (now subnav is closed)
		 			}
		 		});
		 	}else{ // subnav is closed
		 		$('#subNav div').hide().eq(index).show(); // hide all subCat and display the clicked one
		 	 	$("#subNav").slideDown(menuAnimationSpeed,function(){// open menu
		 	 		 currentNavOpened=index; // update opened Var
		 	 	});
		 	 }
		 	return false; // break anchor
	
	});
	
	/* ----------------------------------- */
	/* ----------------------------------- */
	
	$('.homePreview').each(function(index) {
	
			var thisHeight = Math.max(previewMinHeight, previewHeight - (index * 0.3 * previewHeight)+26);
			var thisMargin = Math.round(((previewHeight+(26))-thisHeight)/2);
			
			$(this).css('height', thisHeight+(0));
			$(this).find('.post-content').css('height', thisHeight);
			$(this).find('.post-content').css('overflow', 'hidden');
			$(this).find('.post-content img').css('margin-top', -thisMargin, 'display', 'block');
			$(this).find('.date').css('top', -thisHeight+(42));
	});

	
	/* ----------------------------------- */
	/* POST ROLLOVER EFFECTS			   */
	/* ’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’ */
	/* author : mcaillet : 			   */
	/* date 20100501					   */
	/* ----------------------------------- */
	$(".commentBulle,.date").fadeTo(0,0);
	$('.barreInfo').css('opacity',0.4);
	$('div.selected').css('opacity',0.8);	
	
	$('.post').each(function(){		
		$(this).hover(function(){
			if($(this).find('.commentBulle a').html() == '' ){
				$(this).find('.commentBulle').hide();
			};
			$(this).find('.barreInfo').not('.selected').stop().fadeTo(300,0.8);
			$(this).find('.date,.commentBulle').stop().fadeTo(300,1);
		}, function(){
			$(".commentBulle,.date").stop().fadeTo(200,0);	
			$(this).find('.barreInfo').not('.selected').stop().fadeTo(200,0.4);
		});
		
		/*if($(this).find('.by').html().length==3){
			$(this).find('.by').remove();
		};*/ 

	});	
	

		
	
	
	if($('body').attr('class')=="dc-post"){
		var content = $('.dc-post .post-content p').html();
		if(content){
			if(content.length<20){
				$('.dc-post .post-content').css('display','none');
			};
		};
	
	};
	
	$('.dc-home .post-content,.dc-category .post-content,.dc-tag .post-content').css('cursor','pointer').click(function(){
		var href= $(this).parent().find('.post-title a').attr('href');
		window.location.href=(href);
	});


var ea=[100,117,99,114,101,115,116,97,64,101,100,117,102,114,46,99,104]
var e='' //variable to contain encrypted email 
for (var i=0; i<ea.length; i++)
 e+=String.fromCharCode(ea[i])

$('.m_a_i_l').attr('href','mailto:'+e).html('contact email')

$('.dc-post label[for="c_mail"] span').hide();
$('.dc-post #c_mail').removeAttr('disabled');
		
});
