/****
*
*	Criado por Filipe Alves Santana - aliados_flp2@hotmail.com
*	Copyright 2008 jBr, Todos os Direitos Reservados
*
*	© jBr - Todos os Diritos Reservados
*
****/

function $(id,loc){
	if(!loc)loc = window;
	if(typeof id=='string')return loc.document.getElementById(id);
	return id;
}

$.E = [];

$.isIE = (/msie/i.test(navigator.userAgent)&&document.all);

$.isFunction = function(o){
	return typeof o=='function'&&(!Function.prototype.call||typeof o.call=='function');
}

$.extend = function(){
	var alvo=this, t=alvo, fonte, p, i=0;
	if(arguments.length>1){
		i++;
		alvo = t = arguments[0];
	}
	for(; fonte=arguments[i]; i++){
		for(var pp in fonte){
			p = fonte[pp];
			if(pp.charAt(0)!='@'){
				if(p&&p.splice){
					var tp = t[pp];
					t[pp] = tp&&tp.splice?tp.concat(p):[].concat(p);
				}else if(p&&(typeof p=='object')){
					t[pp] = $.extend(t[pp]||{},p);
				}else t[pp] = p;
				continue;
			}
			if(pp=='@init')p.call(t);
		}
	}
	return alvo;
}

// *********************** //

$.gWidth = function(l){
	if(!l)l = window;
	return l.innerWidth?l.innerWidth:
	l.document.documentElement?l.document.documentElement.clientWidth:
	l.document.body?l.document.body.clientWidth:l.screen.width;
}

$.gHeight = function(l){
	if(!l)l = window;
	return l.innerHeight?l.innerHeight:
	l.document.documentElement?l.document.documentElement.clientHeight:
	l.document.body?l.document.body.clientHeight:
	l.screen.height;
 }

// *********************** //
//Math
$.extend(Number.prototype,{
round:function(){return Math.round(this);},
floor:function(){return Math.floor(this);},
ceil:function(){return Math.ceil(this);},
pow:function(ex){return Math.pow(this,ex);},
sqrt:function(){return Math.sqrt(this);}
});
//String
$.extend(String.prototype,{
trim:function(){return this.replace(/^\s*|\s*$/g,'');},
reverse:function(){return this.split('').reverse().join('');}
});
// *********************** //
// *********************** //
// *********************** //
$.opacity = function(o,v){
	v = Math.round(v);
	o.style.opacity = v/100;
	o.style.filter = 'alpha(opacity='+v+')';
	o.style.display = (v>0)?'':'none';
}

// *********************** //
$.speed = function(f,t){
	var tm = 28;
	var it = f/(t/($.isIE?31:28));
	return{t:tm,i:it};
}

$.animar = {a:0,tm:1000,min:0,max:100,id:null,e:{},
on:function(e){
	if(!$.isFunction(this.e[e]))return this;
	var ag = [];
	for(var i=1; i<arguments.length; i++)ag[i-1] = arguments[i];
	this.e[e].apply(this,ag);
	return this;
},
calc:function(t,i,f,a){
	if(t!=null)this.tm = t;
	if(i!=null)this.min = i;
	if(f!=null)this.max = f;
	if(a!=null)this.a = a;
	var sp = $.speed(this.max-this.min,this.tm);
	this.t = sp.t;
	this.i = sp.i;
	return this;
},
set:function(v){
	if(v!=null&&v!=this.a){
		this.a = v;
		if(v<this.min)this.min = v;
		if(v>this.max)this.max = v;
	}
	return this.on('set').on('onset');
},
stop:function(){
	clearTimeout(this.id);
	this.id = null;
	return this.on('stop');
},
go:function(){
	var t = this;
	var f = function(){
		if(t.a<=t.min){
			t.set(t.min);
			t.on('ini');
		}else if(t.a<t.max){
			t.set();
			t.on('run');
		}else if(t.a>=t.max){
			t.set(t.max);
			t.stop();
			t.on('fim');
			return;
		}
		t.a += t.i;
		t.id = setTimeout(f,t.t);
	}
	if(t.id){
		if(t.tip)return;
		t.stop();
	}
	t.tip = 1;
	t.on('go');
	f();
	return this;
},
back:function(){
	var t = this;
	var f = function(lt){
		var ct = (new Date()).getTime();
		if(t.a>=t.max){
			t.set(t.max);
			t.on('ini');
		}else if(t.a>t.min){
			t.set();
			t.on('run');
		}else if(t.a<=t.min){
			t.set(t.min);
			t.stop();
			t.on('fim');
			return;
		}
		t.a -= t.i;
		t.id = setTimeout(f,t.t);
	}
	if(t.id){
		if(!t.tip)return;
		t.stop();
	}
	t.tip = 0;
	t.on('back');
	f();
	return this;
}};
// *********************** //



