(function($) {
$(function() {

	$('#popular ul').before('<div id="bull"></div>');
	$('#popular li').each(function() { $('#bull').append('<div>&bull;</div>'); })
	$('#bull div:first').addClass('current');
	$('#popular li:first').show();

	rotate = function(){
		$("#bull div").removeClass('current');
		$active.addClass('current');
		$index = $("#bull div.current").index();
		$('#popular li').fadeOut(200).delay(100).eq($index).css({left: '1000'}).show().animate({left: '0'});
	};
	rotateSwitch = function(){
		play = setInterval(function(){
			$active = $('#bull div.current').next();
			if ( $active.length === 0) {
				$active = $('#bull div:first');
			}
			rotate();
		}, 5000);
	};
	rotateSwitch();
	$("#bull div").click(function() {
		$active = $(this);
		clearInterval(play);
		rotate();
		rotateSwitch();
	});
	$("#popular li").hover(function() {
		clearInterval(play);
	}, function() {
	  rotateSwitch();
	});

	var author = $('#author').val();
	if( author !='' && $('#email').val() !='' ) {
		$('#authorData').hide();
		$('#authorData').before('<div id="welcome">Welcome back, <strong>' + author + '</strong>! <a href="#">Edit &raquo;</a></div>')
		$('#welcome a').toggle(
			function() {
				$('#authorData').show(300);
				$(this).html('Minimize &raquo;');
				return false;
			},
			function() {
				$('#authorData').hide(300);
				$(this).html('Edit &raquo;');
				return false;
			}
		);
	}

	$('#tagCloud li:last').addClass('last');

	$.each(
		$('#tagCloud ul li'),function(e) {
			if (e>-1&e<=7) $(this).addClass('tagSize-1');
			if (e>7&e<=16) $(this).addClass('tagSize-2');
			if (e>16&e<=26) $(this).addClass('tagSize-3');
			if (e>26&e<=35) $(this).addClass('tagSize-4');
			if (e>35&e<=47) $(this).addClass('tagSize-5');
	});

	$('#tagCloud .tagSize-2:first, #tagCloud .tagSize-3:first, #tagCloud .tagSize-4:first, #tagCloud .tagSize-5:first').before('<li class="divider"></li>');

});
})(jQuery)


/* === Socialization === */
function socializ(u,t) {

	var m1 = 370; /* расстояние от начала страницы до плавающей панели */
	var m2 = 16; /* расстояние от верха видимой области страницы до плавающей панели */
	var f = '/wp-content/themes/dimox.net/i/s/';

	document.write('<div id="socializ"></div>');
	var s = $('#socializ');
	s.css({top: m1});
	if ( $(window).width() < 1080 ) s.css({marginLeft: -58});
	function margin() {
		var top = $(window).scrollTop();
		if (top+m2 < m1) {
			s.css({top: m1-top});
		} else {
			s.css({top: m2});
		}
	}
	$(window).scroll(function() { margin(); })

	s.append(
		'<div id="soc1">' +
		'<a href="http://twitter.com/home?status=RT @Dimox_en ' + t + ' - ' + u + '" title="Share on Twitter"><img src="' + f + 'twitter.png" alt="" /></a>' +
		'<a href="http://www.google.com/reader/link?url=' + u + '&title=' + t + '&srcURL=http://dimox.net/" title="Share on Google Buzz"><img src="' + f + 'google-buzz.png" alt="" /></a>' +
		'<a href="http://www.stumbleupon.com/submit?url=' + u + '&title=' + t + '" title="Stumble this post"><img src="' + f + 'stumbleupon.png" alt="" /></a>' +
		'<a href="http://www.friendfeed.com/share?title=' + t + ' - ' + u + '" title="Share on FriendFeed"><img src="' + f + 'friendfeed.png" alt="" /></a>' +
		'<a href="http://www.facebook.com/sharer.php?u=' + u + '" title="Share with your friends on Facebook"><img src="' + f + 'facebook.png" alt="" /></a>' +
		'<a href="http://www.linkedin.com/shareArticle?mini=true&url=' + u + '&title=' + t + '&summary=" title="Share this post on Linkedin"><img src="' + f + 'linkedin.png" alt="" /></a>' +
		'<a href="http://designbump.com/node/add/drigg/?url=' + u + '&title=' + t + '" title="Bump it!"><img src="' + f + 'design-bump.png" alt="" /></a>' +
		'<a href="http://www.designfloat.com/submit.php?url=' + u + '" title="Float it!"><img src="' + f + 'designfloat.png" alt="" /></a>' +
		'</div>' +
		'<div id="socmore" title="More">...</div>' +
		'<div id="soc2">' +
		'<a href="http://delicious.com/save?url=' + u + '&title=' + t + '" title="Bookmark this post at Delicious"><img src="' + f + 'delicious.png" alt="" /></a>' +
		'<a href="http://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk=' + u + '&title=' + t + '" title="Bookmark on Google"><img src="' + f + 'google.png" alt="" /></a>' +
		'<a href="http://technorati.com/faves?add=' + u + '" title="Fav on Technorati"><img src="' + f + 'technorati.png" alt="" /></a>' +
		'</div>'
	);
	$('#socializ a').each(function() {
		var src = $(this).find('img').attr('src');
		$(this).find('img').hide().end().css({backgroundImage: 'url('+ src +')'}).attr({rel: 'nofollow', target: '_blank'});
	})
	s.find('a').css({opacity: 0.5}).hover(
		function() { $(this).css({opacity: 1}); },
		function() { $(this).css({opacity: 0.7}); }
	);
	s.hover(
		function() { $(this).find('a').css({opacity: 0.7}); },
		function() { $(this).find('a').css({opacity: 0.5}); }
	);
	$('#socmore').css({opacity: 0.5}).hover(
		function() { $(this).css({opacity: 1}); },
		function() { $(this).css({opacity: 0.5}); }
	);
	$('#soc2').hide();
	$('#socmore').toggle(
		function() {
			$('#soc1').animate({height: 'hide'}, 300);
			$('#soc2').animate({height: 'show'}, 300);
		},
		function() {
			$('#soc2').animate({height: 'hide'}, 300);
			$('#soc1').animate({height: 'show'}, 300);
		}
	)

}