var myFocus={
 //Design By Koen @ 2010.8.x
 //http://hi.baidu.com/koen_li
 $:function(id){return document.getElementById(id);},
 $$:function(tag,obj){return (typeof obj=='object'?obj:this.$(obj)).getElementsByTagName(tag);},
 style:function(obj,style){return (+[1,])?window.getComputedStyle(obj,null)[style]:obj.currentStyle[style];},//getStyle简化版
 easeOut:function(t,b,c,d){return -c*((t=t/d-1)*t*t*t - 1) + b;},
 move:function(obj,prop,val,type,spd,fn){//运动函数，spd为运动需要的时间，时间越大速度越小
  var t=0,b=parseInt(this.style(obj,prop)),c=val-b,d=spd||50,st=type,m=c>0?'ceil':'floor';
  if(obj[prop+'Timer']) clearInterval(obj[prop+'Timer']);
  obj[prop+'Timer']=setInterval(function(){
   if(t<d){obj.style[prop]=Math[m](myFocus[st](++t,b,c,d))+'px';}
   else {clearInterval(obj[prop+'Timer']);fn&&fn.call(obj);}
  },10);return this;
 },
 addList:function(obj,cla,x){//生成HMTL,cla为列表的class,其中封装有:cla='txt'(生成alt文字),cla='num'(生成按钮数字),cla='thumb'(生成小图)
  var s=[],n=x||this.$$('li',this.$$('ul',obj)[0]).length,num=cla.length;
  for(var j=0;j<num;j++){
   s.push('<ul class='+cla[j]+'>');
   for(var i=0;i<n;i++){s.push('<li>'+(cla[j]=='num'?(i+1):(cla[j]=='txt'?this.$$('li',obj)[i].innerHTML.replace(/\<img.*?\>/i,this.$$('img',obj)[i].alt):(cla[j]=='thumb'?'<img src='+(this.$$('img',obj)[i].getAttribute("thumb")||this.$$('img',obj)[i].src)+' />':'')))+'<span></span></li>')};
   s.push('</ul>');
  }; obj.innerHTML+=s.join('');
 },
 setting:function(par){
  if(window.attachEvent){window.attachEvent('onload',function(){myFocus[par.style](par)});}
　　  else{window.addEventListener('load',function(){myFocus[par.style](par)},false);}
 },
 mF_liuzg:function(par){
  var box=this.$(par.id),boxH=box.offsetHeight,t=par.time*1000;
  this.addList(box,['txt-bg','txt','num']);
  var pic=this.$$('li',this.$$('ul', box)[0]),n=pic.length;
  var c=boxH%par.chip?8:par.chip,h=boxH/c,pics=[];
  for(var i=0;i<c;i++){
   pics.push('<li><p>')
   for(var j=0;j<n;j++) pics.push(pic[j].innerHTML);
   pics.push('</p></li>')
  }
  this.$$('ul', box)[0].innerHTML=pics.join('');
  var ul=this.$$('ul',box),txt=this.$$('li',ul[2]),btn=this.$$('li',ul[3]),pic=this.$$('li',ul[0]);
  for(var i=0;i<c;i++){//初始化样式设置
   this.$$('p',pic[i])[0].style.top=-i*h+'px';
   pic[i].style.height=h+'px';
   this.$$('p',pic[i])[0].style.height=boxH*c+'px';
  }
  var index = 0;//开始显示的序号
  box.removeChild(this.$$('div',box)[0]);
  var run = function(idx) {
   var tt=par.type==4?Math.round(1+(Math.random()*(3-1))):par.type;//效果选择
   btn[index].className = '';
   txt[index].style.display='none';
            if(index==n-1) index=-1;
   var N=idx!=undefined?idx:index+1;
   var spd=tt==2?20:(tt==1?80:Math.round(20+(Math.random()*(80-20))));
   for(var i=0;i<c;i++){
    if(tt==3) spd=Math.round(20+(Math.random()*(80-20)));
    myFocus.move(myFocus.$$('p',pic[i])[0],'top',-N*c*h-i*h,'easeOut',spd);
    spd=tt==2?spd+10:(tt==1?spd-10:spd);
   }
   btn[N].className = 'current';
   txt[N].style.display='block';
            index = N;
        }
  run(index);
  var auto=setInterval(function(){run()},t);
  for (var j=0;j<n;j++){
   btn[j].j=j;
   btn[j].onclick=function(){if(!this.className) run(this.j)}
  }
  box.onmouseover=function(){clearInterval(auto);}
     box.onmouseout=function(){auto=setInterval(function(){run()},t);}
  for(var i=0,lk=this.$$('a',box),ln=lk.length;i<ln;i++) lk[i].onfocus=function(){this.blur();}//去除虚线框
 }
};
myFocus.setting({
 style:'mF_liuzg',//style为风格样式，
 id:'myFocus',//焦点图ID
 chip:8,//图片切片数量，能被焦点图的高整除才有效，默认为8片
 type:4,//切片效果，1为甩头，2为甩尾，3为凌乱，4为随机效果
 time:4//每帧图片时间间隔
});//更多样式设置留意myFocus正式版