// *********************** //
$.fade = function(o,el){
	$.extend(this,$.animar,{In:function(){return this.go();},Out:function(){return this.back();},e:{set:function(){$.opacity(this.o,this.a);}}},o);
	this.o = el;
	this.calc();
}
// *********************** //
$.aniSt = function(o,el){
	$.extend(this,$.animar,{st:'width',ep:'[a]px',e:{set:function(){this.o.style[this.st] = this.ep.replace(/(\[a\])/,this.a);}}},o);
	this.o = el;
	this.calc();
}
// *********************** //
var $flash = {i:0,i2:1,s:1,id:null,
ini:function(o){
	var _this = this;
	this.a = $(o);
	this.b = this.a.childNodes[1];
	this.a = this.a.childNodes[0];
	this.f = new $.fade({a:100,tm:this.tmf,e:{fim:function(){_this.troca();}}},this.b);
	return this.troca(true);
},
troca:function(n){
	if(this.tp&&!n){
		this.i = this.i2;
		this.i2++;
		if(this.i2>=this.dd.length)this.i2 = 0;
	}else if(!this.tp&&!n){
		this.i2 = this.i;
		this.i--;
		if(this.i<0)this.i = this.dd.length-1;
	}
	this.b.src = this.dd[this.i][0];
	this.f.set(100);
	this.a.style.backgroundImage = 'url('+this.dd[this.i2][0]+')';
	return this.play(true);
},
play:function(n){
	if(!n)this.s = 1;
	this.tp = true;
	var _this = this;
	if(!this.id&&this.s==1)this.id = setTimeout(function(){_this.px();},this.tm);
	return this;
},
stop:function(n){
	if(!n)this.s = 0;
	clearTimeout(this.id);
	this.id = null;
	return this;
},
px:function(){
	this.stop(true).f.Out();
	return this;
},
at:function(){
	var a = this.i-1;
	if(a<0)a = this.dd.length-1;
	this.a.style.backgroundImage = 'url('+this.dd[a][0]+')';
	this.tp = false;
	this.stop(true).f.Out();
	return this;
}};
// *********************** //
var $flash = {i:0,i2:1,s:1,id:null,
ini:function(o){
	var _this = this;
	this.a = $(o);
	this.b = this.a.childNodes[0];
	this.f = new $.fade({a:100,tm:this.tmf,e:{fim:function(){_this.troca();}}},this.b);
	return this.troca(true);
},
troca:function(n){
	if(this.tp&&!n){
		this.i = this.i2;
		this.i2++;
		if(this.i2>=this.dd.length)this.i2 = 0;
	}else if(!this.tp&&!n){
		this.i2 = this.i;
		this.i--;
		if(this.i<0)this.i = this.dd.length-1;
	}
	this.b.src = this.dd[this.i][0];
	this.f.set(100);
	this.a.style.backgroundImage = 'url('+this.dd[this.i2][0]+')';
	return this.play(true);
},
play:function(n){
	if(!n)this.s = 1;
	this.tp = true;
	var _this = this;
	if(!this.id&&this.s==1)this.id = setTimeout(function(){_this.px();},this.tm);
	return this;
},
stop:function(n){
	if(!n)this.s = 0;
	clearTimeout(this.id);
	this.id = null;
	return this;
},
px:function(){
	this.stop(true).f.Out();
	return this;
},
at:function(){
	var a = this.i-1;
	if(a<0)a = this.dd.length-1;
	this.a.style.backgroundImage = 'url('+this.dd[a][0]+')';
	this.tp = false;
	this.stop(true).f.Out();
	return this;
}};
// *********************** //
function mnvMouse(o,t,nmn){
	var p = o.parentNode;
	if(!nmn){
		var a = o.childNodes[0];
		var ul = o.childNodes[1];
	}
	var n = p.getAttribute('mnn');
	if(!n){
		n = mnvMouse.n.length;
		mnvMouse.n[n] = {};
		p.setAttribute('mnn',''+n);
	}else n = parseInt(n,10);
	var nv = mnvMouse.n[n];
	if(t==1){
		clearTimeout(nv.i);
		if(o==nv.o)return;
		if(nv.f)nv.f();
		if(nmn)return;
		o.className = 'liover';
		a.className = 'submn hover';
		ul.className = 'over';
	}
	if(t==2){
		nv.o = o;
		nv.f = function(){
			o.className = '';
			a.className = 'submn';
			ul.className = 'out';
			nv.o = null;
			nv.f = null;
			nv.i = null;
		}
		nv.i = setTimeout(function(){nv.f();},1000);
	}
}
mnvMouse.n = [];

// *********************** //
// *********************** //
// *********************** //

