$(function(){
	//首页访问日志
	$.post(context+"/index/visit/"+siteId, {}, function (data) {
		$("#indexVisit").html(data.msg);
	}, "json");
	
	index_ad();//首页头部广告
	couplet_ad();//对联广告
	leafingStart();//漂浮广告
});
function index_ad(){//首页头部广告
	var html=$("#head_ad").html();
	$("#head_ad").remove();
	$("body").prepend('<div id="head_ad">'+html+'</div>');
 	$("#head_ad").slideDown(2000);
	setTimeout(closeAd,3000);
}
function couplet_ad(){
	$("#daleft,#daright").show();
 	$(window).scroll(function(){coupletScorll();});
	$("span.couplet_ad_close").click(function(){
		$(this).parent().remove();									  
	});
}
function coupletScorll(){
	var speed=1//速度数值越大速度越慢
	var maxHeight=$("body").height();
	function coupletMarquee(){
		flag=reachBottom();
 		var h=$(document).scrollTop()+150;
		var divh=$("#daright").offset().top;
		if(divh==h || divh>=maxHeight){
			clearInterval(couplet);
			return false;
		}else if(divh<h && flag==1){
			divh=divh+1;
			$("#daright,#daleft").css({"top": divh});  
		}else if(divh>h){
			divh=divh-1;
			$("#daright,#daleft").css({"top": divh});
		}	
	}
	var couplet=setInterval(coupletMarquee,speed)
}
function closeAd(){
	$("#head_ad").slideUp(2000);
}
function leafingStart(){
	var len=$("div.leafing_ad").length;
	for(i=0;i<len;i++){
		var top=$("div.leafing_ad").eq(i).attr('top');
		var left=$("div.leafing_ad").eq(i).attr('left');
		var id="leafing_ad_"+i;
		var x=200*(i+1),y=300*(i+1);
 		leafing_ad(id,top,left,x,y);
	}
}
function leafing_ad(id,top,left,x,y){
 	var xin = true, yin = true 
	var step = 1 
	var delay = 30 
	var obj=document.getElementById(id) 
	function leafing_admove() { 
		var L=T=0
		var R= document.documentElement.clientWidth-obj.offsetWidth; 
		var B = document.documentElement.clientHeight-obj.offsetHeight; 
		obj.style.left = x + document.documentElement.scrollLeft+'px'; 
		obj.style.top = y + document.documentElement.scrollTop+'px'; 
		x = x + step*(xin?1:-1) 
		if (x < L) { xin = true; x = L} 
		if (x > R){ xin = false; x = R} 
		y = y + step*(yin?1:-1) 
		if (y < T) { yin = true; y = T } 
		if (y > B) { yin = false; y = B } 
	} 
	var itl= setInterval(leafing_admove,delay) 
	obj.onmouseover=function(){clearInterval(itl)} 
	obj.onmouseout=function(){itl=setInterval(leafing_admove, delay)}
	$("p.leafing_close_ad").click(function(){
		$(this).parent().remove();									   
	});
}
function reachBottom() {
    var b=$("body").height();
    var o=$("#daright").offset().top;
	var h=$("#daright").height();
	o=o+h;
 	if(b==o){
		return 0;
	}else{
		return 1;
	}
}
