/*=====================================轮换幻灯片=========================================*/
var $ = function (id) {
	return "string" == typeof id ? document.getElementById(id) : id;
}

var Class = {
  create: function() {
	return function() {
	  this.initialize.apply(this, arguments);
	}
  }
}

Object.extend = function(destination, source) {
	for (var property in source) {
		destination[property] = source[property];
	}
	return destination;
}

var TransformView = Class.create();
TransformView.prototype = {
  //容器对象,滑动对象,切换参数,切换数量
  initialize: function(container, slider, parameter, count, options) {
	if(parameter <= 0 || count <= 0) return;
	var oContainer = $(container), oSlider = $(slider), oThis = this;

	this.Index = 0;//当前索引
	
	this._timer = null;//定时器
	this._slider = oSlider;//滑动对象
	this._parameter = parameter;//切换参数
	this._count = count || 0;//切换数量
	this._target = 0;//目标参数
	
	this.SetOptions(options);
	
	this.Up = !!this.options.Up;
	this.Step = Math.abs(this.options.Step);
	this.Time = Math.abs(this.options.Time);
	this.Auto = !!this.options.Auto;
	this.Pause = Math.abs(this.options.Pause);
	this.onStart = this.options.onStart;
	this.onFinish = this.options.onFinish;
	
	oContainer.style.overflow = "hidden";
	oContainer.style.position = "relative";
	
	oSlider.style.position = "absolute";
	oSlider.style.top = oSlider.style.left = 0;
  },
  //设置默认属性
  SetOptions: function(options) {
	this.options = {//默认值
		Up:			true,//是否向上(否则向左)
		Step:		4,//滑动变化率
		Time:		3,//滑动延时
		Auto:		true,//是否自动转换
		Pause:		5000,//停顿时间(Auto为true时有效)
		onStart:	function(){},//开始转换时执行
		onFinish:	function(){}//完成转换时执行
	}
	Object.extend(this.options, options || {});
  },
  //开始切换设置
  Start: function() {
	if(this.Index < 0){
		this.Index = this._count - 1;
	} else if (this.Index >= this._count){ this.Index = 0; }
	
	this._target = -1 * this._parameter * this.Index;
	this.onStart();
	this.Move();
  },
  //移动
  Move: function() {
	clearTimeout(this._timer);
	var oThis = this, style = this.Up ? "top" : "left", iNow = parseInt(this._slider.style[style]) || 0, iStep = this.GetStep(this._target, iNow);
	
	if (iStep != 0) {
		this._slider.style[style] = (iNow + iStep) + "px";
		this._timer = setTimeout(function(){ oThis.Move(); }, this.Time);
	} else {
		this._slider.style[style] = this._target + "px";
		this.onFinish();
		if (this.Auto) { this._timer = setTimeout(function(){ oThis.Index++; oThis.Start(); }, this.Pause); }
	}
  },
  //获取步长
  GetStep: function(iTarget, iNow) {
	var iStep = (iTarget - iNow) / this.Step;
	if (iStep == 0) return 0;
	if (Math.abs(iStep) < 1) return (iStep > 0 ? 1 : -1);
	return iStep;
  },
  //停止
  Stop: function(iTarget, iNow) {
	clearTimeout(this._timer);
	this._slider.style[this.Up ? "top" : "left"] = this._target + "px";
  }
}

window.onload=function(){
	function Each(list, fun){
		for (var i = 0, len = list.length; i < len; i++) { fun(list[i], i); }
	};
	
	var objs = $("idNum").getElementsByTagName("li");
	
	var tv = new TransformView("idTransformView", "idSlider", 280, 3, {
		onStart : function(){ Each(objs, function(o, i){ o.className = tv.Index == i ? "on" : ""; }) }//按钮样式
	})
	
	tv.Start();
	
	Each(objs, function(o, i){
		o.onmouseover = function(){
			o.className = "on";
			tv.Auto = false;
			tv.Index = i;
			tv.Start();
		}
		o.onmouseout = function(){
			o.className = "";
			tv.Auto = true;
			tv.Start();
		}
	})
	var ow=document.body.offsetWidth;
	var oh=document.body.offsetHeight
	document.getElementById("msgbg").style.height=oh+"px";
	document.getElementById("msgbox").style.left=(ow-parseInt(477))/2+"px";
	divProcess();
	showAd2();
	hiddenAd2();
}

/*=====================================轮换幻灯片2=========================================*/
function getid(obj)//取对应id的元素
		  {
			return document.getElementById(obj);
		  }

	function getNames(obj,name,tij)//取obj元素下标签为tij的元素并要求满足name属性=name;返回一个数组
	{	
		var p = getid(obj);
		var plist = p.getElementsByTagName(tij);
		var rlist = new Array();
		for(i=0;i<plist.length;i++)
		{
			if(plist[i].getAttribute("name") == name)
			{
				rlist[rlist.length] = plist[i];
			}
		}
		return rlist;
	}

	function ri(obj)//取得对应的小图列表中当前元素对应的序号
	{
		var p = getid("simg").getElementsByTagName("li");
		for(i=0;i<p.length;i++)
		{
			if(obj == p[i])
			{
				return i;
			}
		}
	}

	function ci(obj)//小图选择框的处理函数
	{
		var p = getid("simg").getElementsByTagName("li");
		for(i=0;i<p.length;i++)
		{
			if(obj ==p[i])
			{
				p[i].className = "s";
			}
			else
			{
				p[i].className = "";
			}
		}
	}
	function fiterplay(obj,num,t,name)//类似页卡的函数.设置对应内容的隐藏和显示 obj:元素的id  name:元素对应的name属性的值, t:对应内容的标签 num:当前选择的元素的序号
	{
		var fitlist = getNames(obj,name,t);
		for(i=0;i<fitlist.length;i++)
		{

			if(i == num)
			{
				fitlist[i].className = "dis";
			}
			else
			{
				fitlist[i].className = "undis";
			}
		}
	}
		  
		  	
	function play(obj,n1,n2)//播放的函数
	{
		var p = obj.parentNode.getElementsByTagName("li");
		var bimg = getid(n1);
		var infos = getid(n2);
		var num = ri(obj);
		try	//ie下的处理部分
		{
			with(bimg)
			{
				filters[0].Apply();	//接收滤镜
				ci(obj); //变幻小图的选择.可以放在try以外.
				fiterplay(n1,num,"div","f");//设置滤镜中对应部分的显示和隐藏
				filters[0].play();	//播放滤镜
				//alert(p[0].innerHTML)
			}
		with(infos)
			{
				filters[0].Apply();	//接收滤镜
				ci(obj); //变幻小图的选择.可以放在try以外.
				fiterplay(n2,num,"div","f");//设置滤镜中对应部分的显示和隐藏
				filters[0].play();	//播放滤镜
			}
		}
		catch(e)//ff下的处理部分
		{
				ci(obj);
				fiterplay(n1,num,"div","f");
				fiterplay(n2,num,"div","f");
		}
	}
var n=0;
function clearAuto() {clearInterval(autoStart);};
function setAuto(){autoStart=setInterval("auto(n)", 4000)}
function auto()
{
	var x = getid("simg").getElementsByTagName("li");
	n++;
	if(n>x.length-1)n=0;
	play(x[n],"bimg","infos");
} 

 setAuto();
