﻿/*
*
*	© Framework jSun
*	Criado por Breno Lima de Freitas
*	v 1.31 (15:55 24/08/2010)
*
*/

window.js=function(id){
	if(typeof id=='string')return document.getElementById(id);
	else if(typeof id=='object') return id;
	return null;
}

js.removeChildren=function(o){
	if(!o||!o.childNodes.length)return false;
	o=js(o);
	for(var i=o.childNodes.length;i>=0;i--)if(o.childNodes[i]&&o.childNodes[i].nodeType==1)o.removeChild(o.childNodes[i]);
}

js.main=function(){
	js.create.apply();
	js.elements.apply();
	js.imgDec.apply();
	if(js.navInfo()[0]=='ie'&&js.navInfo()[1]<=6)js.fixImg();
}

js.elements={
	apply:function(){
		this.datetime();
		this.href();
		this.cl(null,null,document.body);
	},
	inpk:0,
	datetime:function(m){
		var input=document.getElementsByTagName('input');
		if(input.length<=0)return;
		for(var j=0;j<input.length;j++){
			var t=get(input[j],'type');
			if(t=='time'){
				if(has(input[j],'sec')){
					this.inpk=1;
					input[j].value=js.date('hh:mm:ss');
				}else if(!m)input[j].value=js.date('t');
			}else if(t=='date'&&!m){
				input[j].value=js.date('s');
				input[j].onfocus=function(){this.select();}
				input[j].onkeydown=function(){return js.mask.dt(event,this,1);}
				input[j].onblur=function(){if(this.value=='')this.value=js.date('s');}
			}
		}
		if(this.inpk==1)setInterval(function(){js.elements(1);},1000);
	},
	href:function(){
		var b=document.body.getElementsByTagName('*');
		var base=document.getElementsByTagName('base')[0];
		for(var i=0;i<b.length;i++){
			var h=get(b[i],'href');
			if(h){
				if(h.indexOf('www')!=-1)set(b[i],'href','http://'+h);
				if(b[i].tagName!='A')b[i].onclick=function(){(base.target?base.target:window).location=get(this,'href');}
				b[i].style.cursor='pointer';
			}
		}
	},
	cl:function(o,s,obj){
		if(o&&s){
			var t=o.slice?'o':'s';
			o=js(o);
			var l;
			if(t=='s'){
				l=o.className;
				o.onmouseout=function(){this.className=l}
				return js(o).className=s;
			}else if(t=='o'){
				for(var i=0;i<o.length;i++){
					l=o[i].className;
					o[i].onmouseout=function(){this.className=l}
					js(o[i]).className=s[i]+'';
				}
			}
		}else{
			var b=obj.getElementsByTagName('*');
			for(var i=0;e=b[i];i++){
				if(has(e,'jscl')){
					var ctt=get(e,'jscl');
					ctt=ctt.split(' ');
					
					for(var j=0;j<ctt.length;j++)if(ctt[j]&&ctt[j].charAt(0)=='$')ctt[j]=ctt[ctt[j].num()-1]?ctt[ctt[j].num()-1]:a;
					
					var classe=ctt[0]?ctt[0]:e.className?e.className:'';
					var over=ctt[1]?ctt[1]:classe;
					var out=ctt[2]?ctt[2]:classe;
					var clic=ctt[3]?ctt[3]:classe;
					
					e.className=classe;
					
					set(e,'out',out);
					set(e,'over',over);
					set(e,'clic',clic);
					
					set(e,'onclick',js.fctt(e.onclick)+'this.className=this.getAttribute("clic");');
					set(e,'onmouseout',js.fctt(e.onmouseout)+'this.className=this.getAttribute("out");');
					set(e,'onmouseover',js.fctt(e.onmouseover)+'this.className=this.getAttribute("over");');
				}
			}
		}
	}
}

js.extend = function(){
	var t=this, i=0, f, k, v;
	if(arguments.length>1){
		i++;
		t=arguments[0];
	}
	for(var i; f=arguments[i];i++){
		for(var k in f){
			v=f[k];
			if(v&&v.slice)t[k]=t[k]&&t[k].slice?t[k].concat(v):[].concat(v);
			else if(v&&typeof v=='object')t[k]=js.extend(t[k]||{},v);
			else t[k]=v;
		}
	}
}

js.extend(String.prototype,{
			str:function(){
				return this.replace(/\d/g,'');
			},
			num:function(){
				var r=parseFloat(this.replace(/\D/g,''));
				return isNaN(r)?0:r;
			},
			up:function(){return this.toUpperCase;},
			low:function(){return this.toLowerCase;},
			indexOfAt:function(str,pos){
				if(pos<=0)pos=1;
				var r=0;
				for(var i=0;i<this.length;i++){
					if(this.charAt(i)==str)r++;
					if(r==pos)return i;
				}return -1;
			},
			int:function(){
				return parseInt(this);
			},
			float:function(){
				return parseFloat(this);
			},
			trim:function(){
				return this.replace(/(\s*)(\w*)(\s*)/g,'$2');
			},
			count:function(str){
				for(var r=i=0;i<this.length;i++)if(this.charAt(i)==str)r++;
				return r;
			},
			low:function(){
				return this.toLowerCase();
			},
			up:function(){
				return this.toUpperCase();
			},
			mirror:function(){
				for(i=this.length,aux='';i>=0;i--)aux+=this.charAt(i);
				return aux;
			},
			img:function(){
				return /\.(jpe?g|bmp|png|gif)$/.test(this.toLowerCase())?true:false;
			},
			email:function(){
				return /^[-_a-z0-9]+(\.[-_a-z0-9]+)*@([-a-z0-9]+\.)*([a-z]{2,4})$/.test(this)?true:false;
			}
		  });

js.extend(Number.prototype,{
		  abs:function(){return Math.abs(this);},
		  ceil:function(){return Math.ceil(this);},
		  floor:function(){return Math.floor(this);},
		  round:function(){return Math.round(this);},
		  pow:function(n){return Math.pow(this,n);},
		  isValid:function(){
		 	if((this>=96&&this<=105)||(this>=48&&this<=57)||this==8||this==9||this==13)return true;
			return false;
			}
		  });

