
var FadInitTop=18;
function FadGetCurrentLeft(pos, width){
	var docwidth=777; var space=3;
	//FadDebug(document.documentElement.offsetWidth);
	//return left - width - space;
	var totalwidth=document.documentElement.offsetWidth?document.documentElement.offsetWidth:document.body.offsetWidth;
	
	var left=0;
	if(pos=="left"){
		left=(totalwidth-docwidth)/2 - space - width;
	}else{
		left=(totalwidth-docwidth)/2 + space + docwidth;
	}
	return left;
}

function FadDebug(text){
	var d=document.getElementById("faddebug");
	d.style.cssText="display:block; left:0px; top:0px;";
	if(d){d.innerHTML=text;}
}

function FadSetPosition(obj, pos, top, width, height){
	if(obj){
		var left=FadGetCurrentLeft(pos, width);
		left-=7;
		//FadDebug(obj.style.cssText);
		if(obj.style.cssText.length>=12 && obj.style.cssText.length<=16){
		}else{
			//left=0;
			var scrollTop=document.body.scrollTop?document.body.scrollTop:document.documentElement.scrollTop;
			var top=parseInt(FadInitTop+scrollTop+top);
			//
			obj.style.cssText="position:absolute;left:"+left+"px;top:"+top+"px; width:"+width+"px;height:"+(height+21)+"px;overflow:hidden;";
			//FadDebug(obj.style.cssText);
		}
	}
}

function FadShow(pos, top, width, height, src, href){
	var topcontainer=document.getElementById("fad"+pos);
	var container=document.getElementById("fad"+pos+"_"+top);
	if(!container){
		container=document.createElement("div");
		topcontainer.appendChild(container);
		container.id="fad"+pos+"_"+top;
	}
	if(container){
		
		FadSetPosition(container, pos, top, width, height);
		//var left=FadGetCurrentLeft(pos, width);
		//container.style.cssText="position:absolute;left:"+left+"px;top:"+FadInitTop+"px; width:"+width+"px;height:"+(height+21)+"px;overflow:hidden;";
		var link=document.createElement("a");
		container.appendChild(link);
		link.href=href;
		var image=document.createElement("img");
		link.appendChild(image);
		image.src=src;
		image.border=0;
		var closespan=document.createElement("span");
		container.appendChild(closespan);
		closespan.style.cssText="clear:both;display:block; margin-top:2px; text-align:center;";
		var closetxt=document.createElement("span");
		closespan.appendChild(closetxt);
		closetxt.style.cssText="cursor:pointer;font-size:10px;color:#999999;";
		closetxt.innerHTML="Close";
		closetxt.onclick=function(){
			container.style.cssText="display:none;";
		}
		// resize
		var originalResizeHandler=window.onresize;
		window.onresize=function(){
			if(originalResizeHandler){
				originalResizeHandler();
			}
			FadSetPosition(container, pos, top, width, height);
		}
		// scroll
		var originalScrollHandler=window.onscroll;
		window.onscroll=function(){
			if(originalScrollHandler){
				originalScrollHandler();
			}
			FadSetPosition(container, pos, top, width, height);
		}
	}
}

/* FadShow(pos, top, width, height, src, href) */

//FadShow("left", 0, 100,300,"images/090101_notify.png","#");
//FadShow("right", 0, 90, 300, "http://xlphoto.com.cn/TempImages/notify_09_51hol.gif", "http://xlphoto.com.cn/page.2009_51notify.aspx");

FadShow("left", 60, 120, 110, "http://xlphoto.com.cn/TempImages/main_left_xhbb.gif", "http://xhbb.xlphoto.com.cn");
//FadShow("left", 220, 95, 110, "http://xlphoto.com.cn/TempImages/2010_springfestival.gif", "http://xlphoto.com.cn/page.2010spfstvl.aspx");
FadShow("right", 60, 101, 150, "http://xlphoto.com.cn/TempImages/repair_sideicon.gif", "http://m.xlphoto.com.cn/RepairServiceMain.aspx");
FadShow("right", 220, 92, 150, "http://xlphoto.com.cn/TempImages/notify_partner.gif", "http://xlphoto.com.cn/partner");

