$(function(){
	var $Id = 2;
	var i=1;
	var Html = $('#postlist');
	var Load = $('.pagenavi');
	$('.pagenavi').live('click',function(){
		i++;
		$.ajax({
			url: "?action=ajax_post&paged="+$Id,
			beforeSend: function(){Load.text('努力加载中，请稍等……')},
			success:function(a){
				var up=$('.pagenavi').offset().top-20;
				$('html,body').animate({scrollTop: up+100},800);
				$('html,body').animate({scrollTop: up},1000);
				Html.append(a);
				Load.text('———————第————'+i+'————页———————')
			}
		});
		$Id++; //累加，是关键！
		return false;
	});
	//post down and up
    $('.post-title').live('click',function(){
		if($(this).next().is(':visible')){
			$(this).children().children().text('页面载入中……');
			window.location=$(this).children().children().attr('href')
		}else{
			$('.post-title').removeClass('postdown');
			$(this).addClass('postdown');
			$('.post-content').slideUp(500);
			$(this).next().slideDown(500,function(){
				$('html,body').animate({scrollTop:$(this).offset().top-200},400)
				})}return false});
	$('.post-title:first').addClass('postdown');
	$('.post-content:first').slideDown(500);
	
	//slide
	$(".pagernum a:first").addClass("active");
	var contentWidth = $("#slidecontent ul").width();
    var contentNum = $("#slidecontent ul").size();
    var contentReelWidth = contentWidth * contentNum;
	$("#slidecontent").css({'width' : contentReelWidth});
		rotate = function(){
		var triggerID = $active.attr("rel") - 1; 
		var slidecontentPosition = triggerID * contentWidth;
		$(".pagernum a").removeClass('active'); 
			$active.addClass('active'); 
		$("#slidecontent").animate({
		left: -slidecontentPosition
		}, 500 );
	};

                rotateSwitch = function(){
                    play = setInterval(function(){ 
                        $active = $('.pagernum a.active').next();
                        if ( $active.length === 0) { 
                            $active = $('.pagernum a:first'); 
                        }
                        rotate(); 
                    }, 5000); 
                };

                rotateSwitch(); 

                $("#slidecontent ul").hover(function() {
                    clearInterval(play); 
                }, function() {
                    rotateSwitch(); 
                });

                $(".pagernum a").click(function() {
                    $active = $(this);
                    clearInterval(play);
                    rotate();
                    rotateSwitch();
                    return false;
                });
				
	//favicons
	$(".links a").each(function(e){
	$(this).prepend("<img src=http://www.google.com/s2/favicons?domain="+this.href.replace(/^(http:\/\/[^\/]+).*$/, '$1').replace( 'http://', '' )+">");
	});
	
	//menu
	$('.menus').superfish();
	
});
