var intro;
var introHeight = 0;

function bfc_setFlashAttribute(){
	var embedTagObj=document.getElementsByTagName("EMBED");
	var flashObject=document.getElementsByTagName("OBJECT");
	if(embedTagObj.length>0){
		for(var i=0;i<embedTagObj.length;i++){
			embedTagObj[i].setAttribute("wmode","transparent");
		}
	}
	if(flashObject.length>0){
		for(var i=0;i<flashObject.length;i++){
			if(flashObject[i].getAttribute("classid")=="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" || flashObject[i].getAttribute("type")=="application/x-shockwave-flash"){
				var paramTagObj=flashObject[i].getElementsByTagName("PARAM");
				if(paramTagObj.length>0){
					var haveWmode=false;
					for(var j=0;j<paramTagObj.length;j++){
						if(paramTagObj[j].getAttribute("name")=="wmode"){
							paramTagObj[j].setAttribute("value","transparent");	
							haveWmode=true;
						}
					}
					if(!haveWmode){
						var params=document.createElement("param");
						params.setAttribute("name","wmode");
						params.setAttribute("value","transparent");
						flashObject[i].appendChild(params);
					}
				}
			}
		}
	}
}

function bfc_createCSS(sel, decl, media, newStyle) {
  var dynamicStylesheet, dynamicStylesheetMedia;
  var h = document.getElementsByTagName("head")[0];
  if (!h) { return; } // to also support badly authored HTML pages that lack a head element
  var m = (media && typeof media == "string") ? media : "screen";
  if (newStyle) {
    dynamicStylesheet = null;
    dynamicStylesheetMedia = null;
  }
  if (!dynamicStylesheet || dynamicStylesheetMedia != m) {
    // create dynamic stylesheet + get a global reference to it
    var s = document.createElement("style");
    s.setAttribute("type", "text/css");
    s.setAttribute("media", m);
    dynamicStylesheet = h.appendChild(s);
    if (typeof document.styleSheets != "undefined" && document.styleSheets.length > 0) {
      dynamicStylesheet = document.styleSheets[document.styleSheets.length - 1];
    }
    dynamicStylesheetMedia = m;
  }
  // add style rule
  if (dynamicStylesheet && typeof dynamicStylesheet.addRule == "object") {
    dynamicStylesheet.addRule(sel, decl);
  }
}

function bfc_setVisibility(id, isVisible){
	var e = document.getElementById(id);
	if (e){
		var v = e.style.visibility;
		if (isVisible){
			if (v != "visible"){
				e.style.visibility = "visible";
			}
		}else{
			if (v != "hidden"){
				e.style.visibility = "hidden";
			}
		}
	}
}

//实时设置浮动层的位置
function bfc_moveIntroduced(){
	if (intro && typeof intro === "object"){
		var _height = parseInt(intro.style.height);
		if (_height > 0){
    	intro.style.top = document.documentElement.scrollTop + document.documentElement.clientHeight - _height - 1;
    	setTimeout("bfc_moveIntroduced();",100);
    }
  }
}

function bfc_showIntroduced(pos){
  if (intro && typeof intro === "object"){
	  var _lasttop = document.documentElement.scrollTop + document.documentElement.clientHeight; 
		var _height = parseInt(intro.style.height);
	  var _lineHeight=10;
	  if (pos > 0){
	  	bfc_setVisibility(intro.id, true);
		  if (_height < introHeight){
		  	_height += _lineHeight*pos;
		  	if (_height > introHeight)
		  		_height = introHeight;
	  		intro.style.top = _lasttop - _height - 1;
		    intro.style.height = _height;
		    setTimeout('bfc_showIntroduced(1)',2);
		  }else{
		  	bfc_moveIntroduced();
		  }		  	
	  }  
	  else if (pos < 0){
	  	if (_height > 0){
	  		_height += _lineHeight*pos;
	  		if (_height < 0)
	  			_height = 0;
	  		intro.style.top = _lasttop - _height - 1;
		    intro.style.height = _height;
		    setTimeout('bfc_showIntroduced(-1)',2);
		  }else{
		  	bfc_setVisibility(intro.id, false);
			}
		}
	}  
}

function bfc_initIntroduced(id, appdsc, closeImg){
  if (intro) return;
  intro=document.getElementById(id);
  if (!intro)
  {
    var newObj = document.createElement("div");
    newObj.setAttribute("id", id);
    newObj.setAttribute("class", id);
    newObj.innerHTML = '<a class="bfc_closeIntroduced" id="bfc_closeIntroduced" href="javascript:;" title="关闭操作说明"></a><h2>操作说明：</h2><p class="content"></p>';
    document.body.appendChild(newObj);
    intro=document.getElementById(id);
    if (!intro) return;
    bfc_createCSS("#" + id, "position:absolute;left:0;width:100%;z-index:4;color:#ffffff;overflow:hidden;background:#ffffff;filter:Alpha(opacity='80');opacity:0.8;border-top:1px #D2D9DE solid;");
    bfc_createCSS("a.bfc_closeIntroduced", "position:absolute;width:16px;height:17px;right:4px;top:4px;background:url(" + closeImg + ") no-repeat;");
    bfc_createCSS("a.bfc_closeIntroduced:hover", 'background-position:-17px 0;');
    bfc_createCSS("#" + id +" h2", "float:left;margin:10px 0 0 20px;height:40px;width:80px; font-size:13px;color:#1C6CA3;");
    bfc_createCSS("#" + id +" .content", "float:left;padding:8px 30px 10px 0; line-height:22px;color:#222222;");
  }
	
	if (appdsc == "null" || appdsc == "")
		appdsc = "暂无介绍内容";
  intro.getElementsByTagName("p")[0].innerHTML = appdsc;
  introHeight = intro.clientHeight;
  intro.style.height = 0;
  intro.style.top = document.documentElement.scrollTop + document.documentElement.clientHeight - introHeight - 1;  
  document.getElementById("bfc_closeIntroduced").onclick=function(){//关闭操作提示
    bfc_showIntroduced(-1);
  }
}

function bfc_opIntroduced(){//关闭提示
  bfc_setFlashAttribute();
  var bfcapps={"id":0,"url":'%appurl%',"dsc":'%appdsc%',"type":'%apptype%',"height":600,"width":800,"closeImg":'%rootpath%/images/cloud_app_content_close.png'};
  bfc_initIntroduced("bfc_introduced", bfcapps.dsc, bfcapps.closeImg);
  if(parseInt(intro.style.height) != 0){
    bfc_showIntroduced(-1);
  }else{
    bfc_showIntroduced(1);
  }
}