function has(o,str){
	try{
		return (js.navInfo()[0]!='ie'?(o.hasAttribute(str)?true:false):o.getAttribute(str)!=null&&(o.getAttribute(str)==''||o.getAttribute(str)!='')?true:false);
	}catch(e){return false;}
}

function set(o,c,str){
	return o.setAttribute(c,str);
}

function get(o,str){
	return has(o,str)?o.getAttribute(str):'';
}

js.conv={
	toHex:function(r,g,b){
		var c=[parseInt(r),parseInt(g),parseInt(b)];
		var ret='';
		var aux=[0,0];
		var h='0123456789abcdef';
		for(var i=0;i<c.length;i++){
			do{	aux[0]=c[i]%16;
				aux[1]=(c[i]/16).floor();
				c[i]=(c[i]/16).floor();
			}while((c[i]/16)>=16)
			ret+=(h.charAt(aux[1])+h.charAt(aux[0]));
		}
		return ret;
	},
	fromHex:function(h){
		if(h.charAt(0)=='#')h=h.substr(1);
		var hex='0123456789abcdef';
		for(var i=r=g=0;i<h.length;i++){
			for(var j=0;j<hex.length;j++)if(h.charAt(i)==hex.charAt(j))g=j;
			r+=g*(16).pow(i);
		}
		return r;
	}
}

js.exist=function(id){
	var d=document.getElementsByTagName('*');
	var r=[false,''];
	for(var i=0;i<d.length;i++){
		if(get(d[i],'title')==id){r[0]=true;r[1]='t';break;}
		else if(get(d[i],'id')==id){r[0]=true;r[1]='i';break;}
		else if(get(d[i],'name')==id){r[0]=true;r[1]='n';break;}
	}
	return r;
}

js.fctt=function(f){
	if(!f)return '';
	var r=(f+'').substring((f+'').indexOf('{')+2,(f+'').lastIndexOf('}'));
	if(typeof f=='object'){
		r='';
		for(var i=0;t=f[i];i++){
			if(!t)t='';
			r+=(t+'').substring((t+'').indexOf('{')+1,(t+'').lastIndexOf('}'));
		}
	}
	return r;
}

js.navInfo=function(){
	var ret=['nt','',''];
	var a=navigator.appVersion;
	if(document.all)ret[0]='ie';
	else{
		var u=(navigator.userAgent).low();
		var nvs=['firefox','chrome','opera','safari'],cif=['ff','ch','op','sf'];
		for(var i=0;nvsn=nvs[i];i++)if(u.indexOf(nvsn)!=-1){ret[0]=cif[i];break;}
	}
	if(ret[0]=='ie')ret[1]=(a.substring(a.indexOfAt(';',1)+7,a.indexOfAt(';',2)));
	else ret[1]=(a.substr(0,a.indexOf('(')-1));
	ret[2]=(navigator.userLanguage?navigator.userLanguage:navigator.language).substr(0,2);
	return ret;
}

js.out=function(str,o,m){
	o?o=js(o):o=document.body;
	if(o!=document.body)m=0;
	switch(m){
		case 0:return o.innerHTML+=str;break;
		case 1:return alert(str);break;
		default:return document.write(str);break;
	}
}

js.date=function(f,a,m,d){
	if(!f&&!a)return false;
	if(!(f=='f'||f=='l'||f=='s'||f=='t'||f=='p'||f=='bsx')&&(f.replace(/^[YyMmDdAaHhsuiqw<>?!\(\)\{\}\[\]\/,\.:;%\s]+$/g,'')!=''))return false;
	if(f!='l'&&f!='s'){
		if(f=='t')f='h:m';
		f=f.replace(/(y)+/g,'y');
		f=f.replace(/(Y)+/g,'Y');
		f=f.replace(/(M)+/g,'M');
		f=f.replace(/(D)+/g,'D');
		f=f.replace(/(d)+/g,'d');
		f=f.replace(/(h)+/g,'h');
		f=f.replace(/(H)+/g,'H');
		f=f.replace(/(i)+/g,'i');
		f=f.replace(/(s)+/g,'s');
		f=f.replace(/(u)+/g,'u');
		f=f.replace(/(A)+/g,'A');
		f=f.replace(/(a)+/g,'a');
		f=f.replace(/(p)+/g,'p');
		f=f.replace(/(m)+/g,'m');
		f=f.replace(/(q)+/g,'q');
		f=f.replace(/(w)+/g,'w');
	}
	var d = (a&&m&&d)?new Date(a,m-1,d):new Date();
	var c = [d.getDay(),d.getDate(),d.getMonth(),d.getFullYear(),d.getHours(),d.getMinutes(),d.getSeconds(),d.getMilliseconds()];
	var dias = ['Domingo','Segunda-Feira','Terça-Feira','Quarta-Feira','Quinta-Feira','Sexta-Feira','Sábado'];
	var meses = ['Janeiro','Fevereiro','Março','Abril','Maio','Junho','Julho','Agosto','Setembro','Outubro','Novembro','Dezembro'];
	
	if(f=='w')return c[0];
	
	var bsx=c[3]%100==0&&c[3]%400!=0?false:c[3]%4==0&&c[3]%100!=0?true:c[3]%400==0?true:false;
	if(f=='bsx')return bsx;
	
	var tot_dias=(c[2]==1?(bsx?29:28):(c[2]<=6?(c[2]%2!=0?30:31):(c[2]%2==0?30:31)));
    if(f=='q')return tot_dias;
	
	var p='';
	if(c[4]<12)p='m';
	else if(c[4]>=12&&c[4]<18)p='t';
	else p='n';
	var r=[(dias[c[0]]+', '+c[1]+' de '+meses[c[2]]+' de '+c[3]),(c[1]+' de '+meses[c[2]]+' de '+c[3])];
	if(f=='f')return r[0];
	else if(f=='l')return r[1];
	else if(f=='s')return c[1]+'/'+(c[2]+1<10?'0'+(c[2]+1):(c[2]+1))+'/'+c[3];
	c[2]++;
	c[3]+='';
	var cmp='';
	if(f.count('A')>0)cmp=c[4]>12?'PM':'AM';
	else if(f.count('a')>0&&cmp=='')cmp=c[4]>12?'pm':'am';
	f=f.replace(/(d)/g,c[1]<10?'0'+c[1]:c[1]);
	f=f.replace(/(M)/g,c[2]<10?'0'+c[2]:c[2]);
	f=f.replace(/(y)/g,c[3]);
	f=f.replace(/(Y)/g,c[3].substr(2));
	f=f.replace(/(h)/g,c[4]<10?'0'+c[4]:c[4]);
	f=f.replace(/[HAa]/g,c[4]<12?c[4]:c[4]-12);
	f=f.replace(/(i)/g,c[5]<10?'0'+c[5]:c[5]);
	f=f.replace(/(s)/g,c[6]<10?'0'+c[6]:c[6]);
	f=f.replace(/(u)/g,c[7]);
	f=f.replace(/(p)/g,p);
	f=f.replace(/(D)/g,dias[c[0]]);
	f=f.replace(/(m)/g,meses[(c[2]-1)]);
	
	if(cmp!='')f+=(' '+cmp);
	return f;
}

