/* mg.js */


function toogleBlogPost()
{
	var that = $(this);
	var bando = that.parent();
	var article = bando.next();
	if(!article.hasClass('current-article')) // ON MONTRE
	{
		if($('.current-article').length > 0)
		{
			$('.current-article').slideUp(600, function()
			{
				$('.current-article').removeClass('current-article');
				$('.current-bando').css('margin-bottom', '15px');
				$('.current-bando div.blogpost-bando-thumb').show();
				$('.current-bando').removeClass('current-bando');
				
				bando.css('margin-bottom', '0');
				bando.addClass('current-bando');
				bando.children('div.blogpost-bando-thumb').hide();
				article.addClass('current-article');
				article.slideDown(600, function()
				{
					$("html,body").animate({scrollTop : bando.offset().top - 25},1000);
				});
			});
		}
		else
		{
				bando.css('margin-bottom', '0');
				bando.addClass('current-bando');
				bando.children('div.blogpost-bando-thumb').hide();
				article.addClass('current-article');
				article.slideDown(600, function()
				{
					$("html,body").animate({scrollTop : bando.offset().top - 25},1000);
				});
		}
	}
	else // ON CACHE
	{
		/*
		article.slideUp();
		article.removeClass('current-article');
		
		bando.css('margin-bottom', '15px');
		bando.removeClass('current-bando');
		bando.children('div.blogpost-bando-thumb').show();
		*/
	}
	
}


function toggleProjectGroup()
{
	var that = $(this);
	var group = that.next();
	if(that.hasClass('project-item-group-current'))
	{
		$('.project-item-group-label').removeClass('project-item-group-current');
		group.slideUp();
	}
	else
	{
		$('.project-item-group-label').removeClass('project-item-group-current');
			$('.project-item-group').slideUp();
			that.addClass('project-item-group-current');
			group.slideDown();
	}
}


function initMG()
{
	$('.blogpost-article').hide();
	$('.blogpost-bando-title').click(toogleBlogPost);	
	$('.blogpost-bando-thumb').click(toogleBlogPost);	
	
	$('.blogpost-bando').css('margin-bottom', '15px');
	if(openFirst)
	{
		$('.blogpost-article').first().show();
		$('.blogpost-article').first().addClass('current-article');
		$('.blogpost-bando').first().css('margin-bottom', '0');
		$('.blogpost-bando').first().addClass('current-bando');
		$('.blogpost-bando').first().children('div.blogpost-bando-thumb').hide();
	}
	
	$('.project-item-group').hide();
	$('.project-item-group-current').next().show();
	$('.project-item-group-label').click(toggleProjectGroup);
}


$(document).ready(initMG);

