function menuFix() {
    var sfEls = document.getElementById("nav").getElementsByTagName("li");
    for (var i=0; i<sfEls.length; i++) {
        sfEls[i].onmouseover=function() {
        this.className+=(this.className.length>0? " ": "") + "sfhover";
        }
        sfEls[i].onMouseDown=function() {
        this.className+=(this.className.length>0? " ": "") + "sfhover";
        }
        sfEls[i].onMouseUp=function() {
        this.className+=(this.className.length>0? " ": "") + "sfhover";
        }
        sfEls[i].onmouseout=function() {
        this.className=this.className.replace(new RegExp("( ?|^)sfhover\\b"), 
"");
        }
    }
}
window.onload=menuFix;


function $(id) { return document.getElementById(id); }
function addLoadEvent(func){
 var oldonload = window.onload;
 if (typeof window.onload != 'function') {
  window.onload = func;
 } else {
  window.onload = function(){
   oldonload();
   func();
  }
 }
}
function addBtn() {
 if(!$('ibanner')||!$('ibanner_pic')) return;
 var picList = $('ibanner_pic').getElementsByTagName('a');
 if(picList.length==0) return;
 var btnBox = document.createElement('div');
 btnBox.setAttribute('id','ibanner_btn');
 var SpanBox ='';
 for(var i=1; i<=picList.length; i++ ) {
  var spanList = '<span class="normal">'+i+'</span>';
  SpanBox += spanList;
 }
 btnBox.innerHTML = SpanBox;
 $('ibanner').appendChild(btnBox);
 $('ibanner_btn').getElementsByTagName('span')[0].className = 'current';
 for (var m=0; m<picList.length; m++){
  var attributeValue = 'picLi_'+m
  picList[m].setAttribute('id',attributeValue);
 }
}
function moveElement(elementID,final_x,final_y,interval) {
 if (!document.getElementById) return false;
 if (!document.getElementById(elementID)) return false;
 var elem = document.getElementById(elementID);
 if (elem.movement) {
  clearTimeout(elem.movement);
 }
 if (!elem.style.left) {
  elem.style.left = "0px";
 }
 if (!elem.style.top) {
  elem.style.top = "0px";
 }
 var xpos = parseInt(elem.style.left);
 var ypos = parseInt(elem.style.top);
 if (xpos == final_x && ypos == final_y) {
  moveing = false;
  return true;
 }
  if (xpos < final_x) {
    var dist = Math.ceil((final_x - xpos)/10);
    xpos = xpos + dist;
  }
  if (xpos > final_x) {
    var dist = Math.ceil((xpos - final_x)/10);
    xpos = xpos - dist;
  }
  if (ypos < final_y) {
    var dist = Math.ceil((final_y - ypos)/10);
    ypos = ypos + dist;
  }
  if (ypos > final_y) {
    var dist = Math.ceil((ypos - final_y)/10);
    ypos = ypos - dist;
  }
 elem.style.left = xpos + "px";
 elem.style.top = ypos + "px";
 var repeat = "moveElement('"+elementID+"',"+final_x+","+final_y+","+interval+")";
 elem.movement = setTimeout(repeat,interval);
}
function classNormal() {
 var btnList = $('ibanner_btn').getElementsByTagName('span');
 for (var i=0; i<btnList.length; i++){
  btnList[i].className='normal';
 }
}
function picZ() {
 var picList = $('ibanner_pic').getElementsByTagName('a');
 for (var i=0; i<picList.length; i++){
  picList[i].style.zIndex='1';
 }
}
var autoKey = false;
function iBanner() {
 if(!$('ibanner')||!$('ibanner_pic')||!$('ibanner_btn')) return;
 $('ibanner').onmouseover = function(){autoKey = true};
 $('ibanner').onmouseout = function(){autoKey = false};
 var btnList = $('ibanner_btn').getElementsByTagName('span');
 var picList = $('ibanner_pic').getElementsByTagName('a');
 if (picList.length==1) return;
 picList[0].style.zIndex='2';
 for (var m=0; m<btnList.length; m++){
  btnList[m].onmouseover = function() {
   for(var n=0; n<btnList.length; n++) {
    if (btnList[n].className == 'current') {
     var currentNum = n;
    }
   }
   classNormal();
   picZ();
   this.className='current';
   picList[currentNum].style.zIndex='2';
   var z = this.childNodes[0].nodeValue-1;
   picList[z].style.zIndex='3';
   if (currentNum!=z){
    picList[z].style.left='650px';
    moveElement('picLi_'+z,0,0,10);
   }
  }
 } 
}
setInterval('autoBanner()', 3000);//每个图片的停留时间
function autoBanner() {
 if(!$('ibanner')||!$('ibanner_pic')||!$('ibanner_btn')||autoKey) return;
 var btnList = $('ibanner_btn').getElementsByTagName('span');
 var picList = $('ibanner_pic').getElementsByTagName('a');
 if (picList.length==1) return;
 for(var i=0; i<btnList.length; i++) {
  if (btnList[i].className == 'current') {
   var currentNum = i;
  }
 }
 if (currentNum==(picList.length-1) ){
  classNormal();
  picZ();
  btnList[0].className='current';
  picList[currentNum].style.zIndex='2';
  picList[0].style.zIndex='3';
  picList[0].style.left='980px';
  moveElement('picLi_0',0,0,10);
 } else {
  classNormal();
  picZ();
  var nextNum = currentNum+1;
  btnList[nextNum].className='current';
  picList[currentNum].style.zIndex='2';
  picList[nextNum].style.zIndex='3';
  picList[nextNum].style.top='260px';
  moveElement('picLi_'+nextNum,0,0,10);
 }
}
addLoadEvent(addBtn);
addLoadEvent(iBanner);

