$(document).ready(function(){

//幻灯播放

(function(){

	//翻页切换

	$('#previous').click(function(){
		$('#sponsor dl:visible').fadeOut('fast', function(){
			if($(this).prev().is('dl')){
				$(this).prev().fadeIn('fast');
			}else{
				$('#sponsor dl:last-child').fadeIn('fast');
			}
		});
	});
	$('#next').click(function(){
		$('#sponsor dl:visible').fadeOut('fast', function(){
			if($(this).next().is('dl')){
				$(this).next().fadeIn('fast');
			}else{
				$('#sponsor dl:first-child').fadeIn('fast');
			}
		});
	});

	//圆点切换

	$('#point b:first-child').click(function(){
		$('#sponsor dl:visible').fadeOut('fast', function(){
			$('#sponsor dl:first-child').fadeIn('fast');
		});
	});
	$('#point b:nth-child(2)').click(function(){
		$('#sponsor dl:visible').fadeOut('fast', function(){
			$('#sponsor dl:nth-child(2)').fadeIn('fast');
		});
	});
	$('#point b:last-child').click(function(){
		$('#sponsor dl:visible').fadeOut('fast', function(){
			$('#sponsor dl:last-child').fadeIn('fast');
		});
	});

	//定时切换

	var timeout,
	    slide = function(){
			$('#next').trigger('click');
			timeout = setTimeout(slide, 5000);
		}
	$('#scroll').hover(
		function(){
			clearTimeout(timeout);
		},
		function(){
			timeout = setTimeout(slide, 5000);
		}
	);
	timeout = setTimeout(slide, 5000);

})();

//模式切换

(function(){

	$('#switch').toggle(
		function(){
			$(this).text('完整模式');
			$(this).removeClass('switch-up');
			$(this).addClass('switch-down');
			$('#scroll').animate({height: '45px'}, 'fast');
			$('#sponsor dl dt:first-child').css('float', 'left');
			$('#sponsor dl dd:last-child').hide();
		},
		function(){
			$(this).text('精简模式');
			$(this).removeClass('switch-down');
			$(this).addClass('switch-up');
			$('#scroll').animate({height: '90px'}, 'fast', function(){
				$('#sponsor dl dt:first-child').css('float', 'none');
				$('#sponsor dl dd:last-child').show();
			});
		}
	);

})();

//标签收缩

(function(){

	$('#tag').toggle(
		function(){
			$('#bookmark').slideDown('fast');
			$(this).removeClass('slide-down');
			$(this).addClass('slide-up');
		},
		function(){
			$('#bookmark').slideUp('fast');
			$(this).removeClass('slide-up');
			$(this).addClass('slide-down');
		}
	);

})();

//获焦失焦

(function(){

	if($.browser.msie){
		$('.post, .comment li:not(.webmaster)').hover(
			function(){
				$(this).css('backgroundColor', '#fafafa');
			},
			function(){
				$(this).css('backgroundColor', '#fff');
			}
		);
		$('.commentform input, .commentform textarea').focus(function(){
			$(this).css('backgroundColor', '#fafafa');
		});
		$('.commentform input, .commentform textarea').blur(function(){
			$(this).css('backgroundColor', '#fff');
		});
	}

})();

//评论回应

(function(){

	$('.reply').click(function(){
		var reply = '\u56de\u5e94\u0020' + $(this).parent().parent().prev().find('em:first').text() + '\u0020\u7684\u53d1\u8a00';
		$('#commentform').prev().text(reply);
		$('#comment').select();
		$('html, body').animate({
			scrollTop: $('#comment').offset().top
		}, 'slow');
		$('#comment_parent').val($(this).attr('rel'));
		return false;
	});
	$('.reply-to').click(function(){
		$('html, body').animate({
			scrollTop: $($(this).attr('href')).offset().top
		}, 'slow');
		return false;
	});

})();

//用户资料

(function(){

	if($('#switch-comment-author')){
		$('#switch-comment-author').toggle(
			function(){
				$(this).text('隐藏资料');
				$('#comment-author').show('fast');
				return false;
			},
			function(){
				$(this).text('显示资料');
				$('#comment-author').hide('fast');
				return false;
			}
		);
	}

})();

});
