﻿// JavaScript Document
//图片鼠标经过边框，传入作用域ID
function imgBorderShow(id){
var getimg=new Image();
getimg=document.getElementById(id).getElementsByTagName("img");
for(var i=0;i<getimg.length;i++){
getimg[i].style.border="1px #cccccc solid";
getimg[i].onmouseover=function(){
this.style.border="1px #ff0000 solid";}
getimg[i].onmouseout=function(){
this.style.border="1px #cccccc solid";}
}
}

//图片按比例缩放---素材图片页面控制

function newDrawImage(id,width,height){
var img=new Image();
	img=window.document.getElementById(id).getElementsByTagName("img");
 for(var i=0;i<img.length;i++){
	 	draw(img[i],width,height);
	 }
}
//等比例循环调用函数，传送对象，宽，高
function draw(imgd,width,height){
var flag=false; 
var image=new Image(); 
var iwidth = width;  //定义允许图片宽度 
var iheight = height;  //定义允许图片高度 
image.src=imgd.src; 
if(image.width>0 && image.height>0){ 
flag=true; 
if(image.width/image.height>= iwidth/iheight){ 
if(image.width>iwidth){   
  imgd.width=iwidth; 
  this.height=(image.height*iwidth)/image.width; 
  }else{ 
  imgd.width=image.width;   
  imgd.height=image.height; 
  } 
//  ImgD.alt=image.width+"×"+image.height; 
  } 
 else{ 
  if(image.height>iheight){   
  imgd.height=iheight; 
  imgd.width=(image.width*iheight)/image.height;   
  }else{ 
  imgd.width=image.width;   
  imgd.height=image.height; 
  } 
  //ImgD.alt=image.width+"×"+image.height; 
  } 
 } 
}  


//图片展示左滚动，参数：滚动ID，滚动内容ID，复制到目标的ID
function demoLeft(demo,demo1,demo2){
var speed_left=20;
window.document.getElementById(demo2).innerHTML=window.document.getElementById(demo1).innerHTML;
function marquee_left(){
	if(window.document.getElementById(demo2).offsetWidth-window.document.getElementById(demo).scrollLeft<=0){
		window.document.getElementById(demo).scrollLeft-=window.document.getElementById(demo1).offsetWidth;
	}else{window.document.getElementById(demo).scrollLeft++;}
}
var MyMar_left=setInterval(marquee_left,speed_left);
window.document.getElementById(demo1).onmouseover=function(){clearInterval(MyMar_left);}
window.document.getElementById(demo1).onmouseout=function(){MyMar_left=setInterval(marquee_left,speed_left);}
}

//自制选项卡，传入选项卡的ID
function choice(choice){
	var demo=document.getElementById(choice);
	var lis=demo.getElementsByTagName("li");
	var demo_con=document.getElementById(choice+"_con");
	var contens=demo_con.getElementsByTagName("div");
	
	if(lis.length!=contens.length){return false;}else{
		for(var i=0;i<lis.length;i++){
			lis[i].onmouseover = function(){
				for(var d=0;d<contens.length;d++){
					contens[d].style.display="none";
					if(contens[d].id==this.id+"_con"){
						contens[d].style.display="";
						this.className="onmouseover";}else{
						lis[d].className="";
					}
				}
			}
		}
	}
}


//自制选项卡，传入选项卡的ID
function choice2(choice){
	var demo=document.getElementById(choice);
	var lis=demo.getElementsByTagName("li");
	var demo_con=document.getElementById(choice+"_con");
	var contens=demo_con.getElementsByTagName("div");
	
	if(lis.length!=contens.length){return false;}else{
		for(var i=0;i<lis.length;i++){
			lis[i].onclick = function(){
				for(var d=0;d<contens.length;d++){
					contens[d].style.display="none";
					if(contens[d].id==this.id+"_con"){
						contens[d].style.display="";
						this.className="onmouseover";}else{
						lis[d].className="";
					}
				}
			}
		}
	}
}


//隔行变色  参数:作用ID,作用标签，奇偶数
function listColor(id,tag,py){
	var row = window.document.getElementById(id).getElementsByTagName(tag);
	var parity = 0;
	if(py%2==1){var parity = 1;}else{var parity=0;}
	for(var i=0;i<row.length;i++){
		setColor(row[i],i,parity);
	}
}
//隔行变色的改变背景函数，参数作用标签，标签基偶数，基偶数
function setColor(tag,num,parity){
	if(num%2==parity){tag.style.background = "#f2faff";}else{tag.style.background = "#ffffff";}
	var tagcolor = tag.style.background;
	tag.onmouseover = function(){this.style.background="#ffffcc";}	
	tag.onmouseout = function(){this.style.background=tagcolor;}
}


function showTypeList(id){
	var listtwo = window.document.getElementById(id);
	if(listtwo.style.display=="none"){ listtwo.style.display="";}
	else{listtwo.style.display="none";}
	}
