
Zjport.Gaza = {};

Zjport.Gaza.userInfo=1;


// 获得用户信息
Zjport.Gaza.getUserInfo = function(func){
	if(func){
		if(Zjport.Gaza.userInfo==1){
			Zjport.doSubmit("","/userInfo/userInfo.jspa",{
				onInfo : function(message,messageType){
					if(messageType=="1"){
						Zjport.Gaza.userInfo=undefined;
					}
					else{
						Zjport.Gaza.userInfo=message;
					}
					func(Zjport.Gaza.userInfo);
				}
			});
		}
		else{
			func(Zjport.Gaza.userInfo);
		}
	}
	else{
		if(Zjport.Gaza.userInfo==1){
			Zjport.doSubmit("","/userInfo/userInfo.jspa",{
				onInfo : function(message,messageType){
					if(messageType=="1"){
						Zjport.Gaza.userInfo=undefined;
					}
					else{
						Zjport.Gaza.userInfo=message;
					}
				},
				asynchronous : false
			});
		}
		return Zjport.Gaza.userInfo;
	}
};

// 更新页面访问量的计数器
Zjport.Gaza.doUpdateClickCounter = function(frameId,path,bizCode,bizId){
	var userId=Zjport.getCookie("userId");
	var url="";
	var param;
	if(userId){
		param=$.param({
			"action" : "click",
			"bizCode" : bizCode,
			"bizId" : bizId,
			"userId" : userId,
			"url" : url
		});
	}
	else{
		param=$.param({
			"action" : "click",
			"bizCode" : bizCode,
			"bizId" : bizId,
			"url" : url
		});
	}
	document.getElementById(frameId).src=path+"?"+param;
};

// 对联广告
Zjport.Gaza.Couplet ={};

Zjport.Gaza.Couplet.items = [];
Zjport.Gaza.Couplet.delta = 0.2;
Zjport.Gaza.Couplet.isStart = false;
Zjport.Gaza.Couplet.addItem = function(width,height,x,y,content) {
	var num=Zjport.Gaza.Couplet.items.length;
	var str="<div id='gaza_couplet_item_"+num+"' style='z-index:10;position:absolute;width:"+width+"px;height:"+height+"px;left:"+(typeof(x)=="string"?eval(x):x)+"px;top:"+(typeof(y)=="string"?eval(y):y)+"px'><iframe style='position:absolute;z-index:-1; top:0px;left:0px;width:"+width+"px;height:"+height+"px;border:0;'></iframe>"+content+"<div style='text-decoration:underline;cursor:pointer' onclick='Zjport.Gaza.Couplet.close("+num+");'>关闭</div><br/></div>";
	$(document.body).prepend(str);
　　	var newItem= {};
　　	newItem.object = document.getElementById("gaza_couplet_item_"+num);
　　	newItem.x = x;
　　	newItem.y = y;
	newItem.closed = false;
	Zjport.Gaza.Couplet.items[num]= newItem;
};

Zjport.Gaza.Couplet.start = function() {
	Zjport.Gaza.Couplet.isStart = true;
　　	setInterval('Zjport.Gaza.Couplet.play()',30);
};

Zjport.Gaza.Couplet.play = function(){
　　	for(var i=0;i<Zjport.Gaza.Couplet.items.length;i++) {
		var item=Zjport.Gaza.Couplet.items[i];
		if(!item.closed){
			var followObj= item.object;
	　　		var followObj_x= (typeof(item.x)=='string'?eval(item.x):item.x);
	　　		var followObj_y= (typeof(item.y)=='string'?eval(item.y):item.y);
			var scrollLeft=document.documentElement.scrollLeft;
	　　		if(followObj.offsetLeft!=(scrollLeft+followObj_x)) {
	　　			var dx=(scrollLeft+followObj_x-followObj.offsetLeft)*Zjport.Gaza.Couplet.delta;
				dx=(dx>0?1:-1)*Math.ceil(Math.abs(dx));
				followObj.style.left=followObj.offsetLeft+dx+"px";
	　　		}
			var scrollTop=document.documentElement.scrollTop;
	　　		if(followObj.offsetTop!=(scrollTop+followObj_y)) {
	　　			var dy=(scrollTop+followObj_y-followObj.offsetTop)*Zjport.Gaza.Couplet.delta;
	　　			dy=(dy>0?1:-1)*Math.ceil(Math.abs(dy));
	　　			followObj.style.top=followObj.offsetTop+dy+"px";
	　　		}
		}
　　	}
};

Zjport.Gaza.Couplet.close = function(id) {
	Zjport.Gaza.Couplet.items[id].object.style.display = 'none';
	Zjport.Gaza.Couplet.items[id].closed=true;
};



