﻿function $( obj ){
	return document.getElementById( obj );
};

function showAjaxContent(){
	var obj=document.getElementById("navigation");
	var liObj=obj.getElementsByTagName("li");
	var length=liObj.length;
	var currentLiObj;
	for(var i=0;i<length;i++){
		currentLiObj=liObj[i];
		if(currentLiObj.parentNode!=obj){continue;}
		//然后循环添加事件
		currentLiObj.onmouseover=function(){
			if(this.className.indexOf("show")<0){
				this.className+=" show";
			}
			clearStyle(this);
		}		
		currentLiObj.onmouseout=function(){
			this.className=this.className.replace("show","");
			clearStyle(this);
		}
	}
	function clearStyle(obj){
		for(var i=0;i<length;i++){
			currentLiObj=liObj[i];
			if(obj!=currentLiObj){
				currentLiObj.className=currentLiObj.className.replace("show","");
			}
		}
	}
};

function bookmark(title,url){
	if(document.all){
		window.external.AddFavorite(url,title);
	}else if(window.sidebar){
		window.sidebar.addPanel(title,url,'');
	}
};
function setHome(url){
    try{
        document.body.style.behavior='url(#default#homepage)';
        document.body.setHomePage(url);
    }
    catch(e){
        if(window.netscape) {
            try{
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
				var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
				prefs.setCharPref('browser.startup.homepage','http://www.yehealth.com');
            }
            catch(e) { 
                alert("不好意思，此操作被浏览器拒绝……\n请在浏览器地址栏输入“about:config”并回车\n然后将[signed.applets.codebase_principal_support]设置为'true'\n或者直接在选项中设置首页。");
            }
         }
    }
};


//图片轮播
function f_getflash(link1,link2,link3,link4,link5){
	var pic_width=777; //图片宽度
	var pic_height=183; //图片高度
	var button_pos=4; //按扭位置 1左 2右 3上 4下
	var stop_time=5000; //图片停留时间(1000为1秒钟)
	var show_text=0; //是否显示文字标签 1显示 0不显示
	var txtcolor="000000"; //文字色
	var bgcolor="28AEE3"; //背景色
	var imag=new Array();
	var link=new Array();
	var text=new Array();
	//imag[1]="images/cyc/01.jpg";
	imag[1]="imgshow.asp?n=indexcyc1";
	link[1]=link1;
	text[1]="";
	imag[2]="imgshow.asp?n=indexcyc2";
	link[2]=link2;
	text[2]="";
	imag[3]="imgshow.asp?n=indexcyc3";
	link[3]=link3;
	text[3]="";
	imag[4]="imgshow.asp?n=indexcyc4";
	link[4]=link4;
	text[4]="";
	imag[5]="imgshow.asp?n=indexcyc5";
	link[5]=link5;
	text[5]="";
	//可编辑内容结束
	var swf_height=show_text==1?pic_height+20:pic_height;
	var pics="", links="", texts="";
	for(var i=1; i<imag.length; i++){
		pics=pics+("|"+imag[i]);
		links=links+("|"+link[i]);
		texts=texts+("|"+text[i]);
	}
	pics=pics.substring(1);
	links=links.substring(1);
	texts=texts.substring(1);
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+ pic_width +'" height="'+ swf_height +'">');
	document.write('<param name="allowScriptAccess" value="always" />');
	document.write('<param name="movie" value="swf/focus.swf">');
	document.write('<param name="quality" value="high"><param name="wmode" value="opaque">');
	document.write('<param name="FlashVars" value="pics='+pics+'&links='+links+'&texts='+texts+'&pic_width='+pic_width+'&pic_height='+pic_height+'&show_text='+show_text+'&txtcolor='+txtcolor+'&bgcolor='+bgcolor+'&button_pos='+button_pos+'&stop_time='+stop_time+'">');
	document.write('<embed src="swf/focus.swf" FlashVars="pics='+pics+'&links='+links+'&texts='+texts+'&pic_width='+pic_width+'&pic_height='+pic_height+'&show_text='+show_text+'&txtcolor='+txtcolor+'&bgcolor='+bgcolor+'&button_pos='+button_pos+'&stop_time='+stop_time+'" quality="high" width="'+ pic_width +'" height="'+ swf_height +'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
};


//右侧轮播
function f_right_getflash(){
	var pic_width=183; //图片宽度
	var pic_height=160; //图片高度
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+ pic_width +'" height="'+ pic_height +'">');
	document.write('<param name="allowScriptAccess" value="always" />');
	document.write('<param name="movie" value="swf/right_cyc.swf">');
	document.write('<param name="quality" value="high"><param name="wmode" value="opaque">');
	document.write('<embed src="swf/right_cyc.swf" quality="high" width="'+ pic_width +'" height="'+ pic_height +'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
};



