function hj$(id) {
	return document.getElementById(id);
}
function updateseccode() {
	var rand = Math.random();
	hj$('seccodeimage').innerHTML = '<img id="seccode" onclick="updateseccode()" src="' + blogurl + 'seccode.php?update=' + rand + '" class="codeimg" alt="单击图片换张图片" />';
}

jQuery.intval = function (v){
	v = parseInt(v);
	return isNaN(v) ? 0 : v;
};

jQuery.getPos = function (e){
	var l = 0;
	var t  = 0;
	var w = jQuery.intval(jQuery.css(e,'width'));
	var h = jQuery.intval(jQuery.css(e,'height'));
	var wb = e.offsetWidth;
	var hb = e.offsetHeight;
	while (e.offsetParent){
		l += e.offsetLeft + (e.currentStyle?jQuery.intval(e.currentStyle.borderLeftWidth):0);
		t += e.offsetTop  + (e.currentStyle?jQuery.intval(e.currentStyle.borderTopWidth):0);
		e = e.offsetParent;
	}
	l += e.offsetLeft + (e.currentStyle?jQuery.intval(e.currentStyle.borderLeftWidth):0);
	t  += e.offsetTop  + (e.currentStyle?jQuery.intval(e.currentStyle.borderTopWidth):0);
	return {x:l, y:t, w:w, h:h, wb:wb, hb:hb};
};

var xPos;
var yPos;
$(document).mousemove(function(evt){
    evt=evt || window.event;
	if(evt.pageX){
    	xPos=evt.pageX;
    	yPos=evt.pageY;
	} else {
	    xPos=evt.clientX+document.body.scrollLeft-document.body.clientLeft;
	    yPos=evt.clientY+document.body.scrollTop-document.body.clientTop;
	}
});
$(document).ready(function(){
	var hclose;
	var tempXPos;
	var isMoved = false;
	var Showing;
	$("#news li").mouseout(function(){
		clearTimeout(Showing);
		hclose = setTimeout('$(".hiddencontent").fadeOut(300)',1500);
									  });
	$("#news li").mouseover(function(){
		if(isMoved) {
			$(".hiddencontent").stop('true');
			$(".hiddencontent").animate({left: tempXPos});
		}
		isMoved = false;
		clearTimeout(hclose);
									  });
	$("#news li").children("a").mouseover(function(){
												   var that = this;
												   clearTimeout(Showing);
												   Showing = setTimeout(function(){
		if($(that).parent("li").next(".hiddencontent").css("display") == "none") {
			var parentPos = jQuery.getPos($("#news").get(0));
			var childPos = jQuery.getPos(that);
			$(that).parent("li").next(".hiddencontent").css("left",function(){if(xPos-parentPos.x < 280){tempXPos = 285; return "285px"; }else{tempXPos = xPos-parentPos.x+5 ;return xPos-parentPos.x+5 + "px";}});
			$(that).parent("li").next(".hiddencontent").css("top",childPos.y-parentPos.y +"px");
			$(".hiddencontent").fadeOut(300);
			$(".hiddencontent .post-body").slideUp(100);
			$(that).parent("li").next('.hiddencontent').slideDown(function() {
																		   $(this).find(".post-body").slideDown();
																		   });
			if($("#news > h1").position().left != 0) {
				$("#news").children("h1").css({position:"relative"});
				$("#news").children("h1").css("left:-"+ $("#news > h1").position().left + "px");
			}
		}

																	   }, 800);
	});
	$("#sidebar *").mouseover(function(){
		if(!isMoved) {
			$(".hiddencontent").animate({left:'10px'}, 500, function() {isMoved = true;});
		}
		clearTimeout(hclose);
									 });
	$(".hiddencontent .post-title").children("span").click(function(){
			$(".hiddencontent").fadeOut(300);
			$(".hiddencontent .post-body").slideUp(100);
																	});
});
$('a[href^=#cm]').click(function(){
    $('[name='+this.href.split('#')[1]+']').ScrollTo(800);
    return false;
});