var Tween = {
	Linear: function(t,b,c,d){ return c*t/d + b; },
	Quad: {
		easeIn: function(t,b,c,d){
			return c*(t/=d)*t + b;
		},
		easeOut: function(t,b,c,d){
			return -c *(t/=d)*(t-2) + b;
		},
		easeInOut: function(t,b,c,d){
			if ((t/=d/2) < 1) return c/2*t*t + b;
			return -c/2 * ((--t)*(t-2) - 1) + b;
		}
	},
	Cubic: {
		easeIn: function(t,b,c,d){
			return c*(t/=d)*t*t + b;
		},
		easeOut: function(t,b,c,d){
			return c*((t=t/d-1)*t*t + 1) + b;
		},
		easeInOut: function(t,b,c,d){
			if ((t/=d/2) < 1) return c/2*t*t*t + b;
			return c/2*((t-=2)*t*t + 2) + b;
		}
	},
	Quart: {
		easeIn: function(t,b,c,d){
			return c*(t/=d)*t*t*t + b;
		},
		easeOut: function(t,b,c,d){
			return -c * ((t=t/d-1)*t*t*t - 1) + b;
		},
		easeInOut: function(t,b,c,d){
			if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
			return -c/2 * ((t-=2)*t*t*t - 2) + b;
		}
	},
	Quint: {
		easeIn: function(t,b,c,d){
			return c*(t/=d)*t*t*t*t + b;
		},
		easeOut: function(t,b,c,d){
			return c*((t=t/d-1)*t*t*t*t + 1) + b;
		},
		easeInOut: function(t,b,c,d){
			if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
			return c/2*((t-=2)*t*t*t*t + 2) + b;
		}
	},
	Sine: {
		easeIn: function(t,b,c,d){
			return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
		},
		easeOut: function(t,b,c,d){
			return c * Math.sin(t/d * (Math.PI/2)) + b;
		},
		easeInOut: function(t,b,c,d){
			return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
		}
	},
	Expo: {
		easeIn: function(t,b,c,d){
			return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
		},
		easeOut: function(t,b,c,d){
			return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
		},
		easeInOut: function(t,b,c,d){
			if (t==0) return b;
			if (t==d) return b+c;
			if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
			return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
		}
	},
	Circ: {
		easeIn: function(t,b,c,d){
			return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
		},
		easeOut: function(t,b,c,d){
			return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
		},
		easeInOut: function(t,b,c,d){
			if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
			return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
		}
	},
	Elastic: {
		easeIn: function(t,b,c,d,a,p){
			if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
			if (!a || a < Math.abs(c)) { a=c; var s=p/4; }
			else var s = p/(2*Math.PI) * Math.asin (c/a);
			return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
		},
		easeOut: function(t,b,c,d,a,p){
			if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
			if (!a || a < Math.abs(c)) { a=c; var s=p/4; }
			else var s = p/(2*Math.PI) * Math.asin (c/a);
			return (a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b);
		},
		easeInOut: function(t,b,c,d,a,p){
			if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
			if (!a || a < Math.abs(c)) { a=c; var s=p/4; }
			else var s = p/(2*Math.PI) * Math.asin (c/a);
			if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
			return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
		}
	},
	Back: {
		easeIn: function(t,b,c,d,s){
			if (s == undefined) s = 1.70158;
			return c*(t/=d)*t*((s+1)*t - s) + b;
		},
		easeOut: function(t,b,c,d,s){
			if (s == undefined) s = 1.70158;
			return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
		},
		easeInOut: function(t,b,c,d,s){
			if (s == undefined) s = 1.70158; 
			if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
			return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
		}
	},
	Bounce: {
		easeIn: function(t,b,c,d){
			return c - Tween.Bounce.easeOut(d-t, 0, c, d) + b;
		},
		easeOut: function(t,b,c,d){
			if ((t/=d) < (1/2.75)) {
				return c*(7.5625*t*t) + b;
			} else if (t < (2/2.75)) {
				return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
			} else if (t < (2.5/2.75)) {
				return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
			} else {
				return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
			}
		},
		easeInOut: function(t,b,c,d){
			if (t < d/2) return Tween.Bounce.easeIn(t*2, 0, c, d) * .5 + b;
			else return Tween.Bounce.easeOut(t*2-d, 0, c, d) * .5 + c*.5 + b;
		}
	}
}






