dojo.provide("frame.js.sfConfig");
dojo.global.slife=dojo.global.slife || {};
dojo.global.slife.frame={};
var $sf;
(function(){
	var tempVar={
		hasBackground:false,
		coverAll:true,
		transparentIndex:60,
		frameContainerSize:{isRate:true,rate:0.5},
		minHeight:600,
		minWidth:900,
		minFrameHeight:150,
		minFrameWidth:300,
		//frameContainerSize:{height:300,width:400},
		frameUrl:"",
		pageInnerHTML:"",
		frameParameter:{},
		frameBorder:"0",
		frameScrolling:"yes",
		position:{},
		isControlPosition:false,
		isDynamic:false,
		language:"auto",
		sfStyle:"sfDefault",
		errorMessage:"",
		titleContent:"",
		titleImage:"",
		isMove:true,
		isResize:true,
		langList:[{name:'en',charset:'UTF-8'},{name:'zh-cn',charset:'gb2312'}],
		skinList:[{name:'sfDefault',charset:'gb2312'},{name:'sfBlack',charset:'gb2312'},{name:'sfQQ',charset:'gb2312'}]
	};

	dojo.global.slife.frame["create"] = S;
	var TopContainer=window,N="document",H="documentElement",A="getElementsByTagName",sfStatus;
	if(TopContainer.$sf){
		try{
			dojo.byId("my97");
		}
		catch(P){
			sfStatus=P.number==-2146823277?true:false
		}
	}
	if(!TopContainer.$sf){
		$sf=Q({
			sfVersion:2,
			sfPath:2,
			sfwin:TopContainer,
			sfRP:dojo.baseUrl+"../frame/",
			pgel:null,
			status:sfStatus?2:0,
			cssAmount:0,
			resizeTimer:null,
			scroll:{top:0,left:0},
			dSize:{height:0,left:0},
			hasLoaded:false,
			hadLoaded:false,
			childPageHandler:null,
			showsf:function(_){
				if(this.sfObjectContainer){
					this.sfObjectContainer.style.display="block";
					if(_){
						this.sfBackground.style.display="block";
					}else{
						this.sfBackground.style.display="none";
					}
				}
			},
			hidesf:function(){
				if(this.sfObjectContainer){
					this.sfObjectContainer.style.display="none";
					this.sfBackground.style.display="none";
				}
			}
		});
		if(!sfStatus){
			X(TopContainer,function(){S(null,true)});
		}
	}
	else{
		$sf=TopContainer.$sf;
	}

	function Q(_){
		TopContainer.$sf=TopContainer.$sf||{};
		for(var $ in _){
			TopContainer.$sf[$]=_[$];
		}
		return TopContainer.$sf;
	}

	function C(A,$,_){
		_._eventHandler=function($){return _($)};
		if($ == "onload"){
			dojo.addOnLoad(_._eventHandler);
		}else{
			dojo.connect(A, $.replace(/on/,"") , _._eventHandler);
		}
	}

	function X($,_){
		C($,"onload",_);
	}
	
	function S(C,$){
	    if(dojo.isIE && document.readyState!="complete"){
	        if(!($sf.hasLoaded)){
                $sf.hasLoaded=true;
                setTimeout(Bind(this,_S),500);
            }
            function _S(){
               $sf.hadLoaded=true;
               S(C,true);
            }
	    }else{
	        $sf.hadLoaded=true;
	    }
	    if($sf.hadLoaded){
	        $sf.sfwin = TopContainer;
		    C=C||{};
		    if($){
			    $sf.status=1;
			    I({pgel:{innerHTML:""}},true);
		    }
		    else{
			    if($sf.status==0){
				    $sf.status=1;
			    }
			    else if($sf.status!=2){
				    return;
			    }
			    var B,A=_();
			    if(A){
				    B=A.srcElement||A.target;
				    A.cancelBubble=true;
			    }
			    if($sf.hasBackground){
			        if(dojo.isIE){
			            document.selection.empty();
			        }else{
			            window.getSelection().removeAllRanges();
			        }
			    }
			    C.pgel=dojo.byId(C.pgel||B);
				if(!C.pgel||C.pgel&&C.pgel.disabled||(C.pgel==$sf.pgel&&$sf.sfObjectContainer.style.display!="none"&&$sf.sfObjectContainer.style.left!="-1970px")){
					return;
				}
				I(C);
		    }
	    }
		
		function _(){
			if(dojo.isFF || dojo.isKhtml){
				func=_.caller;
				while(func!=null){
					var $=func.arguments[0];
					if($&&($+"").indexOf("Event")>=0){
						return $;
					}
					func=func.caller;
				}
				return null;
			}
			return event;
		}
	}

	function I(G,A){
		for(var F in tempVar){
			if(F.substring(0,1)!="$"){
				$sf[F]=tempVar[F];
			}
		}
		for(F in G){
			if($sf[F]===undefined){
				$sf.errorMessage="invalid property:"+F;
			}else{
				$sf[F]=G[F];
			}
		}
		$sf.pgelContent=$sf.pgel&&$sf.pgel.nodeName=="INPUT"?"value":"innerHTML";
		if($sf.pgel[$sf.pgelContent]==null){
			return;
		}
		if($sf.language=="auto"){
			$sf.language=dojo.isIE?navigator.browserLanguage.toLowerCase():navigator.language.toLowerCase();
		}
		if(!$sf.sfObjectContainer||($sf.language&&$sf.explorerLanguage&&$sf.explorerLanguage.name!=$sf.language)){
			if($sf.sfObjectContainer){
				TopContainer[N].body.removeChild($sf.sfObjectContainer);
			}
			var ps=pageSize();
			var height=ps.h,rHeight=ps.h,width=ps.w,rWidth=ps.w,dHeight=ps.dh,dWidth=ps.dw;
			if(parseInt(height) < $sf.minHeight){
				height=$sf.minHeight;
			}
			if(parseInt(width) < $sf.minWidth){
				width=$sf.minWidth;
			}
			$sf.sfBackground = TopContainer[N].createElement("div");
			$sf.sfBackground.id="DivCoverBackground";
			if($sf.coverAll){
				if(parseInt(dHeight)>parseInt(height)){
					$sf.sfBackground.style.height=parseInt(dHeight)+"px";
				}else{
					$sf.sfBackground.style.height=parseInt(height)+"px";
				}
				if(parseInt(dWidth)>parseInt(width)){
					$sf.sfBackground.style.width=parseInt(dWidth)+"px";
				}else{
					$sf.sfBackground.style.width=parseInt(width)+"px";
				}
			}else{
				$sf.sfBackground.style.height = parseInt(height)+"px";
				$sf.sfBackground.style.width = parseInt(width)+"px";
			}
			if(dojo.isIE){
				$sf.sfBackground.style.filter = "alpha(opacity:"+$sf.transparentIndex+")";	
			}else{
				$sf.sfBackground.style.opacity = $sf.transparentIndex / 100;
			}
			TopContainer[N].body.appendChild($sf.sfBackground);
			$sf.sfObjectContainer = TopContainer[N].createElement("div");
			$sf.sfObjectContainer.id = "DivFrameContainer";
			initDivFrameContainer(height,width,$sf.sfObjectContainer,rHeight,rWidth);
			TopContainer[N].body.appendChild($sf.sfObjectContainer);
			if(A){
			    dojo.require("frame.js.frame");
				new SlifeFrame();
				$sf.hidesf();
				$sf.status=2;
			}else{
				fds();
				R();
				$sf.showsf($sf.hasBackground);
				if(!($sf.hasBackground)&&$sf.isControlPosition){
					IC();
				}
			}
		}
		else if($sf.instance){
			fds();
			R();
			$sf.showsf($sf.hasBackground);
			$sf.instance.init();
			if(!($sf.hasBackground)&&$sf.isControlPosition){
				IC();
			}
		}
	}

	function fds(){
		$sf.fixDivSize={};
		if($sf.sfStyle=="sfQQ"){
			$sf.fixDivSize.act=26;
			$sf.fixDivSize.actc=60;
			$sf.fixDivSize.acby=26;
			$sf.fixDivSize.acbm=26;
		}else{
			$sf.fixDivSize.act=18;
			$sf.fixDivSize.actc=50;
			$sf.fixDivSize.acby=8;
			$sf.fixDivSize.acbm=8;
		}
	}
	
	function R(){
		var fhfs = dojo.byId("DivFrameHead");
		var ps=pageSize();
		var height=ps.h,rHeight=ps.h,width=ps.w,rWidth=ps.w,dHeight=ps.dh,dWidth=ps.dy;
		if(parseInt(height) > 1000){
			fhfs.style.fontSize=18+"px";
		}else if(parseInt(height) > 800 && parseInt(height) < 1000){
			fhfs.style.fontSize=15+"px";
		}else if(parseInt(height) > 600 && parseInt(height) < 800){
			fhfs.style.fontSize=12+"px"
		}else{
			fhfs.style.fontSize=9+"px";
		}
		if(parseInt(height) < $sf.minHeight){
			height=$sf.minHeight;
		}
		if(parseInt(width) < $sf.minWidth){
			width=$sf.minWidth;
		}
		if($sf.hasBackground){
		    Scroll($sf.sfObjectContainer,TopContainer,$sf.sfBackground.clientHeight,$sf.sfBackground.clientWidth);
		}
	    if($sf.dSize.height!=rHeight || $sf.dSize.width!=rWidth){
			if($sf.hasBackground){
			    if($sf.coverAll){
				    if(parseInt(dHeight)>parseInt(height)){
					    $sf.sfBackground.style.height=parseInt(dHeight)+"px";
				    }else{
					    $sf.sfBackground.style.height=parseInt(height)+"px";
				    }
				    if(parseInt(dWidth)>parseInt(width)){
					    $sf.sfBackground.style.width=parseInt(dWidth)+"px";
				    }else{
					    $sf.sfBackground.style.width=parseInt(width)+"px";
				    }
			    }else{
				    $sf.sfBackground.style.height = parseInt(height)+"px";
				    $sf.sfBackground.style.width = parseInt(width)+"px";
			    }
			    if(dojo.isIE){
				    $sf.sfBackground.style.filter = "alpha(opacity:"+$sf.transparentIndex+")";	
			    }else{
				    $sf.sfBackground.style.opacity = $sf.transparentIndex / 100;
			    }
		    }
		    initDivFrameContainer(height,width,$sf.sfObjectContainer,rHeight,rWidth);
		    $sf.dSize.height=rHeight;
		    $sf.dSize.width=rWidth;
	    }
	    if($sf.isMove){
	        initDivFrameContainer(height,width,$sf.sfObjectContainer,rHeight,rWidth);
	    }else{
	        $sf.resizeTimer = TopContainer.setTimeout(R,500);
	    }
	}
	
	function pageSize(){
	    var aa=TopContainer[N],ab=aa[H],ac=aa.body;
		//alert(TopContainer[N][H].scrollHeight)
		if(TopContainer[N][H].clientHeight>0){
		    return {h:ab.clientHeight,w:ab.clientWidth,dh:ab.scrollHeight,dw:ab.scrollWidth};
		}else{
		    return {h:ac.clientHeight,w:ac.clientWidth,dh:ac.scrollHeight,dw:ac.scrollWidth};
		}
	}

	function initDivFrameContainer(H,W,O,rH,rW){
		if($sf.frameContainerSize.isRate){
			O.style.height=Math.round(H*$sf.frameContainerSize.rate)+"px";
			O.style.width=Math.round(W*$sf.frameContainerSize.rate)+"px";
		}else{
			O.style.height=$sf.frameContainerSize.height +"px";
			O.style.width=$sf.frameContainerSize.width + "px";	
		}
		if($sf.instance&&$sf.instance.sfcd.frameHeadDiv){
		    var _titleContent="";
			$sf.instance.sfcd.frameHeadDiv.getElementsByTagName("div")[1].style.width=(parseInt(O.style.width)-$sf.fixDivSize.act)+"px";
		    if(dojo.isIE==6){
				$sf.instance.sfcd.frameHeadDiv.style.position="relative";
				$sf.instance.sfcd.frameHeadDiv.getElementsByTagName("div")[3].style.position="absolute";
				$sf.instance.sfcd.frameHeadDiv.getElementsByTagName("div")[3].style.right=15+"px";
			}else{
				$sf.instance.sfcd.frameHeadDiv.getElementsByTagName("div")[2].style.width=Math.round(parseInt(O.style.width)-$sf.fixDivSize.actc)+"px";
			}
			if($sf.titleImage==""){
				_titleContent="<img align=\"bottom\" src=\""+$sf.sfRP+"skin/home.png"+"\" class=\"ImgTitle\"/>";
			}else{
				_titleContent="<img align=\"bottom\" src=\""+$sf.titleImage+"\" class=\"ImgTitle\" />";
			}
			_titleContent+=$sf.titleContent;
			$sf.instance.sfcd.frameHeadDiv.getElementsByTagName("div")[2].innerHTML=_titleContent;
		}
		if($sf.instance&&$sf.instance.sfcd.frameBody){
		    $sf.instance.sfcd.frameBody.getElementsByTagName("div")[1].style.width=(parseInt(O.style.width)-$sf.fixDivSize.acby)+"px";
		}
		if($sf.instance&&$sf.instance.sfcd.frameBottom){
		    $sf.instance.sfcd.frameBottom.getElementsByTagName("div")[1].style.width=(parseInt(O.style.width)-$sf.fixDivSize.acbm)+"px";     
		}
		var _sc=Y(TopContainer);
		if($sf.hasBackground||!($sf.isControlPosition)){
			var _=Math.round((rW-parseInt(O.style.width))/2);
			var $=Math.round((rH-parseInt(O.style.height))/2);
			if($>0){
			    O.style.top=($+_sc.top)+"px";
			}else{
			    O.style.top=(_sc.top)+"px";
			}
			if(_>0){
			    O.style.left=(_+_sc.left)+"px";
			}else{
				O.style.left=(_sc.left)+"px";
			}
		}
		//alert(O.style.top)
	}

	function IC(){
		var F=$sf.position.left;
		var B=$sf.position.top;
		var G=U($sf.pgel);
		//$=E(ViewContainer),
		var C=M(TopContainer);
		var A=Y(TopContainer);
		var D=$sf.sfObjectContainer.offsetHeight;
		var _=$sf.sfObjectContainer.offsetWidth;
		if(isNaN(B)){
			if(B=="above"||(B!="under"&&((G.bottom+D>C.height)&&(G.top-D>0)))){
				B=A.top+G.top-D-3;
			}
			else{
				B=A.top+G.bottom;
			}
			B+=dojo.isIE?-1:1;
		}
		else{
			B+=A.top;	
		}
		if(isNaN(F)){
			if(_ > C.width){
				F=A.left+G.left-(dojo.isIE?2:0);
			}else{
				F=A.left+Math.min(G.left,C.width-_-5)-(dojo.isIE?2:0);
			}
		}
		else{
			F+=A.left;
		}
		$sf.sfObjectContainer.style.top=B+"px";
		$sf.sfObjectContainer.style.left=F+"px";
	}

	function U(E){
		if(dojo.isIE){
			return E.getBoundingClientRect();
		}
		else{
			var A={ROOT_TAG:/^body|html$/i,OP_SCROLL:/^(?:inline|table-row)$/i},
				G=null,
				_=E.offsetTop,
				F=E.offsetLeft,
				D=E.offsetWidth,
				B=E.offsetHeight,
				C=E.offsetParent;
			if(C!=E){
				while(C){
					F+=C.offsetLeft;
					_+=C.offsetTop;
					if(C.tagName.toLowerCase()=="body"){
						G=C.ownerDocument.defaultView;
					}
					C=C.offsetParent;
				}
			}
			C=E.parentNode;
			while(C.tagName&&!A.ROOT_TAG.test(C.tagName)){
				if(C.scrollTop||C.scrollLeft){
					if(!A.OP_SCROLL.test(C.style.display)){
						if(!dojo.isOpera||C.style.overflow!=="visible"){
							F-=C.scrollLeft;
							_-=C.scrollTop;
						}
					}
				}
				C=C.parentNode;
			}
			var $=Y(G);
			F-=$.left;
			_-=$.top;
			D+=F;
			B+=_;
			return{"left":F,"top":_,"right":D,"bottom":B};
		}
	}

	function E($){
		$=$||TopContainer;
		var B=0,_=0;
		while($!=TopContainer){
			var D=$.parent[N][A]("iframe");
			for(var F=0;F<D.length;F++){
				try{
					if(D[F].contentWindow==$){
						var E=U(D[F]);
						B+=E.left;
						_+=E.top;
						break;
					}
				}
				catch(C){}
			}
			$=$.parent;
		}
		return{"leftM":B,"topM":_};
	}

	function M($){
		$=$||TopContainer;
		var _=$[N];
		_=_[H]&&_[H].clientHeight&&_[H].clientHeight<=_.body.clientHeight?_[H]:_.body;
		return{"width":_.clientWidth,"height":_.clientHeight};
	}

	function Y($){
		$=$||TopContainer;
		var B=$[N],A=B[H],_=B.body;
		B=(A&&A.scrollTop!=null&&(A.scrollTop>_.scrollLeft||A.scrollLeft>_.scrollLeft))?A:_;
		return{"top":B.scrollTop,"left":B.scrollLeft};
	}
	
	function Scroll($,_,h,w){
	    _=_||TopContainer;
	    var _sc=Y(_);
	    var sfH=parseInt($sf.sfObjectContainer.style.height);
	    var sfW=parseInt($sf.sfObjectContainer.style.width);
	    if((_sc.top !=$sf.scroll.top) || (_sc.left != $sf.scroll.left)){
	        if(_sc.top>$sf.scroll.top){
	            var t=parseInt($.style.top)+(_sc.top-$sf.scroll.top);
	            if((t+sfH)>h){
	                $.style.top=(h-sfH)+"px";
	            }else{
	                $.style.top=t+"px";
	            }
	        }else{
	            var t=parseInt($.style.top)-($sf.scroll.top-_sc.top);
	            if((t+sfH)>h){
	                $.style.top=(h-sfH-2)+"px";
	            }else{
	                var _h=$sf.dSize.height;
	                if(_h>$sf.minHeight){
	                    $.style.top=t+"px";
	                }else{
	                    if((_sc.top+sfH)<h){
	                        if((_h-sfH)>0){
	                            $.style.top=(_sc.top+Math.round((_h-sfH)/2))+"px";
	                        }else{
	                            $.style.top=_sc.top+"px";
	                        }
	                    }
	                }
	            }
	        }
            if(_sc.left>$sf.scroll.left){
                var l=parseInt($.style.left)+(_sc.left-$sf.scroll.left);
                if((l+sfW)>w){
                    $.style.left=(w-sfW)+"px";
                }else{
                    $.style.left=l+"px";
                }
            }else{
                var l=parseInt($.style.left)-($sf.scroll.left-_sc.left);
                if((l+sfW)>w){
                    $.style.left=(l-sfW-2)+"px";
                }else{
                    var _w=$sf.dSize.width;
                    if(_w>$sf.minWidth){
                        $.style.left=l+"px";
                    }else{
                        if((_sc.left+sfW)<w){
                            if((_w-sfW)>0){
                                $.style.left=(_sc.left+Math.round((_w-sfW)/2))+"px";
                            }else{
                                $.style.left=_sc.left+"px";
                            }  
                        }
                    }
                }  
            }
	        $sf.scroll.top=_sc.top;
	        $sf.scroll.left=_sc.left;
	    }
	}
})()
