﻿/*
幻灯片显示层类
作者：Andyfoo
Email：andyfoo@163.com
*/
/*
<style>
// 幻灯片
.slide{}
.slide .con{height:186px;}
.slide .con div,.slide .con img{filter:revealTrans(duration=0.5,transition=23 ) blendTrans(duration=0.5) Alpha(Opacity=100,FinishOpacity=99,Style=0);}

.slide .btn{position:relative;text-align:right;margin-top:-32px;margin-right:5px;padding:0px;cursor:pointer }
</style>
<div class="slide" id="slide_ad_div">
	<div class="con">
		<div id="slide_ad_item_1"><a href="#"><img class="con" src="images/demo/index_slide1.jpg" border="0" /></a></div>
		<div id="slide_ad_item_2" style="display:none"><a href="#"><img src="images/demo/index_slide2.jpg" border="0" /></a></div>
		<div id="slide_ad_item_3" style="display:none"><a href="#"><img src="images/demo/index_slide3.jpg" border="0" /></a></div>
		<div id="slide_ad_item_4" style="display:none"><a href="#"><img src="images/demo/index_slide4.jpg" border="0" /></a></div>
		<div id="slide_ad_item_5" style="display:none"><a href="#"><img src="images/demo/index_slide5.jpg" border="0" /></a></div>
	</div>
	<div class="btn">
		<img src="images/index_slide_1.gif" id="slide_ad_btn_1" />
		<img src="images/index_slide_2.gif" id="slide_ad_btn_2" />
		<img src="images/index_slide_3.gif" id="slide_ad_btn_3" />
		<img src="images/index_slide_4.gif" id="slide_ad_btn_4" />
		<img src="images/index_slide_5.gif" id="slide_ad_btn_5" />				
	</div>
	
</div>
<script src="images/js/scroll_div.js"></script>
//幻灯片
var slideAD = new slideDiv("slideAD");
slideAD.OnShowItem = function (n){
	slideAD.btn_id[n-1].src = "images/index_slide_" + n + "_s.gif";
}
slideAD.OnHideItem = function (n){
	slideAD.btn_id[n-1].src = "images/index_slide_" + n + ".gif";
}
slideAD.start(4, "slide_ad_div", "slide_ad_btn", null, "slide_ad_item");

*/

function slideDiv(name)
{ 
	this._self = this;
	this._name = name;

	this._auto_stop=false;
	this._play_img = null;
	this._slideTime = 4000;
	
	this.main_id = null;
	this.btn_id = new Array();
	this.arr_id = new Array();
	this.con_id = new Array();

	this.maxItem = 0;
	this.OnShowItem = new Function();
	this.OnHideItem = new Function();
	this._isStop=false;
	
	//初始化
	this.start = function(num, main, btn, arr, con){
		var _this = this;
		if(!btn)this.btn_id=null;
		if(!arr)this.arr_id=null;
		this.main_id = getID(main);
		this.maxItem = num;
		for(var i = 1; i<=num; i++){
			if(btn){
				this.btn_id[i-1] = getID(btn + "_" + i);
				this.btn_id[i-1].setAttribute("val",i);
				this.btn_id[i-1].onmouseover=function() {_this.show(parseInt(this.getAttribute("val") , 10))};
			}

			if(arr){
				this.arr_id[i-1] = getID(arr + "_" + i);
			}
			this.con_id[i-1] = getID(con + "_" + i);
		}

		this.main_id.onmouseover = function() {_this._isStop=true}
		this.main_id.onmouseout = function() {_this._isStop=false}
		this.auto_show();
	}
	this.show = function(n){
		for(var i = 0; i < this.maxItem; i++){
			if(n == i+1){
				this.con_id[i].style.display = "";
				this.OnShowItem(n);
			}else{
				this.con_id[i].style.display = "none";
				this.OnHideItem(i+1);
			}
		}
	}
	this.show2 = function(n){
		for(var i = 0; i<this.maxItem; i++){
			if(n == i+1){
				this.focus_play_filter(i);
				//this.con_id[i].style.display = "";
				this.OnShowItem(n);
			}else{
				this.con_id[i].style.display = "none";
				this.OnHideItem(i+1);
			}
		}
	}

	this.auto_show = function(n){
		if(!this._isStop && typeof(n) == 'number' && n>=1){
			if(!n || n>this.maxItem){
				n=1;
			}
			this.show2(n);
			n++;
		}
		if(typeof(n) == 'undefined')var n=2;
		if(typeof(n) != 'number')n=2;
		window.setTimeout(this._name + ".auto_show(" + n + ")",  this._slideTime);
	}


	this.focus_play_filter = function(n){
		var obj = this.con_id[n];
		
		var imgs = this.con_id[n].getElementsByTagName("IMG");
		var img = imgs[0];
		if(document.all){
			try{
				obj.style.display = '';
				img.style.visibility = 'hidden';
				img.filters.revealTrans.apply();
				img.style.visibility = 'visible';
				img.filters.revealTrans.play();

			}catch(e){
				//alert(e.description)
				try{
					obj.style.MozOpacity = 0;
					obj.style.display = '';
					img.style.visibility = 'visible';
					this.focus_play_fade(n, 0.1);
				}catch(e){
					obj.style.display = '';
					img.style.visibility = 'visible';
				}
			}
		}else{
			try{
				obj.style.MozOpacity = 0;
				obj.style.display = '';
				this.focus_play_fade(n, 0.1);
			}catch(e){
				obj.style.display = '';
			}
		}	
	}
	this.focus_play_fade = function(n, o){
		if(o >= 1)return;
		var obj = this.con_id[n];
		if(o > 0 && o <= 1) {
			try{
				if(Browser.Opera){
					obj.style.opacity = o;
				}else{
					obj.style.MozOpacity = o;
				}
				
			}catch(e){
				
			}
		}
		o = o + 0.1;
		window.setTimeout(this._name + ".focus_play_fade(" + n + ", " + o + ")",  100);
	}
}
