function checkUncheckAll(theElement) {
	var theForm = theElement.form, z = 0;

	for(z=0;z<theForm.length;z++) {
		if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall'){theForm[z].checked = theElement.checked;}
	}
}

$(function (){
	var $authform = $('#authform');
	var $statcontainer = $('#achach_statcontainer');
	var ajaxresponse = 'ajaxresp032010.php';

	$('#authform').hide();
	
	$('#authopen').click(function () {$authform.fadeIn("slow");});

	if ($('#authopen2').length)
	{
		$('#authopen2').click(function () {$authform.fadeIn("slow");});
	}
	$('#authclose').click(function () {$authform.fadeOut("slow");});
	$('#add_video').click(function () {top.location.href='/upload';});

	$('#period li a').click(function () {
		if (!$(this).hasClass("active")) {
			$('#period li a').removeClass('active');
			$(this).addClass('active');
			var id = $(this).attr('id');
		}

		if (id == 'mostly_today' || id == "mostly_week" || id == "mostly_month" || id == "mostly_alltime")
		{
			$.ajax({
				type: 'GET',url: ajaxresponse,data: 'id='+id,
				success: function(html){$statcontainer.animate({'opacity': 0}, 700, function () {$(this).empty().append(html).animate({'opacity': 1}, 700);});}
			});
		}
	});

	$('#rat_type li a').click(function()
	{
		if (!$(this).hasClass("active")) {
			var id = $(this).attr('id');

			if (id == 'by_rating') {$('#period').slideUp('slow');}
			if ($('#by_rating').hasClass("active")) {$('#period').slideDown('slow');}
			if (id == 'by_views') {
				$('#period li a').removeClass('active');
				$('#mostly_today').addClass('active');
				id = 'mostly_today';
			}

			$('#rat_type li a').removeClass('active');
			$(this).addClass('active');
		}

		if (id == 'by_rating' || id == "mostly_today") {
			$.ajax({
				type: 'GET',url: ajaxresponse,data: 'id='+id,
				success: function(html){$statcontainer.animate({'opacity': 0}, 700, function () {$(this).empty().append(html).animate({'opacity': 1}, 700);});}
			});
		}
	});

	$('div.comment').click(function (event)
	{
		var tgt = $(event.target);
		if (tgt.is('a.reply') && $(this).find('div.textarea')) {$(this).find('div.textarea').slideDown('slow');}
	});

	$('a.view-comment-form').toggle(
		function() {$('div.comment_mainpad').slideDown('slow');},
		function() {$('div.comment_mainpad').slideUp('slow');}
	);

	$('span.view-comment-form').toggle(
		function() {$('div.comment_mainpad').slideDown('slow');},
		function() {$('div.comment_mainpad').slideUp('slow');}
	);

});