js.fixImg=function(){
	var s;
	var a = ['id','alt','onmouseover','onmouseout','onmouseup','onmousemove','onmousedown','onclick','ondblclick','onkeypress','onkeyup','onkeydown','title','class','onload'];
	for(var i=0,img;img=document.images[i]; i++){
		s=document.createElement('span');
		for(var j=0,v; v=a[j]; j++){
			s[v]=img[v];
		}
		s.style.cssText=img.style.cssText;
		s.style.width=img.width;
		s.style.height=img.height;
		s.style.display='inline-block';
		s.style.filter='progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'+img.src+'", sizingMethod="scale")';
		img.parentNode.replaceChild(s,img);
	}
}

var disOb=new Array();
js.dis=function(o,m,t,display){
	if(!o)return -1;
	o=js(o);
	if(!o.id&&isNaN(arguments[1]))return -1;
	if(!o.style.opacity||o.style.opacity==''){
		o.style.opacity=(o.style.display=='none'?0:1);
		o.style.filter=(o.style.display=='none'?'alpha(opacity=0)':'alpha(opacity=100)');
		if(o.style.opacity==0)o.style.display=display?display:'inline-block';
	}
	var id=o.id;
	for(var i=0,k=-1;i<disOb.length;i++)if(disOb[i]['id']==id)k=i;
	
	if(k==-1){
		k=disOb.length;
		disOb[disOb.length++]={id:id,opa:parseInt(o.style.opacity)};
	}
	
	t=t?t:22;
	//var relation=(t/550)*2;
	
	if(m==null){
		if(disOb[k].opa>=1)m=0;
		else m=1;
	}
	disOb[k].opa+=(m==1?0.2:-0.2);
	o.style.opacity=disOb[k].opa;
	o.style.filter='alpha(opacity='+(disOb[k].opa*100)+')';
	if(m==0&&disOb[k].opa<=0){
		o.style.opacity='';
		o.style.display='none';
		disOb[k].opa=0;
		return 0;
	}else if(m==1&&disOb[k].opa>=1)return 0;
	else setTimeout(function(){js.dis(o,m,t,display);},t);
	return 1;
}

js.imgMiddle=function(o,url){
	try{
		o=js(o);
		var img_aux=document.createElement('img');
		var at = [o.style.width.num(),o.style.height.num()];
		if(isNaN(at[0])){at[0]=300;o.style.width='300px';}
		if(isNaN(at[1])){at[1]=300;o.style.height='300px';}
	}catch(e){return false;}
	function loop(c){
		at[c]-=(c==0?(at[c]-img_aux.width):(at[c]-img_aux.height));
		at[c]-=30;
		for(var i=0;i<at[c];i++){
			if(at[c]%10==0)return at[c];
			at[c]--;
		}
	}
	if(typeof url=='object'){
		if(url[1]=='0'){
			if(o.style.background.charAt(0)!='#')url[0]=(o.style.background).substring((o.style.background).indexOf('(')+1,(o.style.background).lastIndexOf(')'));
			if(url[0]!=''){
				img_aux.src=url[0];
				if(at[0]>img.width)o.style.width=loop(0)+'px';
				if(at[1]>img.height)o.style.height=loop(1)+'px';
				o.style.backgroundPosition=((img_aux.width-at[0])/2)*-1+'px '+
				((img_aux.height-at[1])/2)*-1+'px';
			}
			return;
		}
	}else{
		if(o.style.background.charAt(0)=='#')return;
		img_aux.src=(url+'');
		if(at[0]>img_aux.width)o.style.width=loop(0)+'px';
		if(at[1]>img_aux.height)o.style.height=loop(1)+'px';
		o.style.backgroundPosition=((img_aux.width-at[0])/2)*-1+'px '+
		((img_aux.height-at[1])/2)*-1+'px';
		return;
	}
}

