// JavaScript Document

// SLIDER CONFIG
		$(function(){
			$('#main-top-slider').slides({
				preload: true,
				preloadImage: 'img/loading.gif',
				play: 10000,
				pause: 2500,
				hoverPause: true,
				orientation:'vertical',
				animationStart: function(){
					$('.caption').animate({ bottom:0 },100);
				},
				animationComplete: function(current){
					$('.caption').animate({
						bottom:0
					},200);
					if (window.console && console.log) {
						// example return of current slide number
						console.log(current);
					};
				}
			});
		});
// ----------------------------------------------------------

function zxcAnimate(mde,obj,srt){
 this.to=null;
 this.obj=typeof(obj)=='object'?obj:document.getElementById(obj);
 this.mde=mde.replace(/\W/g,'');
 this.data=[srt||0];
 return this;
}
 
zxcAnimate.prototype.animate=function(srt,fin,ms,scale,c){
 clearTimeout(this.to);
 this.time=ms||this.time||0;
 this.neg=srt<0||fin<0;
 this.data=[srt,srt,fin];
 this.mS=this.time*(!scale?1:Math.abs((fin-srt)/(scale[1]-scale[0])));
 this.c=typeof(c)=='string'?c.charAt(0).toLowerCase():this.c?this.c:'';
 this.inc=Math.PI/(2*this.mS);
 this.srttime=new Date().getTime();
 this.cng();
}
 
zxcAnimate.prototype.cng=function(){
 var oop=this,ms=new Date().getTime()-this.srttime;
 this.data[0]=(this.c=='s')?(this.data[2]-this.data[1])*Math.sin(this.inc*ms)+this.data[1]:(this.c=='c')?this.data[2]-(this.data[2]-this.data[1])*Math.cos(this.inc*ms):(this.data[2]-this.data[1])/this.mS*ms+this.data[1];
 this.apply();
 if (ms<this.mS) this.to=setTimeout(function(){oop.cng()},10);
 else {
  this.data[0]=this.data[2];
  this.apply();
  if (this.Complete) this.Complete(this);
 }
}
 
zxcAnimate.prototype.apply=function(){
 if (isFinite(this.data[0])){
  if (this.data[0]<0&&!this.neg) this.data[0]=0;
  if (this.mde!='opacity') this.obj.style[this.mde]=Math.floor(this.data[0])+'px';
  else zxcOpacity(this.obj,this.data[0]);
 }
}
 
function zxcOpacity(obj,opc){
 if (opc<0||opc>100) return;
 obj.style.filter='alpha(opacity='+opc+')';
 obj.style.opacity=obj.style.MozOpacity=obj.style.KhtmlOpacity=opc/100-.001;
}

function zxcStepCarouselII(o){
 var mde=typeof(o.Mode)=='string'&&o.Mode.charAt(0)=='V'?['top','offsetHeight']:['left','offsetWidth'];
 var obj=document.getElementById(o.ID);
 if (obj&&typeof(o.Pitch)=='number'){
  var objs=this.cls(o.ClassName,obj);
  this.nu=typeof(o.Number)=='number'?o.Number:Math.floor(objs.length/2);
  this.oops=[];this.use=[];this.pos=[];
  for (var inc=o.Pitch,lft,oop,z0=0;z0<objs.length;z0++){
   lft=inc*z0;
   oop=new zxcAnimate(mde[0],objs[z0],lft);
   this.oops.push([oop,new zxcAnimate('opacity',objs[z0]),z0]);
   oop.min=-inc;
   oop.max=inc*this.nu;
   oop.Complete=function(){
    if (this.data[0]==this.min||this.data[0]==this.max){
     this.obj.style.visibility='hidden';
    }
   }
   objs[z0].style.position='absolute';
   objs[z0].style[mde[0]]=lft+'px';
   if (z0<this.nu){
    this.pos.push(lft);
    this.use[z0]=this.oops[z0];
   }
   else {
    objs[z0].style.visibility='hidden';
   }
  }
  this.wrap=typeof(o.WrapAround)!='boolean'?true:o.Wrap;
  this.fwd=0;
  this.ms=typeof(o.Duration)=='number'?o.Duration:1000;
  this.hold=typeof(o.Hold)=='number'?o.Hold:this.ms*4;
  this.pro=typeof(o.Progression)=='string'?o.Progression:'';
  this.to=null;
  this.pobj=obj.parentNode;
  this.master=typeof(o.MasterImage)=='number'&&this.use[o.MasterImage]?o.MasterImage:Math.floor(this.nu/2);
  this.pages=[];
  if (o.Paginate){
   this.Paginate(o.Paginate);
  }
  this.AddEvents(o.AddEvents);
  this.ud=typeof(o.AutoDirection)=='number'?o.AutoDirection:1;
  if (o.AutoStart){
   this.Auto();
  }
 }
}
 
