$(document).ready(function() {

	$(".IamNews").each( function(i){
		if( parseInt($.cookie(this.id)) == 0 ) {
			var tmp = new String(""+this.id+"");
			tmp = tmp.replace("news_id_", "");
			toggle_news( parseInt( tmp ) ); 
		}
	});
});

function toggle_news(id) {

	if( get_news_states(id) == 1 ) {
		$("#news_content_"+id+"").animate({ height: "0px", opacity: "0.0"}, 500, function() {
			$("#news_content_"+id+"").addClass("no_overflow");
		});;
			
		var titre = $("#news_top_"+id+"").html();
		$("#news_titre_"+id+"").html(titre);
	
		$("#news_titre_"+id+"").animate({ opacity: 1.0, height: "12px", marginTop: "-6px"});
		$("#news_top_"+id+"").animate({ height: "0px", opacity: "0.0"});

	}
	else if( get_news_states(id) == 0 ) {
		$("#news_content_"+id+"").animate({ height: "100%", opacity: "1.0"}, 500, function() {
                        $("#news_content_"+id+"").removeClass("no_overflow");
                });

                $("#news_titre_"+id+"").html('');

                $("#news_titre_"+id+"").animate({ opacity: 0.0, height: "0px", marginTop: "0px"});
                $("#news_top_"+id+"").animate({ height: "100%", opacity: "1.0"});
	}

	switch_news_states(id);
}
function get_news_states(id) {
	return parseInt($("#news_states_"+id+"").html());
}
function set_news_states(id, states) {
        $("#news_states_"+id+"").html(''+states+'');
}
function switch_news_states(id) {

	var futur = 1;
	if( get_news_states(id) == 0 ) {
		futur = 1;
	}
	else if( get_news_states(id) == 1 ) {
		futur = 0;
        }
	
	set_news_states(id, futur);
	$.cookie('news_id_'+id+'', futur);
}

