type = 'all';

$(document).ready(function() {
	
	if (typeof timeline_limit != 'undefined') {
		Timeline(timeline_limit,type);
		setInterval(function() { Timeline(timeline_limit,type); },20000);
	}

	$('form.poll ul li').live('click',function() {

		if ($(this).is('.checked')) {
			$('form.poll ul li').removeClass('checked');
			$('form.poll ul li input').attr('checked',false);
			$('form.poll input.submit').attr('disabled','disabled');
		} else {
			$('form.poll ul li').removeClass('checked');
			$(this).addClass('checked');
			$('input',this).attr('checked',true);
			$('form.poll input.submit').attr('disabled',false);
		}

	});
	
	$('.homebox.null').each(function() {
		
		id = $(this).attr('id');
		
		$.get('/ajax/account/home.php',{id:id},function(html) {
			
			box = $('.homebox.null:first');
            box.before(html).remove();

            i = 0;
            $('.homebox').each(function() {
                if (i == 0 || i == 2) {
                    $('.content',this).removeClass('right').addClass('left');
                } else {
                    $('.content',this).removeClass('left').addClass('right');
                }
                i++;
            });

			if ($(html).attr('id') == 'poll') {

				$('.homebox#poll form').ajaxForm({

					beforeSubmit: function() {

						$(this).css('opacity',0.5);

					},

					success: function(result) {

						titre = $('.homebox#poll .content p:first').html();
						$('.homebox#poll .content').html('<p>'+titre+'</p><p class="question">'+result+'</p>');

					}

				});

			}
			
		});

		showContexts();
		
	});

	/* Pour le blog */

	$('.homebox#poll form').ajaxForm({

		beforeSubmit: function() {

			$(this).css('opacity',0.5);

		},

		success: function(result) {

			titre = $('.homebox#poll .content p:first').html();
			$('.homebox#poll .content').html('<p>'+titre+'</p><p class="question">'+result+'</p>');

		}

	});

});

function Timeline(nb,type) {

	$('.timeline.previously').append('<img id="loading" src="/images/site/ajax-loader.gif" />');
	
	$.get('/ajax/timeline/get.php',{limit:nb,type:type},function(html) {
	
		$('.timeline.previously #loading').remove();
		$('.timeline.previously .item').remove();
		$('.timeline.previously').append(html);
	
	});

}

function timelineToggle(data,el) {
	
	$(el).parent().toggleClass('active');
	
	value = '0';
	if ($(el).parent().is('.active')) {
		value = '1';
	}
	
	$.get('/ajax/timeline/option.php',{data:data,value:value},function() {
	
		Timeline(10,'all');
	
	});

}