var slideVar=new Array();
var slideVarI=0;
js.imgSlide=function(o,m){
	if(!o||!o.id||!o.style.background)return;
	o = js(o);
	
	var key=[0,0];
	for(var i=0;i<slideVar.length;i++){
		if(slideVar[i]['id']==o.id){
			key[0]=1;
			key[1]=i;
		}
	}
	
	var url=['',''];
	if(key[0]==1)url=[(slideVar[key[1]]['url'][0]),(slideVar[key[1]]['url'][1])];
	else url=['','0'];
	
	if(!o.style.width)o.style.width='300px';
	if(!o.style.height)o.style.height='300px';
	if(!o.style.backgroundPosition||o.style.backgroundPosition.split('px').length==1)o.style.backgroundPosition='0px 0px';
	o.style.cursor='crosshair';
		
	js.imgMiddle(o,url);
	
	var aux=[o.style.width.num(),o.style.height.num(),o.style.backgroundPosition.split('px'),o.id];
	
	if(key[0]==0){
			slideVar[slideVarI++]={id:aux[3],
			p:[(aux[2][0].trim().float()),(aux[2][1].trim().float())],
			mp:[(aux[2][0].trim().float()).abs()*2,(aux[2][1].trim().float()).abs()*2],
			r:[(aux[2][0].trim().float()).abs()/(aux[0]/2).ceil()*2,(aux[2][1].trim().float()).abs()/(aux[1]/2).ceil()],
			time:null,
			last:[0,0],
			url:['','1']};}
	
	o.onmousemove=function(){js.imgSlide(o);}
	o.onmouseup=function(){clearTimeout(slideVar[key[1]]['time']);o.onmousemove=null;}
	o.onmouseout=function(){clearTimeout(slideVar[key[1]]['time']);o.onmousemove=null;}

	if(!m)var m = [event.offsetX,event.offsetY,aux[0]/2,aux[1]/2];
	
	if(m[0]>m[2]&&slideVar[key[1]]['last'][0]<=m[0]){//direita
		if((slideVar[key[1]]['p'][0]-slideVar[key[1]]['r'][0])<=(slideVar[key[1]]['mp'][0]*-1))return;
		else{
			slideVar[key[1]]['p'][0]-=slideVar[key[1]]['r'][0];
			o.style.backgroundPosition=slideVar[key[1]]['p'][0]+'px '+slideVar[key[1]]['p'][1]+'px';
			clearTimeout(slideVar[key[1]]['time']);
			slideVar[key[1]]['time']=setTimeout(function(){js.imgSlide(o,m);},33);
		}
	}
	
	else if(m[0]<m[2]&&slideVar[key[1]]['last'][0]<=m[0]){//esquerda
		if((slideVar[key[1]]['p'][0]+slideVar[key[1]]['r'][0])>=0)return;
		else{
			slideVar[key[1]]['p'][0]+=slideVar[key[1]]['r'][0];
			o.style.backgroundPosition=slideVar[key[1]]['p'][0]+'px '+slideVar[key[1]]['p'][1]+'px';
			clearTimeout(slideVar[key[1]]['time']);
			slideVar[key[1]]['time']=setTimeout(function(){js.imgSlide(o,m);},33);
		}
	}
	
	if(m[1]>m[3]&&slideVar[key[1]]['last'][1]<=m[1]){//baixo
		if((slideVar[key[1]]['p'][1]-slideVar[key[1]]['r'][1])<=(slideVar[key[1]]['mp'][1]*-1))return;
		else{
			slideVar[key[1]]['p'][1]-=slideVar[key[1]]['r'][1];
			o.style.backgroundPosition=slideVar[key[1]]['p'][0]+'px '+slideVar[key[1]]['p'][1]+'px';
			clearTimeout(slideVar[key[1]]['time']);
			slideVar[key[1]]['time']=setTimeout(function(){js.imgSlide(o,m);},33);
		}
	}
	
	else if(m[1]<m[3]&&slideVar[key[1]]['last'][1]>=m[1]){//cima
		if((slideVar[key[1]]['p'][1]+slideVar[key[1]]['r'][1])>=0)return;
		else{
			slideVar[key[1]]['p'][1]+=slideVar[key[1]]['r'][1];
			o.style.backgroundPosition=slideVar[key[1]]['p'][0]+'px '+slideVar[key[1]]['p'][1]+'px';
			clearTimeout(slideVar[key[1]]['time']);
			slideVar[key[1]]['time']=setTimeout(function(){js.imgSlide(o,m);},33);
		}
	}
	
	slideVar[key[1]]['last'][0]=m[0];
	slideVar[key[1]]['last'][1]=m[1];
}

js.mask={
	tel:function(k,obj){
		len=js(obj).value.length;
		if(js(obj).maxlength=!14)js(obj).maxlength=14;
		k=k.keyCode;
		if(k.isValid()){
			if(len==0)obj.value='(';
			else if(len==1&&obj.value.charAt('0')!='(')obj.value='('+obj.value;
			else if(len==3&&k!=8)obj.value+=') ';
			else if(len==9&&k!=8)obj.value+='-';
		}else return false;
	},
	rg:function(k,obj){
		var len=js(obj).value.length;
		k=k.keyCode;
		js(obj).maxlength='12';
		if(k.isValid()){
			if((len==2||len==6)&&k!=8)obj.value+='.';
			else if(len==10&&k!=8)obj.value+='-';
		}else return false;
	},
	cpf:{
		v:function(){},
		m:function(k,obj){
			var len = js(obj).value.length;
			js(obj).maxlength='14';
			k=k.keyCode;
			if(k.isValid()){
				if((len==3||len==7)&&k!=8)obj.value+='.';
				else if(len==11&&k!=8)obj.value+='-';
			}else return false;
		}
	},
	dt:function(k,obj,y){
		var len = js(obj).value.length;
		k=k.keyCode;
		y=y?y:0;
		y==1?y=10:y=5;
		js(obj).maxlength=y+'';
		if(k.isValid()){
			if(k==8||k==9||k.isValid()){
				if((len==2||(len==5&&y==10))&&k!=8)obj.value+='/';
			}else return false;
		}else return false;
	},
	cnpj:function(){
	},
	cep:function(){
	},
	money:function(obj){
		obj=js(obj);
		if(get(obj,'money')==obj.value)return;
		obj.value.replace(/^\D+$/g,'');
		for(var i=obj.value.length,c=0,aux='';i>=0;i--){
			c++;
			aux+=obj.value.charAt(i);
			if(i==obj.value.length-2&&obj.value.indexOf(',')==-1){
				aux+=',';
				c=0;
			}
			if(i<obj.value.length-2&&c%3==0&&i>0)aux+='.';
		}
		set(obj,'money',aux.mirror());
		obj.value=aux.mirror();
		return aux.mirror();
	}
}