function init()
{
var slideArea = document.getElementById("slideArea");
var picList = slideArea.getElementsByTagName("li");
var btnFrame = document.getElementById("slideBtn");
var btnArr = [];
var b=0,c=0,d=60,t=0;
var currentIndex =0;
var moveEnd = true;
var index = 0;
var isOver=false;
for(var i =0; i<picList.length;i++)
{
	(btnArr[i]=btnFrame.appendChild(document.createElement("span")));//.innerHTML = i+1;
	btnArr[i].name = i;
	btnArr[i].onclick = function(){move(this.name)};
	btnArr[i].onmouseover = function(){isOver = true;};
	btnArr[i].onmouseout = function(){isOver = false;};
	if(btnArr.length == picList.length)
	{
	    btnArr[0].className = "current";
		slideArea.onmouseover = function(){isOver = true;};
		slideArea.onmouseout = function(){isOver = false;};
	}
}
function move(n)
{
	index = n;
	if(moveEnd)
	{
		for(var i=0; i<btnArr.length;i++)
	    {
		     btnArr[i].className = i==btnArr[n].name?"current":"";
	    }
	    if(currentIndex+1==n)
	    {
		     c = -254;
	    }
	    else if(currentIndex-1==n)
	    {
		     c = 254;
	    }
	    else
	    {
		     c = -254 * (n-currentIndex);
	    }
	    Run();
	    currentIndex = n;
	}
	
}
function Run(){
    slideArea.style.left = Math.ceil(Tween.Elastic.easeInOut(t,b,c,d)) + "px";
    if(t<d)
	{ 
	    t++; 
	    timer=setTimeout(Run, 50); 
		moveEnd = false;
	}
	else
	{
		//alert("运动完成");
		clearTimeout(timer);
		b+=c;
		t=0;
		moveEnd = true;
	}
}
function startTimer()
{
	if(!isOver)
	{
		move(index);
	    if(index<picList.length-1)
	    {
		    index++;
		
	    }
	    else
	    {
	        index = 0;
		
	    }
	}
	setTimer=setTimeout(startTimer,3000);
}
startTimer();	
}


/*News Tab*/

$(function(){
    function tabs(tabTit,on,tabCon){
	$(tabCon).each(function(){
	  $(this).children().eq(0).show();
	  });
	$(tabTit).each(function(){
	  $(this).children().eq(0).addClass(on);
	  });
     $(tabTit).children().hover(function(){
        $(this).addClass(on).siblings().removeClass(on);
         var index = $(tabTit).children().index(this);
         $(tabCon).children().eq(index).show().siblings().hide();
    });
     }
  tabs(".tab-hd","active",".tab-bd");
   });