// 漂浮广告
Zjport.Gaza.Float ={}
Zjport.Gaza.Float.step = 1;
Zjport.Gaza.Float.items = [];
Zjport.Gaza.Float.isStart = false;
Zjport.Gaza.Float.addItem = function(width,height,x,y,xon,yon,content) {
	var num=Zjport.Gaza.Float.items.length;
	var str="<div id='gaza_float_item_"+num+"' style='z-index:11;position:absolute;width:"+width+"px;height:"+height+"px;left:"+(typeof(x)=="string"?eval(x):x)+"px;top:"+(typeof(y)=="string"?eval(y):y)+"px' onmouseover='Zjport.Gaza.Float.stop("+num+");' onmouseout='Zjport.Gaza.Float.resume("+num+");'><iframe style='position:absolute;z-index:-1; top:0px;left:0px;width:"+width+"px;height:"+height+"px;border:0;'></iframe>"+content+"<div style='text-decoration:underline;cursor:pointer' onclick='Zjport.Gaza.Float.close("+num+");'>关闭</div><br/></div>";
　　	$(document.body).prepend(str);
	var newItem= {};
　　	newItem.object = document.getElementById("gaza_float_item_"+num);
　　	newItem.x = (typeof(x)=='string'?eval(x):x);
　　	newItem.y = (typeof(y)=='string'?eval(y):y);
	newItem.xon = xon;
	newItem.yon = yon;                   
	newItem.closed = false;
	newItem.stoped = false;
	Zjport.Gaza.Float.items[num]= newItem;
};

Zjport.Gaza.Float.start = function() {
	Zjport.Gaza.Float.isStart = true;
　　	setInterval('Zjport.Gaza.Float.play()',30);
};

Zjport.Gaza.Float.play = function(){
　　	for(var i=0;i<Zjport.Gaza.Float.items.length;i++) {
		var item=Zjport.Gaza.Float.items[i];
		var step=Zjport.Gaza.Float.step;
		if(!item.closed && !item.stoped){
			item.object.style.left = item.x + document.documentElement.scrollLeft + "px";
			item.object.style.top = item.y + document.documentElement.scrollTop + "px";
			var wMax = document.documentElement.clientWidth-item.object.offsetWidth;
			var hMax = document.documentElement.clientHeight-item.object.offsetHeight;
			if (item.yon) {
				item.y = item.y + step;
			}
			else {
				item.y = item.y - step;
			}
			if (item.y < 0) {
				item.yon = true;
				item.y = 0;
			}
			else if (item.y >= hMax) {
				item.yon = false;
				item.y = hMax;
			}
			if (item.xon) {
				item.x = item.x + step;
			}
			else {
				item.x = item.x - step;
			}
			if (item.x < 0) {
				item.xon = true;
				item.x = 0;
			}
			else if (item.x >= wMax) {
				item.xon = false;
				item.x = wMax;
			}
		}
　　	}
};

Zjport.Gaza.Float.close = function(id) {
	Zjport.Gaza.Float.items[id].object.style.display = 'none';
	Zjport.Gaza.Float.items[id].closed=true;
};

Zjport.Gaza.Float.stop = function(id) {
	Zjport.Gaza.Float.items[id].stoped=true;
};

Zjport.Gaza.Float.resume = function(id) {
	Zjport.Gaza.Float.items[id].stoped=false;
};

Zjport.Gaza.Fullscreen ={};
Zjport.Gaza.Fullscreen.items = [];
Zjport.Gaza.Fullscreen.maxWaitTime = 100;
Zjport.Gaza.Fullscreen.isStart = false;
Zjport.Gaza.Fullscreen.addItem = function(width,height,div,content) {
	var num=Zjport.Gaza.Fullscreen.items.length;
	var str="<div id='gaza_fullscreen_item_"+num+"' style='z-index:12;width:"+width+"px;height:0px;overflow:hidden;color:white'><div style='text-decoration:underline;cursor:pointer' onclick='Zjport.Gaza.Fullscreen.close("+num+");'>关闭</div>"+content+"</div>";
	$("#"+div).prepend(str);
	var newItem= {};
　　	newItem.object = document.getElementById("gaza_fullscreen_item_"+num);
　　	// 最大高度
	newItem.maxHeight = (typeof(height)=='string'?eval(height):height);
　　	newItem.waitTime = 0;
	// open,wait,close
	newItem.state = "open";
	newItem.closed = false;
	Zjport.Gaza.Fullscreen.items[num]= newItem;
};

Zjport.Gaza.Fullscreen.start = function() {
	Zjport.Gaza.Fullscreen.isStart = true;
　　	setInterval('Zjport.Gaza.Fullscreen.play()',5);
};

Zjport.Gaza.Fullscreen.play = function(){
　　	for(var i=0;i<Zjport.Gaza.Fullscreen.items.length;i++) {
		var item=Zjport.Gaza.Fullscreen.items[i];
		if(!item.closed){
			// 打开状态
			if(item.state=="open"){
				var height = item.object.offsetHeight;
				item.object.style.height = height+5+"px";
				if(item.object.offsetHeight>=item.maxHeight){
					item.state="wait";
				}
			}
			// 打开后等待状态
			else if(item.state=="wait"){
				item.waitTime = item.waitTime+1;
				if(item.waitTime>=Zjport.Gaza.Fullscreen.maxWaitTime){
					item.state="close";
				}
			}
			else if(item.state=="close"){
				var height = item.object.offsetHeight;
				item.object.style.height = height-5+"px";
				if(item.object.offsetHeight<=0){
					item.object.style.height = "0px";
					item.object.style.display = 'none';
					item.state="closed";
					item.closed=true;
				}
			}
		}
　　	}
};

Zjport.Gaza.Fullscreen.close = function(id) {
	Zjport.Gaza.Fullscreen.items[id].object.style.display = 'none';
	Zjport.Gaza.Fullscreen.items[id].state="closed";
};



