$(function() {

	$('span.hide').toggle(
		function() {
			$(this).parents('div.section').find('div.inner').animate({height: 'hide'}, 200);
			$(this).removeClass('hide').addClass('showme');
		},
		function() {
			$(this).parents('div.section').find('div.inner').animate({height: 'show'}, 200);
			$(this).removeClass('showme').addClass('hide');
		}
	);

	$('span.close').click(function() {
		$(this).parents('div.section').fadeOut();
		$.get('/index.php?do=sb&d='+$(this).parent().parent().parent().attr("id"));
	});

	$('ul.tabs').each(function(i) {
		i += 1; var div1 = i*2-1; var div2 = i*2;
		$('ul.tabs li').click(function(){
			var thisClass = this.className.slice(0,3);
			$('div.t'+div1).hide();
			$('div.t'+div2).hide();
			$('div.' + thisClass).show();
			$('ul.tabs li').removeClass('tab-current');
			$(this).addClass('tab-current');
		});
	});

	$('#enter').click(function() {
		$('#enter').toggleClass('hover');
	 	$('#authoriz form').toggle();
		return false;
	});
	
	$('#login_dialog').dialog({
		autoOpen: false,
		resizable: false,
		width: 600,
		buttons: {
			"Войти": function() { 
				$('#loginForm').submit();
			}, 
			"Отмена": function() { 
				$(this).dialog("close"); 
				
			} 
		}
	});
	
	$('#enter').click(function(){
		$('#login_dialog').dialog('open');
		return false;
	});

	$('#nav li').hover(
		function() {
			$(this).addClass('hover');
		},
		function() {
			$(this).removeClass('hover');
		}
	);
	
	$(function() {
		$("input:submit.bbcodes_poll,.bbcodes,input:submit#yandexenter,input:submit#addcommentbutton").button();
	});
	
	$(".column").sortable({
			connectWith:	$(".column"),
			cancel: '.partners',
			placeholder:	'widget-placeholder',
			handle : '.section h3',
			update: function() {
				$.get('/index.php?do=sb&q='+$(".column").sortable("toArray"));
			}
	});
		
	$('#showall').click(function() {
		$.get('/index.php?do=sb&d=a');
		window.location.href = '/index.php';
	});
	
	$('#mailregisterform').dialog({
		autoOpen: false,
		resizable: false,
		width: 600,
		buttons: {
			"Зарегистрировать": function() { 
				$.post("/mailregister/index.php",{username: $("#yausername").val(), password:$("#yapassword").val(), again:$("#yaagain").val(),action: "register"}, function(data) {
						$('#mailregisterform').html(data);
				});
			}, 
			"Отмена": function() { 
				$(this).dialog("close"); 
				
			} 
		}
	});
	
	$('#mailregister').click(function() {
		$("#mailregisterform").load('/mailregister/index.php');
		$('#mailregisterform').dialog('open');
		return false;
	});
	
	$('#blocksettings').dialog({
		autoOpen: false,
		resizable: false,
		width: 600,
		buttons: {
			"Изменить": function() { 
				var allVals = [];
				$('input[name=blocks]:checked').each(function() {
						allVals.push($(this).val());
				});
				$.post("/index.php",{'blocks':allVals,'do': "sb"}, function(data) {
					window.location.href = '/index.php';	
					//$('#blocksettings').html(data);
				});
			}, 
			"Отмена": function() { 
				$(this).dialog("close"); 
				
			} 
		}
	});
	
	$('#blocksetup').click(function() {
		$("#blocksettings").load('/index.php?do=blocksettings');
		$('#blocksettings').dialog('open');
		return false;
	});
	
	$('.slideshow').cycle({
			fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
			speed:  2000,
			timeout:  2000 ,
			random:  1 ,
			pause:  1 
	});	
})