zxcStepCarouselII.prototype={
 
 Back:function(){
  clearTimeout(this.to);
  this.fwd--;
  if (this.fwd<0){
   if (!this.wrap){
    return this.fwd=0;
   }
   this.fwd=this.oops.length-1;
  }
  var nu=this.fwd;
  this.oops[nu][0].data[0]=this.oops[nu][0].min;
  this.oops[nu][1].animate(100,100,this.ms,null,this.pro);
  this.use[this.nu-1][0].animate(this.use[this.nu-1][0].data[0],this.use[this.nu-1][0].max,this.ms,null,this.pro);
  this.use[this.nu-1][1].animate(100,100,this.ms,null,this.pro);
  var ary=[this.oops[nu]];
  for (var z0=0;z0<this.nu-1;z0++){
   ary.push(this.use[z0]);
  }
  this.use=ary;
  this.position();
 },
 
 Forward:function(){
  clearTimeout(this.to);
  this.fwd++;
  if (this.fwd==this.oops.length){
   if (!this.wrap){
    return this.fwd=this.oops.length-1;
   }
   this.fwd=this.fwd%this.oops.length
  }
  var nu=(this.fwd+this.nu-1)%this.oops.length;
  this.oops[nu][0].data[0]=this.oops[nu][0].max;

  // -> ALTERA A OPACIDADE DE FADE OUT <-
  this.oops[nu][1].animate(100,100,this.ms,null,this.pro);
  this.use[0][0].animate(this.use[0][0].data[0],this.use[0][0].min,this.ms,null,this.pro);
  // -> ALTERA A OPACIDADE DE FADE IN <-
  this.use[0][1].animate(100,100,this.ms,null,this.pro);
  
  var ary=[];
  for (var z0=1;z0<this.nu;z0++){
   ary.push(this.use[z0]);
  }
  ary.push(this.oops[nu]);
  this.use=ary;
  this.position();
 },
 
 GoTo:function(nu){
  var goto=this.use[this.master][2];
  for (var b=0,z0=goto+this.oops.length;z0>=0;z0--){
   b++;
   if (z0%this.oops.length==nu){
    break;
   }
  }
  for (var f=0,z1=goto;z1<goto+this.oops.length;z1++){
   f++;
   if (z1%this.oops.length==nu){
    break;
   }
  }
  if (goto!=nu){
   clearTimeout(this.to);
   var oop=this;
   oop[f<=b?'Forward':'Back']();
   this.to=setTimeout(function(){ oop.GoTo(nu); },this.ms);
  }
 },
 
 Auto:function(ud){
  var e=window.event?window.event:arguments.callee?arguments.callee.caller.arguments[0]:false;
  if (this.ckevt(e)){
   clearTimeout(this.to);
   if (typeof(ud)=='number'&&ud!=0){
    this.ud=ud;
   }
   this[this.ud>0?'Forward':'Back']();
   var oop=this;
   this.to=setTimeout(function(){ oop.Auto(); },this.hold+this.ms)
  }
 },
 
 Pause:function(ud){
  var e=window.event?window.event:arguments.callee?arguments.callee.caller.arguments[0]:false;
  if (this.ckevt(e)){
   clearTimeout(this.to);
  }
 },
 
 ckevt:function(e){
  if (e){
   var obj=e.relatedTarget||e[(e.type=='mouseover'?'from':'to')+'Element'];
   if (obj){
    while (obj.parentNode){
     if (obj==this.pobj){
      return false;
     }
     obj=obj.parentNode;
    }
   }
  }
  return true;
 },
 
 position:function(){
  if (this.page){
   this.page(this.use[this.master][2]);
  }
  for (var z1=0;z1<this.use.length;z1++){
   this.use[z1][0].obj.style.visibility='visible';
   this.use[z1][0].animate(this.use[z1][0].data[0],this.pos[z1],this.ms,null,this.pro);
  }
 },
 
 addevt:function(o,t,f,p){
  var oop=this;
  if (o.addEventListener) o.addEventListener(t,function(e){ return oop[f](p,e);}, false);
  else if (o.attachEvent) o.attachEvent('on'+t,function(e){ return oop[f](p,e); });
 },
 
 cls:function(nme,el){
  var reg=new RegExp('\\b'+nme+'\\b'),els=el.getElementsByTagName('*'),ary=[]
  for (var reg=new RegExp('\\b'+nme+'\\b'),els=el.getElementsByTagName('*'),ary=[],z0=0; z0<els.length;z0++){
   if(reg.test(els[z0].className)) ary.push(els[z0]);
  }
  return ary;
 },
 
// Optional Add Events Code
 AddEvents:function(ary){
  ary=typeof(ary)=='object'&&ary.constructor==Array?ary:[];
  for (var but,type,z1=0;z1<ary.length;z1++){
   var but=document.getElementById(ary[z1][0]),type=this.evttype(ary[z1][2]);
   if (but&&this[ary[z1][1]]&&type){
    this.addevt(but,type,ary[z1][1],ary[z1][3]);
   }
  }
 },
 
 evttype:function(et){
  type=(typeof(et)=='string'?et:'').toLowerCase().replace('on','');
  return type=='click'||type=='mousedown'||type=='mouseup'||type=='mouseover'||type=='mouseout'||type=='static'?type:false;
 },
 
 page:function(nu){
  var active=this.use[this.master][2];
  if (this.pages[nu]){
   this.pages[this.lstpage][0].className=this.pages[this.lstpage][1];
   this.pages[nu][0].className=this.pages[this.lstpage][3];
   this.lstpage=nu;
  }
 },
 
 mse:function(nu,e){
  if (this.pages[nu][0].className!=this.pages[nu][3]){
   this.pages[nu][0].className=e.type=='mouseout'?this.pages[nu][1]:this.pages[nu][2];
  }
 }
 
 
}

// ----- SLIDER PROGRAMAS CONFIIG ---

function Init(){
new zxcStepCarouselII({
 ID:'tstV',
 ClassName:'img',
 Pitch:79,
 Mode:'Vertical',
 Number:3,
 Duration:1220,
 Hold:15000,
 AutoDirection:0,
 AutoStart:true,

 AddEvents:[
	//['tstV','Auto','mouseout'],
	['tstV','Pause','mouseover'],
	['F','Forward','click'],
	['B','Back','click']
 ]
 
});
}
 
if (window.addEventListener){
 window.addEventListener('load',Init, false);
}
else if (window.attachEvent){
 window.attachEvent('onload',Init);
}


