var current_pic_index = 0;
var pic_urls = ["http://www.jguoer.com/blog/wp-content/themes/jguoer/images/topanou0.png",
                    "http://www.jguoer.com/blog/wp-content/themes/jguoer/images/topanou1.png"
               ];

var pic_url_links = ["http://www.jguoer.com/blog/index.php/archives/1110","#"];

var pic_num = pic_urls.length;
$(document).ready(function(){
	addTitle("home");
	addTitle("work");
	addTitle("design");
	addTitle("theme");
	addTitle("about");
	addTitle("douban");
    
    var title_num = Math.ceil(Math.random()*10);
    var titles = ["用心对待每一行代码",
              "生活，要TMD有激情",
              "酒后秒杀丈母娘",
              "为了巫妖王",
              "程序员出没，请注意",
              "活着就是为了改变世界，难道还有其他原因吗",
              "点我订阅JGuoer的RSS",
              "哇哈哈，哇哈哈，每个人脸上都笑开颜",
              "0527爱上了0718",
              "怎么办？豆瓣"
             ];
    var title = titles[title_num];
    $("#topdesc a").html(title);

    $("#anoucontent").html("<a href=\"" + pic_url_links[current_pic_index] + "\"><img src=\"" + pic_urls[current_pic_index] + "\"/></a>");

    var pointer_html = "<ul>";
    for(var temp=0; temp<pic_num; temp++){
        if(temp==current_pic_index){
            pointer_html += "<li class=\"p_a\" index=\"" + temp + "\"></li>";
        }else{
            pointer_html += "<li class=\"p_n\" index=\"" + temp + "\"></li>";
        }
    }
    pointer_html += "</ul>";
    $("#pointer").html(pointer_html);

	$("#sidebar #recentbody li").hover(
		function () {
			$(this).css("background-color","gray");
			$(this).css("background-image","images/posts.png");
			$(this).css("color","white");
			$(this).css("text-shadow","0 1px 0 black");
			
			if(this.getElementsByTagName("a").length>0)
			{
				for(var temp=0;temp<this.getElementsByTagName("a").length;temp++)
				{
					var ele = this.getElementsByTagName("a")[temp];
					$(ele).css("color","white");
					$(ele).css("text-shadow","0 1px 0 black");
				}
			}
		},
		function () {
			$(this).css("background-color","#e4e4e4");
			$(this).css("background-image","images/view.png");
			$(this).css("color","#3B3B3B");
			$(this).css("text-shadow","0 1px 0 white");
			if(this.getElementsByTagName("a").length>0)
			{
				for(var temp=0;temp<this.getElementsByTagName("a").length;temp++)
				{
					var ele = this.getElementsByTagName("a")[temp];
					$(ele).css("color","#3B3B3B");
					$(ele).css("text-shadow","0 1px 0 white");
				}
			}
		}
	);
	
	$(".details img").css("background","transparent");
	$(".commentbody img").css("background","transparent");
	$(".commentbody img").css("border","none");
	$(".code img").css("background","transparent");
    
    $("#douban_ra2").css("margin","18px 0");
    $("#douban_ra2").css("padding-top","15px");
	$("#douban_ra2").css("padding-left","2px");
    
	$("#sidebar #recentcommentsbody li").hover(
		function () {
			$(this).css("background-color","gray");
			$(this).css("background-image","images/posts.png");
			$(this).css("color","white");
			$(this).css("text-shadow","0 1px 0 black");
			if(this.getElementsByTagName("a").length>0)
			{
				for(var temp=0;temp<this.getElementsByTagName("a").length;temp++)
				{
					var ele = this.getElementsByTagName("a")[temp];
					$(ele).css("color","white");
					$(ele).css("text-shadow","0 1px 0 black");
				}
			}
		},
		function () {
			$(this).css("background-color","#e4e4e4");
			$(this).css("background-image","images/view.png");
			$(this).css("color","#3B3B3B");
			$(this).css("text-shadow","0 1px 0 white");
			if(this.getElementsByTagName("a").length>0)
			{
				for(var temp=0;temp<this.getElementsByTagName("a").length;temp++)
				{
					var ele = this.getElementsByTagName("a")[temp];
					$(ele).css("color","#3B3B3B");
					$(ele).css("text-shadow","0 1px 0 white");
				}
			}
		}
	);
	
	$("#sidebar #link li").hover(
		function () {
			$(this).css("background-color","gray");
			$(this).css("background-image","images/posts.png");
			$(this).css("color","white");
			$(this).css("text-shadow","0 1px 0 black");
			if(this.getElementsByTagName("a").length>0)
			{
				for(var temp=0;temp<this.getElementsByTagName("a").length;temp++)
				{
					var ele = this.getElementsByTagName("a")[temp];
					$(ele).css("color","white");
					$(ele).css("text-shadow","0 1px 0 black");
				}
			}
		},
		function () {
			$(this).css("background-color","#e4e4e4");
			$(this).css("background-image","images/view.png");
			$(this).css("color","#3B3B3B");
			$(this).css("text-shadow","0 1px 0 white");
			if(this.getElementsByTagName("a").length>0)
			{
				for(var temp=0;temp<this.getElementsByTagName("a").length;temp++)
				{
					var ele = this.getElementsByTagName("a")[temp];
					$(ele).css("color","#3B3B3B");
					$(ele).css("text-shadow","0 1px 0 white");
				}
			}
		}
	);
    add_event(current_pic_index);
    $($("#commentlist ol li").last()).css("border-bottom","none");
});

function addTitle(title){
	$("#header ."+title+"").hover(
		function () {
			$(this).attr("class",""+title+"active");
		},
		function () {
			$(this).attr("class",title);
		}
	);
}

function quote(name){
	var value = $("#comment").attr("value");
	$("#comment").attr("value",value+"@"+name+"\n");
}

function change_pointer(pic_num, current_pic_index){
    $("#pointer ul li").attr("class","p_n");
    $($("#pointer ul li")[current_pic_index]).attr("class","p_a");
}

function add_event(current_pic_index){
    $("#pointer ul li").click(function(){
        var index = $(this).attr("index");
        current_pic_index = parseInt(index);
        $("#anoucontent").hide();
        $("#anoucontent").html("<a href=\"" + pic_url_links[current_pic_index] + "\"><img index=\"" + current_pic_index + "\" src=\"" + pic_urls[current_pic_index] + "\"/></a>");
        $("#anoucontent").fadeIn();
        change_pointer(pic_num, current_pic_index);
    });

    $(".blog_h2 a").click(function(){
        $(this).html("请稍等，我正在努力的加载中..");
    });
}

$(".main_anou #goleft").click(function(){
    if (current_pic_index>0){
        current_pic_index -= 1;
    }
    $("#anoucontent").hide();
    $("#anoucontent").html("<a href=\"" + pic_url_links[current_pic_index] + "\"><img index=\"" + current_pic_index + "\" src=\"" + pic_urls[current_pic_index] + "\"/></a>");
    $("#anoucontent").fadeIn();
    change_pointer(pic_num, current_pic_index);
});

$(".main_anou #goright").click(function(){
    if (current_pic_index<pic_num - 1){
        current_pic_index += 1;
    }
    $("#anoucontent").hide();
    $("#anoucontent").html("<a href=\"" + pic_url_links[current_pic_index] + "\"><img index=\"" + current_pic_index + "\" src=\"" + pic_urls[current_pic_index] + "\"/></a>");
    $("#anoucontent").fadeIn();
    change_pointer(pic_num, current_pic_index);
});

