﻿if(window.ActiveXObject)var isIE=1;

function $(objectId) {
	if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	return document.getElementById(objectId);
	} 
	else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
		return document.all(objectId);
	} 
	else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this won't find nested layers
		return document.layers[objectId];
	} 
	else {
		return false;
    }
}

function rui_intMenuEvent(sId, tId) {
	var tt;
	var sArr = $(sId).getElementsByTagName("A");
	var tArr = $(tId).getElementsByTagName("UL");
	for(var i=0;i<sArr.length;i++){
		if(sArr[i].className=="actLink"){
			rui_showMenu(sArr,tArr,sArr[i],sArr[i].rel);
			tt=i;
		}
		sArr[i].onmouseover=function(){
			rui_showMenu(sArr,tArr,this,this.rel);
		}
	}
	if(tt){
		$("contents").onmouseover=function(){
			rui_showMenu(sArr,tArr,sArr[tt],sArr[tt].rel);
		}
	}
}
function rui_showMenu(alis,uls,obj,ml) {
	for(var i=0; i<alis.length; i++){
		alis[i].id = "a_id_"+i;
		alis[i].className = "";
		for(var ii=0; ii<uls.length; ii++){
			uls[ii].style.display = "none";
		}
		if(obj.id==alis[i].id)obj.className="actLink";
	}
	if(!ml || !$(ml)){
		obj.style.backgroundImage="none";
	}else{
		$(ml).style.display = "block";
		$(ml).style.left = (isIE)?obj.offsetParent.offsetLeft - 45 + "px":obj.offsetLeft - 45 + "px";
	}
}

function rui_intSecondMenu(objid) {
	var uls = $(objid).getElementsByTagName("UL");
	for(var i=0; i<uls.length; i++) {
		uls[i].style.display = "none";
	}
}

function rui_showPics(objId, objClass, _w, _h, _minw,  _minh) {
	var l1, tName, tClass, tagObj, imgObj;
	l1=objClass.indexOf(".");
	tName=objClass.substring(0,l1).toUpperCase();
	tClass=objClass.substring(l1+1);
	tagObj=$(objId).getElementsByTagName(tName);
	if(tClass && tagObj){
		for(var i=0;i<tagObj.length;i++){
			if(tagObj[i].className==tClass){
				if(tName!="IMG"){
					imgObj=tagObj[i].getElementsByTagName("IMG")[0];
					if(imgObj){
						imgObj.onload=function(){rui_setPicScale(this, _w, _h, _minw, _minh);}
					}
				}else{
					tagObj[i].onload=function(){rui_setPicScale(this, _w, _h, _minw,  _minh);}
				}
			}
		}
	}
}
function rui_setPicScale(obj, _w, _h, _minw, _minh){
	var w = obj.width;
	var h = obj.height;
	if(_w && w>_w)obj.width = _w;
	if(_h && h>_h) {
		obj.height = _h;
		obj.width = w*obj.height/h;
	}
	if(_minw) {
		obj.style.left=-(obj.width-_minw)/2+"px";
	}
	if(_minh) {
		obj.style.top=-(obj.height-_minh)/2+"px";
	}
}

function play() {
	clipControl.onclick=function(){chanImg('pause')};
	clipControl.innerHTML="暂停";
	autoplay=window.setInterval("chanImg(0)",10000);//幻灯片频率
}

function chanImg(meth) {  
	var check;
	var power=10;
	var direct="--";
	clearInterval(convert);
	if (meth==1 || meth==(-1)) {
		imgIndex+=meth;
		check=true;
		clearInterval(autoplay)
		clipControl.onclick=play;
		clipControl.innerHTML="幻灯片播放"
	}
	else if (meth==0) {
			imgIndex++;
			check=true;
		}
	else if (meth=="pause") {
			check=false;
			clearInterval(autoplay);
			clipControl.onclick=play;
			clipControl.innerHTML="幻灯片播放";
		}
	else if (meth=="stop") {
			check=true;
			imgIndex=0;
			clearInterval(autoplay);
			clipControl.onclick=play;
			clipControl.innerHTML="幻灯片播放";
		}
		
	if (check){
			convert=setInterval(chaOpa,30);
		}
	
	function chaOpa() {
		if (imgIndex >= imgsrc.length){imgIndex=0}
		if (imgIndex < 0){imgIndex=imgsrc.length-1}
		eval("power"+direct);
		setOpa();
		power <=0 ? function(){tarImg.src=imgsrc[imgIndex];direct="++"}():(power >=10 ? function(){clearInterval(convert)}():null);
	}
	
	function setOpa() {
		if (tarImg.style.filter!=null) tarImg.style.filter="alpha(opacity="+power*10+")";
		else tarImg.style.opacity=power/10;
	}
}