//------------------------ScrollText  start------------------------
function ScrollText(content,btnPrevious,btnNext,autoStart){
    this.Delay = 10;
    this.LineHeight = 20;
	this.Amount = 1;//注意:LineHeight一定要能整除Amount.
	this.Direction = "up";
    this.Timeout = 1500;
    this.Level = 1;         //内容的嵌套层级
    this.StartNum = 1;   // 设置开始数量 
    this.ScrollContent = this.$(content);

    //this.ScrollContent.scrollTop = 0;
    if(btnNext){
        this.NextButton = this.$(btnNext);
        this.NextButton.onclick = this.GetFunction(this,"Next");
        this.NextButton.onmouseover = this.GetFunction(this,"Stop");
        this.NextButton.onmouseout = this.GetFunction(this,"Start");
    }
    if(btnPrevious){
        this.PreviousButton = this.$(btnPrevious);
        this.PreviousButton.onclick = this.GetFunction(this,"Previous");
        this.PreviousButton.onmouseover = this.GetFunction(this,"Stop");
        this.PreviousButton.onmouseout = this.GetFunction(this,"Start");
    }
    this.ScrollContent.onmouseover = this.GetFunction(this,"Stop");
    this.ScrollContent.onmouseout = this.GetFunction(this,"Start");
    if(autoStart){
        this.Start();
    }
}
ScrollText.prototype.$ = function(element){
    return document.getElementById(element);
}
ScrollText.prototype.Previous = function(){
    clearTimeout(this.AutoScrollTimer);
    clearTimeout(this.ScrollTimer);
    this.Scroll("up");
}
ScrollText.prototype.Next = function(){
    clearTimeout(this.AutoScrollTimer);
    clearTimeout(this.ScrollTimer);
    this.Scroll("down");
}
ScrollText.prototype.Start = function(){
   switch(this.Level) {
       case 1:
            if (this.ScrollContent.childNodes.length >= this.StartNum) {
                this.ScrollContent.innerHTML += this.ScrollContent.innerHTML;
            }            
   	        break;
       case 2:
            if (this.ScrollContent.firstChild.childNodes.length >= this.StartNum) {
                this.ScrollContent.innerHTML += this.ScrollContent.innerHTML;
            }       
   	        break;
       case 3:
            if (this.ScrollContent.firstChild.firstChild.childNodes.length >= this.StartNum) {
                this.ScrollContent.innerHTML += this.ScrollContent.innerHTML;
            }       
   	        break;   	        
    } 
    
    clearTimeout(this.AutoScrollTimer);
    this.AutoScrollTimer = setTimeout(this.GetFunction(this,"AutoScroll"), this.Timeout);
}
ScrollText.prototype.Stop = function(){
    clearTimeout(this.ScrollTimer);
    clearTimeout(this.AutoScrollTimer);
}
ScrollText.prototype.AutoScroll = function(){
    if(this.Direction == "up"){
        if(parseInt(this.ScrollContent.scrollTop) >= parseInt(this.ScrollContent.scrollHeight) / 2){
            this.ScrollContent.scrollTop = 0;
        }
        this.ScrollContent.scrollTop += this.Amount;
    } else{
        if(parseInt(this.ScrollContent.scrollTop) <= 0){
            this.ScrollContent.scrollTop = parseInt(this.ScrollContent.scrollHeight) / 2;
        }
        this.ScrollContent.scrollTop -= this.Amount;
    }
    if(parseInt(this.ScrollContent.scrollTop) % this.LineHeight != 0){
        this.ScrollTimer = setTimeout(this.GetFunction(this,"AutoScroll"), this.Delay);
    }else{
        this.AutoScrollTimer = setTimeout(this.GetFunction(this,"AutoScroll"), this.Timeout);
    }
}
ScrollText.prototype.Scroll = function(direction){
    if(direction=="up"){
        if(this.ScrollContent.scrollTop == 0){
            this.ScrollContent.scrollTop = parseInt(this.ScrollContent.scrollHeight) / 2;
        }
        this.ScrollContent.scrollTop -= this.Amount;
    }else{
        this.ScrollContent.scrollTop += this.Amount;
    }
    if(parseInt(this.ScrollContent.scrollTop) >= parseInt(this.ScrollContent.scrollHeight) / 2){
            this.ScrollContent.scrollTop = 0;
    }
    if(parseInt(this.ScrollContent.scrollTop) % this.LineHeight != 0){
        this.ScrollTimer = setTimeout(this.GetFunction(this,"Scroll",direction), this.Delay);
    }
}
ScrollText.prototype.GetFunction = function(variable,method,param){
    return function()
    {
        variable[method](param);
    }
}