var obp={x:0,y:0,ol:0,ot:0}
var ea;
document.onmouseup=function(){ea=null;}
document.onmousemove=function(){js.move.m();}
js.move={
	d:function(){
		event=event||window.event;
		if(event.which==1||event.button==1){
			ea=event.srcElement.parentNode;
			obp.x=event.clientX;
			obp.y=event.clientY;
			obp.ol=ea.offsetLeft;
			obp.ot=ea.offsetTop;
 		}
	},
	m:function(event){
		if(!ea)return;
		event=event||window.event;
		if(event.which==1||event.button==1){
			var p=[event.clientX,event.clientY];
			ea.style.left=obp.ol+(p[0]-obp.x)+'px';
			ea.style.top=obp.ot+(p[1]-obp.y)+'px';
 		}
	}
}

js.create={
	apply:function(){
		var base=document.getElementsByTagName('base');
		for(var j=0;bt=base[j];j++){
			var len=this.common.jswin_themes.length;
			if(get(bt,'jswin')=='')this.common.jswin_themes[len++]={
				theme:get(bt,'theme'),
				alpha:get(bt,'alpha'),
				bgc:get(bt,'bgc'),
				bgi:get(bt,'bgi'),
				title:get(bt,'title'),
				width:get(bt,'width'),
				hide:get(bt,'hide'),
				pos:get(bt,'pos'),
				style:get(bt,'style')
				};
		}
		
		var b=document.getElementsByTagName('div');
		for(var i=b.length-1;i>=0;i--){
			var ob=b[i];
			if(has(ob,'jswin')){
				this.common.showWindows(ob);
				ob.parentNode.removeChild(ob);
			}else if(has(ob,'jsbar')){
				this.common.showBar(ob);
				ob.parentNode.removeChild(ob);
			}else if(has(ob,'jslabel'))this.common.showLabel(ob);
			else if(has(ob,'jscode'))this.common.showCode(ob);
			else if(has(ob,'jsslide')){
				js.create.common.pn(ob.id);
				this.common.showSlide(ob);
			}
		}
	},
	ci:[0,0],
	//st=[menu,ul,li,over,onclick]
	bar:function(c,li,st){
		if(!c)return false;
		var colors=[c.low(),'#','#','#'];
		var sq='0123456789abcdef';
		for(var i=1;i<colors[0].length;i++){
			var aux=0;
			for(var j=0;j<sq.length;j++)if(colors[0].charAt(i)==sq.charAt(j))aux=j;
		
			colors[1]+=(i%2!=0?sq.charAt((aux-6<0?aux+(aux-6).abs():aux-6).abs()):sq.charAt((aux+3>15?aux-(aux-15):aux+3).abs()));
			colors[2]+=(i%2!=0?sq.charAt((aux+1>15?aux-(aux-15):aux+1).abs()):sq.charAt((aux-3<0?aux+(aux-3).abs():aux-3).abs()));
			colors[3]+=(i%2!=0?sq.charAt((aux+5>15?aux-(aux-15):aux+5).abs()):sq.charAt((aux-8<0?aux+(aux-8).abs():aux-8).abs()));
		}
		
		if(!st)st=['','','','',''];
		else for(var i=0;i<5;i++)if(!st[i])st[i]='';
		
		var div=document.createElement('div');
		div.onselectstart=function(){return false;}
		div.className='jsbar';
		var ul=document.createElement('ul');
		var rep='\<li onmouseover="this.style.background=\''+colors[2]+'\'"';
		rep+=' onmouseout="this.style.background=\'\'"';
		rep+=' onclick="this.style.background=\''+colors[3]+'\'"';
		rep+=' style="color: '+colors[1]+';"';
		li=li.replace(/\<li/g,rep);
		ul.innerHTML=li;
		div.appendChild(ul);
		document.body.appendChild(div);
		c[0]++;
	},
	//ctt[title,ctt]
	win:function(ctt,bg,size,opa,pid,hide,pos,style){
		if(!ctt)return;
		bg[0]?bg[0]:bg[0]='#cccccc';
		if(bg[0]=='null')bg[0]='';
		bg[1]?bg[1]:bg[1]='';
		if(bg[0]!=''){
			var aux=bg[0];
			if(bg[0].charAt(0)=='#'&&bg[0].indexOf(',')==-1){
				aux='';
				bg[0]=bg[0].substr(1);
				if(bg[0].length==3){
					for(i=0;i<3;i++)aux+=bg[0].charAt(i)+bg[0].charAt(i);
					bg[0]=aux;
				}
				aux='';
				aux=js.conv.fromHex(bg[0].charAt(0)+bg[0].charAt(1))+',';
				aux+=js.conv.fromHex(bg[0].charAt(2)+bg[0].charAt(3))+',';
				aux+=js.conv.fromHex(bg[0].charAt(4)+bg[0].charAt(5))+'';
			}
			bg[0]=aux;
		}
		var img=bg[1];
		img=img.split(' ');
		if(!img[1])img[1]=''
		if(!img[2])img[2]='';
		
		if(img[1].indexOf('px')==-1)img[1]+='px';
		if(img[2].indexOf('px')==-1)img[2]+='px';
		var bgp=img[1]+' '+img[2];
		
		if(/\.(png|bmp|jpe?g|png|gif)/.test(bg[1])&&bg[1]!='')bg[1]='url('+img[0]+')';
		
		if(!size)size=['400','400'];
		for(i=0;i<2;i++)if(!size[i])size[i]='400';
		if(!opa)opa=1;
		opa=parseFloat(opa);
		if(opa<=100&&opa>1)opa/=100;
		if(!pos)pos='0 0';
		pos=pos.split(' ');
		if(pos[0]=='auto')pos[0]=((screen.height-(size[1].int()+51))/4);
		if(pos[0].indexOf('px')==-1)pos[0]+='px';
		if(pos[1]=='auto')pos[1]=((screen.width-(size[0].int()+18))/2);
		if(pos[1].indexOf('px')==-1)pos[1]+='px';
		var display=1;
		if(hide=='')hide='none';
		else hide='block';
		
		var global=document.createElement('div');
		global.className='jswin_global';
		set(global,'style','background-image:'+bg[1]+';background-position:'+bgp+';width:'+size[0]+'px;display:'+hide+';top:'+pos[1]+';left:'+pos[0]+';'/*+'filter="alpha(opacity='+(opa*100)+')"'*/);
		global.id=!pid?'js_wind_window_'+this.ci[1]:pid;
		
		if(bg[0]!=''){
			global.style.backgroundColor='rgb('+bg[0]+')';
			if(js.navInfo()[0]!='ie')global.style.backgroundColor='rgba('+bg[0]+','+opa+')';
		}
		
		if(bg[1]!=''){
			global.style.opacity=opa;
			global.style.filter='alpha(opacity='+(opa*100)+')';
		}else{
			global.style.opacity=1;
			global.style.filter='alpha(opacity=100)';
		}
		
		var content=document.createElement('div');
		set(content,'style',style);
		content.className='jswin_content';
		content.id='js_wind_ctt_'+this.ci[1];
		this.common.slidevar[this.common.slideI++]={id:'js_wind_ctt_'+this.ci[1],w:0,h:0,l:0,k:0,off:false};
		typeof ctt[1]=='object'?content.appendChild(ctt[1]):content.innerHTML+=ctt[1];
		var head=document.createElement('div');
		head.id='head';
		head.className='jswin_head';
		head.onselectstart=function(){return false;}
		head.onmouseover=function(){this.style.cursor='move';}
		head.onmouseout=function(){this.style.cursor='default';}
		head.onmousedown=head.ondblclick=function(){
			js.move.d(event);
			var b=document.getElementsByTagName('*');
			var zi=z=0;
			for(i=0; i<b.length; i++){
				z=b[i].style.zIndex;
				if(z>zi)zi=z;
			}
			this.parentNode.style.zIndex=zi+1;
		}
		
		var title=document.createElement('span');
		if(ctt[0]){
			title.innerHTML='▼'+ctt[0];
			title.style.cursor='pointer';
			title.onclick=function(){js.create.common.slide(this);}
		}
		var x=document.createElement('span');
		x.innerHTML='X';
		set(x,'style','float: right;cursor: pointer;');
		if(js.navInfo()[0]=='ie'){
			x.style.position='absolute';
			x.style.right='8px';
			x.style.top='0';
			x.style.float='';
		}
		
		var rrs=document.createElement('div');
		rrs.className='jswin_rslr';
		rrs.style.right='0';
		rrs.onmousedown=function(){
			var g=this.parentNode;
			document.onmousemove=function(){
				var l=(g.offsetWidth+(event.clientX-g.offsetWidth));
				g.style.width=(l>80?l:80)+'px';
			}
			document.onmouseup=function(){
				document.onmousemove=null;
			}
		}
		
		var lrs=document.createElement('div');
		lrs.className='jswin_rslr';
		lrs.style.left='0';
		lrs.onmousedown=function(){
			var g=this.parentNode;
			g.style.right=g.offsetRight+'px';
			document.onmousemove=function(){
				var l=(g.offsetWidth+(g.offsetWidth-event.clientX));
				g.style.width=(l>80?l:80)+'px';
			}
			document.onmouseup=function(){
				document.onmousemove=null;
			}
		}
		
		
		x.onclick=function(){js.dis(this.parentNode.parentNode,0);}
		head.appendChild(title);
		head.appendChild(x);
		global.appendChild(head);
		global.appendChild(content);
		document.body.appendChild(global);
		
		lrs.style.height=(global.offsetHeight-50)+'px';
		rrs.style.height=(global.offsetHeight-50)+'px';
		
		global.appendChild(lrs);
		global.appendChild(rrs);
		
		this.ci[1]++;

	},
	label:function(o){
		if(!o.id||!get(o,'for'))return false;
		var trg=js(get(o,'for'));
		if(!trg)return false;
		o.style.position='absolute';
		o.style.display='none';
		set(trg,'labelob',o.id);
		var over=function(event){
			event=event||window.event;
			var o=js(get(this,'labelob'));
			var t=event.clientY>(screen.availHeight/2)?-1*(o.offsetHeight+15):15;
			var l=event.clientX>(screen.availWidth/2)?-1*(o.offsetWidth+15):15;
			o.style.top=(event.clientY+t)+'px';
			o.style.left=(event.clientX+l)+'px';
			o.style.display='block';
		}
		var move=function(event){
			event=event||window.event;
			var o=js(get(this,'labelob'));
			var t=event.clientY>(screen.availHeight/2)?-(o.offsetHeight+15):15;
			var l=event.clientX>(screen.availWidth/2)?-(o.offsetWidth+15):15;
			o.style.top=(event.clientY+t+(js.navInfo()[0]=='ch'?document.body.scrollTop:document.documentElement.scrollTop))+'px';
			o.style.left=(event.clientX+l)+'px';
		}
		var out=function(){
			js(get(this,'labelob')).style.display='none';
		}
		//set(trg,'onmouseover',js.fctt(trg.onmouseover)+js.fctt(over));
		//set(trg,'onmousemove',js.fctt(trg.onmousemove)+js.fctt(move));
		//set(trg,'onmouseout',js.fctt(trg.onmouseout)+js.fctt(out));
		trg.onmouseover=over;
		trg.onmouseout=out;
		trg.onmousemove=move;
	},
	code:function(o,l){
		o.className='jscode';
		tx=o.innerHTML;
		tx=tx.replace(/&/g,'&amp;');
		tx=tx.replace(/</g,'&lt;');
		tx=tx.replace(/>/g,'&gt;');
		tx=tx.replace(/	/g,'&nbsp;&nbsp;&nbsp;&nbsp;');
		
		var lang=['js','html','java'];

		var js=[ 
				[/(:|=)/g,'<span class="jscode_str">$1</span>'],
				[/(\/[^\/>]+\/[^\/\\])(.*)/g,'<span class="jscode_re">$1</span>$2'],
				[/(\d)/g,'<span class="jscode_num">$1</span>'],
				[RegExp('([^\w])?(set(Interval|Timeout)|resize(By|To)|isNaN|getSelection|eval|(un)?escape|Date|(de|en)codeURI(Component)?|RegExp|Boolean|Array|String|Number|Object|Math|abs|floor|ceil|max|min|round|sqrt|pow|acos|asin|a?tan2?|E|PI|random|exp|log|replace|charAt|split|slice|substr(ing)?|(i|lastI)ndexOf|parse(Int|Float)?)([^\w])','g'),'$1<span class="jscode_fct">$2</span>$11'],
				[RegExp('([^\w])(stop|scroll(By|To)?|open|navigator|move(By|To)|home|forward|find|focus|clear(Interval|Timeout)|captureEvents|close|confirm|prompt|alert|blur|screen|back|event|document|window|([^<]body[^(\s*)?\/?>]))','g'),'$1<span class="jscode_ppt">$2</span>'],
				[/('[^']*')/g,'<span class="jscode_str">$1</span>'],
				[/("[^"]*")[^>]$/g,'<span class="jscode_str">$1</span>'],
				[/(function)/g,'<span class="jscode_bld">$1</span>'],
				[/(\(|\)|\{|\}|\[|\])/g,'<span class="jscode_res">$1</span>'],
[/([^\w])(instanceof|var|for|break|if|else|typeof|this|new|in|try|catch|throw|with|void|delete)([^\w])/g,'$1<span class="jscode_res">$2</span>$3'],
				[/\/\/(.*)(\n|\r\n)(.*)/g,'<br/><span class="jscode_cmt">//$1$2</span><br/>$3'],
				[/\/\*(.*|\n*|\r\n*)\*\//g,'<span class="jscode_doc">/*$1*/</span>'],
				[/(@(param|ret|author))/g,'<span class="bld_doc">$1</span>'],
				];
		
		
		var html=[ [/:/,'<span style="color: #0000ff;">:</span>'],
				 [],
				];
		
		var java=[ [/:/,'<span style="color: #0000ff;">:</span>'],
				 [],
				];
		
		var re=[js,html,java];
		
		for(var i=0;i<lang.length;i++)if(l==lang[i]){l=i;break;}
		
		for(var i=0;el=re[l][i];i++)tx=tx.replace(el[0],el[1]);
		
		if(document.all)tx=tx.replace(/\r\n/g,'<br/><br/>');
		else tx=tx.replace(/\n/g,'<br/><br/>');
		tx=tx.substr(tx.charAt(0)=='<'?5:0);
		o.innerHTML=tx;
		
	},
	slide:function(o){
		var cn=o.getElementsByTagName('*');
		for(var i=0,e;e=cn[i++];){
			if(has(e,'jspanel'))e.style.overflow='hidden';
			if(has(e,'jsbt')){
				
				var over=function(){
					var actual=0;
					function goto(n){
						if(!n){
							actual=ul.offsetLeft-5;
							ul.style.left=actual+'px';
							if(actual%panel.offsetWidth!=0)setTimeout(function(){goto();},33);
						}else{
							actual=ul.offsetLeft+5;
							ul.style.left=actual+'px';
							if(actual%panel.offsetWidth!=0)setTimeout(function(){goto(1);},33);
						}
					}
					var sn=(this.get('goto')).substring(0,1);
					var v=(this.get('goto').substr(1)).int();
					var o=this.parentNode;
					var panel=js.create.common.pn(o.id)
					var ul=panel.getElementsByTagName('ul')[0];
					if(sn=='+')goto();
					else goto(1);		
				}
				
				set(e,'onmouseover',js.fctt(e.get('onmouseover'))+js.fctt(over));
			}
		}
		
	},
	common:{
		showCode:function(div){
			js.create.code(div,div.get('language'));
		},
		showLabel:function(div){
			js.create.label(div);
		},
		showBar:function(div){
			js.create.bar(div.get('color'),div.innerHTML);
		},
		showSlide:function(div){
			js.create.slide(div);
		},
		pn:function(id){
			var cn=document.getElementsByTagName('div');
			for(var i=0,e;e=cn[i++];){
				if(has(e,'jsslide')&&e.has(e,'id')&&e.id==id){
					var n=e.getElementsByTagName('div');
					for(var j=0,s;s=n[j++];)if(has(s,'jspanel')){
						var imgs=s.getElementsByTagName('ul')[0];
						for(var r=0,m;m=imgs.childNodes[r];r++){
							if(m&&(m.nodeType==1&&m.style.float!='left'))m.style.float='left';
						}
						return s;
					}
				}
			}
		},
		t:null,
		goto:function(o,w,q){
			q=q?q:33;
			js.create.common.t=setInterval(function(){
					
					e.style.position=tw;
			},q);
		},
		jswin_themes:new Array(),
		showWindows:function(div){
			jan=div;
			var atb=['','','','','','1','',''];
			if(has(jan,'theme')){
				for(j=0;plus=this.jswin_themes[j];j++){
					if(plus.theme==get(jan,'theme'))atb=[plus.title,plus.bgc,plus.bgi,plus.width,plus.alpha,plus.hide,plus.pos,plus.style];
				}
			}
			
			js.create.win(
						  [get(jan,'title')?get(jan,'title'):atb[0],jan.innerHTML],
						  [get(jan,'bgc')?get(jan,'bgc'):atb[1],get(jan,'bgi')?get(jan,'bgi'):atb[2]],
						  [get(jan,'width')?get(jan,'width'):atb[3],get(jan,'height')],
						  get(jan,'alpha')?get(jan,'alpha'):atb[4],
						  get(jan,'id'),
						  has(jan,'hide')?'':atb[5],
						  get(jan,'pos')?get(jan,'pos'):atb[6],
						  atb[7]+';'+(has(jan,'style')?get(jan,'style'):'')
						  );
			
		},
		slidevar:new Array(),
		slideI:0,
		slide:function(o){
			o=js(o);
			var t=o.innerHTML;
			var ctt=js(o).parentNode.parentNode.childNodes[1];
			for(i=0;i<this.slideI;i++)if(ctt.id==this.slidevar[i].id)if(!this.slidevar[i].off){
				this.slidevar[i].h=ctt.offsetHeight;
				this.slidevar[i].l=ctt.offsetHeight+5;
				this.slidevar[i].off=true;
				this.slidevar[i].w=ctt.offsetWidth;
			}
			var k=-1;
			for(i=0;i<this.slideI;i++)if(ctt.id==this.slidevar[i].id)k=i;
			js(o).innerHTML=(this.slidevar[k].k==0?'►':'▼')+t.substr(1);
			if(this.slidevar[k].k==0){
				if(this.slidevar[k].h<=50)js.dis(ctt,0);
				setTimeout(function(){
						js.create.common.slidevar[k].h-=3.1;
						ctt.style.height=js.create.common.slidevar[k].h+'px';
						if(js.create.common.slidevar[k].h<=0)js.create.common.slidevar[k].k=1;
						else js.create.common.slide(o,t);
				},11);
			}else{
				ctt.style.width=this.slidevar[k].w-13+'px';
				if(js.create.common.slidevar[k].h>=50)js.dis(ctt,1);
				setTimeout(function(){
						js.create.common.slidevar[k].h+=3.1;
						ctt.style.height=js.create.common.slidevar[k].h+'px';
						if(js.create.common.slidevar[k].h>=js.create.common.slidevar[k].l)js.create.common.slidevar[k].k=0;
						else js.create.common.slide(o,t);
				},11);
			}
		}
	}
}

js.imgDec={
	apply:function(){
		var imgs=document.images;
		for(var i=0;e=imgs[i];i++){
			var atb=[get(e,'jsfade'),get(e,'jsbright'),get(e,'jsphoto')];
			if(has(e,'jsfade'))this.fade(e,atb[0]!=''?atb[0]:null);
			if(has(e,'jsbright'))this.bright(e,atb[1]!=''?atb[1]:null);
			if(has(e,'jsphoto'))this.photo(e,atb[2]!=''?atb[2]:null);
		}
	},
	hue:function(o,c,v){
		if(!o)return;
		o=js(o);
		if(c.charAt(0)=='#'){
		}else{
		}
		if(!v)v=50;
		var div=document.createElement('div');
		div.style.width=o.style.width?(o.style.width):(o.width+'px');
		div.style.height=o.style.height?(o.style.height):(o.height+'px');
		div.style.backgroundColor=c;
		div.style.filter='alpha(opacity='+v+');';
		div.style.opacity=(v/100);
		div.style.position='absolute';
		o.style.position='absolute';
		div.style.cssText+='-moz-opacity:'+(v/100);
		div.id='hue_color_div';
		var g=document.createElement('div');
		o.parentNode.appendChild(div);
	},
	bright:function(o,v){
		if(!o||!v||v==0)return;
		if(v>9)v=9;
		else if(v<-9)v=-9;
		o=js(o);
		v*=10;
		
		var div=document.createElement('div');
		div.style.width=o.style.width?(o.style.width):(o.width+'px');
		div.style.height=o.style.height?(o.style.height):(o.height+'px');
		div.style.backgroundColor=(v<0)?'#000000':'#ffffff';
		v=v.abs();
		div.style.filter='alpha(opacity='+v+');';
		div.style.opacity=(v/100);
		div.style.position='absolute';
		o.style.position='absolute';
		div.style.cssText+='-moz-opacity:'+(v/100);
		div.style.zIndex=10;
		
		var g=document.createElement('div');
		g.style.position='relative';
		g.appendChild(div);
		o.parentNode.appendChild(g);
		g.appendChild(o);
	},
	photo:function(o,s){
		s=s.split(' ');
		var zoom=s[1]?true:false;
		s=s[0]?s[0]:1;
		
		var div=document.createElement('div');
		div.style.borderTop='2px solid #e4e4e4';
		div.style.borderRight='2px solid #bbbbbb';
		div.style.borderBottom='2px solid #bbbbbb';
		div.style.borderLeft='2px solid #eeeeee';
		div.style.padding='17px';
		div.style.width=o.width+'px';
		
		if(s==2)div.style.backgroundColor='#dfddd3';
		if(s==3)div.style.borderRadius='20px';
		if(s==4)div.style.padding='5px';
		if(s==5){
			div.style.borderRadius='20px';
			div.style.borderTop='5px solid #777777';
			div.style.borderRight='5px solid #292929';
			div.style.borderBottom='5px solid #2b2b2b';
			div.style.borderLeft='5px solid #282828';
			div.style.padding='0px';
			o.style.borderRadius='14px';
		}
		if(s==6){
			div.style.borderRadius='500px';
			div.style.borderTop='5px solid #777777';
			div.style.borderRight='5px solid #292929';
			div.style.borderBottom='5px solid #2b2b2b';
			div.style.borderLeft='5px solid #282828';
			div.style.padding='0px';
			o.style.borderRadius='350px';
		}
		
		set(o,'last_height',o.height);
		o.parentNode.appendChild(div);
		div.appendChild(o);
	},
	fade:function(o,t){
		o=js(o);
		t=t?t:33;
		o.style.filter='alpha(opacity=50);';
		o.style.opacity=0.5;
		set(o,'opa',0.5);
		o.onmouseover=function(){
			if(parseFloat(get(o,'opa'))<1){
				var opa=parseFloat(get(o,'opa'))+0.1;
				set(o,'opa',parseFloat(opa));
				setTimeout(function(){
									o.style.opacity=opa;
									o.style.filter='alpha(opacity='+(opa*100)+');';
									o.onmouseover();},t);
			}
		}
		o.onmouseout=function(){
			if(parseFloat(get(o,'opa'))>0.5){
				var opa=parseFloat(get(o,'opa'))-0.1;
				set(o,'opa',parseFloat(opa));
				setTimeout(function(){
									o.style.opacity=opa;
									o.style.filter='alpha(opacity='+(opa*100)+');';
									o.onmouseout();},t);
			}
		}
	}
}