function ScrollImgLeft(){
var speed=18
var scroll_begin = document.getElementById("scroll_begin");
var scroll_end = document.getElementById("scroll_end");
var scroll_div = document.getElementById("scroll_div");
scroll_end.innerHTML=scroll_begin.innerHTML
function Marquee(){
    if(scroll_end.offsetWidth-scroll_div.scrollLeft<=0)
      scroll_div.scrollLeft-=scroll_begin.offsetWidth
    else
      scroll_div.scrollLeft++
}
var MyMar=setInterval(Marquee,speed)
scroll_div.onmouseover=function() {clearInterval(MyMar)}
scroll_div.onmouseout=function() {MyMar=setInterval(Marquee,speed)}
}

var  flag=false;  
function  DrawImage(ImgD){  
     var  image=new  Image();  
     image.src=ImgD.src;  
     if(image.width>0  &&  image.height>0){  
       flag=true;  
       if(image.width/image.height>=  160/120){  
         if(image.width>160){      
         ImgD.width=160;  
         ImgD.height=(image.height*160)/image.width;  
         }else{  
         ImgD.width=image.width;      
         ImgD.height=image.height;  
         }  
         ImgD.alt=image.width+"×"+image.height;  
         }  
       else{  
         if(image.height>120){      
         ImgD.height=120;  
         ImgD.width=(image.width*120)/image.height;            
         }else{  
         ImgD.width=image.width;      
         ImgD.height=image.height;  
         }  
         ImgD.alt=image.width+"×"+image.height;  
         }  
       }  
}  

function clearstr(seb){
	if(seb.value=='请输入搜索关键字'){
		seb.value='';
	}
	setfoc(seb);
}

function addstr(seb){
	if(seb.value==''){
		seb.value='请输入搜索关键字';
	}
}

function SearchA()
{
	if (document.Search.Keyworks.value==""||document.Search.Keyworks.value=="请输入搜索关键字")
  {
    alert("请输入您要搜索的关键字！  ");
	document.Search.Keyworks.focus();
	return false;
  }
}

function CheckForm()
{
  if (document.Add.NicName.value=="")
  {
    alert("您忘记填写姓名了！  ");
	document.Add.NicName.focus();
	return false;
  }
  if (document.Add.Tel.value=="")
  {
    alert("您忘记填写联系电话了！  ");
	document.Add.Tel.focus();
	return false;
  }
  if (document.Add.Email.value=="")
  {
    alert("您忘记填写Email了！  ");
	document.Add.Email.focus();
	return false;
  }
  if (document.Add.Title.value=="")
  {
    alert("您忘记填写标题了！  ");
	document.Add.Title.focus();
	return false;
  }
  if (document.Add.Conter.value=="")
  {
    alert("您忘记填写内容了！  ");
	document.Add.Conter.focus();
	return false;
  }
}

function addFavorites() { // 加入收藏
    if (document.all) {
        window.external.addFavorite(document.URL + '',document.title+'');
    }
    else if (window.sidebar) {
        window.sidebar.addPanel(""+document.title,document.URL+'','');
    }
}
function setHomepage() { // 设为首页
    if (document.all) {
        document.body.style.behavior = 'url(#default#homepage)';
        document.body.setHomePage(document.URL);
    }
    else if (window.sidebar) {
        if (window.netscape) {
            try {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            }
            catch (e) {
                alert("该操作被浏览器拒绝，假如想启用该功能，请在地址栏内输入 about:config,然后将项 signed.applets.codebase_principal_support 值该为true");
            }
        }
        var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
        prefs.setCharPref("browser.startup.homepage", document.URL);
    } 
}
