
Hmove=-100;
function moveObjRight() 
{   
 
   	document.getElementById('oclick_p01').style.left=Hmove+"px";
   	Hmove+=2;
   	if(Hmove<100)	
		//alert('rodo')
   	  	window.setTimeout("moveObjRight();", 0);
}
function exibir(){
	moveObjRight('oclick_p01')
}
function piscar(imagem,fator){
		if (fator == 0){document.getElementById('oclick_p01').src = "image/"+imagem+"B.png";}
		if (fator == 1){document.getElementById('oclick_p01').src = "image/"+imagem+".png";}
		if (fator == 2){
			document.getElementById('oclick_p01').src = "image/"+imagem+"B.png";
			fator=-1
		}
		fator++
	//window.setTimeout(function(){piscar(imagem,fator)}, 100);
}
	var m3D = function () {
		/* ---- private vars ---- */
		var debugx = 0
		var imagePath = "image/";
		var nav        = [];
		var composDef  = [];
		var compos     = [];
		var pos        = 0;
		var nbrCompos  = 0;
		var nbrimage  = 0;
		var loadedImg  = 0;
		var loadingBar = 0;
		var widthBar   = 0;
		var xm         = 0;
		var ym         = 0;
		var nw         = 0;
		var nh         = 0;
		var nx         = 0;
		var ny         = 0;
		var obak       = "";
		var movimentar_pelo_mouse = false;
		var scr, structure;
		/* ---- Easing function ---- */
		var Ease = function () {
			this.target = 0;
			this.position = 0;
		}
		Ease.prototype.move = function (target, speed) {
			this.position += (target - this.position) * speed;
		}
		/* ---- camera setup ---- */
		var camera = {
			x : new Ease(),
			y : new Ease(),
			focalLength : 300
		}
		/* ==== composite image Constructor ==== */
		var Compo3D = function (i, p) {
			/* ---- insert HTML element ---- */
			//this.img.id = p[0]
			if (p[0] == "text") {
				/* ---- text ---- */
				this.img = document.getElementById(p[4]).cloneNode(true);
				//this.img.style.right = Math.round(document.body.offsetWidth - 440) + 'px';
				this.img.className = "txt";
				this.img.propriedadeoclick = p[0]
				this.img.style.zIndex = Math.round(1100);
				loadingBar.className = "b_" + p[4];
				this.wt = true;
				this.img.style.display="block"
			} else {
				/* ---- image ---- */
				this.img = document.createElement('img');
				this.img.id = ""+p[0]
				this.img.className = "img";
				this.img.propriedadeoclick = p[0]
				this.img.src = imagePath + p[0] + (p[0].indexOf(".") > 0 ? "" : ".png");
				this.img.style.display="block"
				/* os menus */
				if (p[0] == "oclick_janela_conteudo"){
					this.img.onclick = function(){m3D.goto(28);}
					this.img.style.cursor='pointer';
					this.img.onmouseover = function(evt){
						document.getElementById('oclick_ballon').onclick = function(){m3D.goto(28);}
						document.getElementById('oclick_ballon').style.display="block"
						document.getElementById('oclick_ballon').style.positon="absolute"
						document.getElementById('oclick_ballon').style.zIndex=Math.round(39999)
						document.getElementById('oclick_ballon').src = "image/oclick_ballon.png";
						
						if (typeof evt == 'undefined') {
							myEvent = window.event;
						} else {
							myEvent = evt;
						}
						if(myEvent.clientX){
							posX = myEvent.clientX+document.body.scrollLeft;
							posY = myEvent.clientY+document.body.scrollTop;
						}
						else if(myEvent.pageX){
							posX = myEvent.pageX+window.pageXOffset;
							posY = myEvent.pageY+window.pageYOffset;
						}
						document.getElementById('oclick_ballon').style.top = posY+"px"
						document.getElementById('oclick_ballon').style.left = posX+"px"
						
						
					}
					this.img.onmouseout = function(){
						document.getElementById('oclick_ballon').style.display="none"
					}
				}
				if (p[0] == "oclick_servicos_propaganda"){
					this.img.onclick = function(){m3D.goto(23);}
					this.img.style.cursor='pointer';
				}
				
				if (p[0] == "oclick_servicos_website"){
					this.img.onclick = function(){m3D.goto(24);}
					this.img.style.cursor='pointer';
				}
				if (p[0] == "oclick_servicos_networks"){
					this.img.onclick = function(){m3D.goto(25);}
					this.img.style.cursor='pointer';
				}
				if (p[0] == "oclick_servicos_google"){
					this.img.onclick = function(){m3D.goto(26);}
					this.img.style.cursor='pointer';
				}
				if (p[0] == "oclick_servicos_app"){
					this.img.onclick = function(){m3D.goto(27);}
					this.img.style.cursor='pointer';
				}
				if (p[0] == "oclick_fechar"){
			   		 this.img.onmouseover = function(){document.getElementById('oclick_fechar').src = "image/oclick_fechar_on.png";}
					 this.img.onmouseout = function(){document.getElementById('oclick_fechar').src = "image/oclick_fechar.png";}
					 this.img.style.cursor='pointer';
					 this.img.onclick = function(){m3D.goto(22)}
			   }
			   if (p[0] == "oclick_menu1"){
			   		 this.img.onclick = function(){m3D.goto(1);}
					 this.img.style.cursor='pointer';
			   }
			   if (p[0] == "oclick_menu2"){
			   		 this.img.onclick = function(){m3D.goto(2)}
					 this.img.style.cursor='pointer';
			   }
			   if (p[0] == "oclick_menu3"){
			   		 this.img.onclick = function(){m3D.goto(3)}
					 this.img.style.cursor='pointer';
			   }
			   if (p[0] == "oclick_menu4"){
			   		 this.img.onclick = function(){m3D.goto(4)}
					 this.img.style.cursor='pointer';
			   }
			   if (p[0] == "oclick_2009"){
			   		 this.img.onclick = function(){document.location.href='http://www.oclickbh.com.br/index2.asp'}
					 this.img.style.cursor='pointer';
			   }
			   if (p[0] == "oclick_p01"){
			   		this.img.onclick = function(){m3D.goto(5)}
					this.img.style.cursor='pointer';
			   }
			   if (p[0] == "oclick_p02"){
			   		this.img.onclick = function(){m3D.goto(6)}
					this.img.style.cursor='pointer';
			   }
			   if (p[0] == "oclick_p03"){
			   		this.img.onclick = function(){m3D.goto(7)}
					this.img.style.cursor='pointer';
			   }
			   if (p[0] == "oclick_p04"){
			   		this.img.onclick = function(){m3D.goto(8)}
					this.img.style.cursor='pointer';
			   }
			   if (p[0] == "oclick_p05"){
			   		this.img.onclick = function(){m3D.goto(9)}
					this.img.style.cursor='pointer';
			   }
			   if (p[0] == "oclick_p07"){
			   		this.img.onclick = function(){m3D.goto(10)}
					this.img.style.cursor='pointer';
			   }
			   if (p[0] == "oclick_p08"){
			   		this.img.onclick = function(){m3D.goto(11)}
					this.img.style.cursor='pointer';
			   }
			   if (p[0] == "oclick_p09"){
			   		this.img.onclick = function(){m3D.goto(12)}
					this.img.style.cursor='pointer';
			   }
			   if (p[0] == "oclick_p10"){
			   		this.img.onclick = function(){m3D.goto(13)}
					this.img.style.cursor='pointer';
			   }
			   if (p[0] == "oclick_p11"){
			   		this.img.onclick = function(){m3D.goto(14)}
					this.img.style.cursor='pointer';
			   }
			   if (p[0] == "oclick_p12"){
			   		this.img.onclick = function(){m3D.goto(15)}
					this.img.style.cursor='pointer';
			   }
			   if (p[0] == "oclick_p13"){
			   		this.img.onclick = function(){m3D.goto(16)}
					this.img.style.cursor='pointer';
			   }
			   if (p[0] == "oclick_p14"){
			   		this.img.onclick = function(){m3D.goto(17)}
					this.img.style.cursor='pointer';
			   }
			   if (p[0] == "oclick_p15"){
			   		this.img.onclick = function(){m3D.goto(18)}
					this.img.style.cursor='pointer';
			   }
			   if (p[0] == "oclick_p16"){
			   		this.img.onclick = function(){m3D.goto(19)}
					this.img.style.cursor='pointer';
			   }
			   if (p[0] == "oclick_p17"){
			   		this.img.onclick = function(){m3D.goto(20)}
					this.img.style.cursor='pointer';
			   }
			   if (p[0] == "oclick_p18"){
			   		this.img.onclick = function(){m3D.goto(21)}
					this.img.style.cursor='pointer';
			   }
				if (i >= 0) nbrimage++;
			}
			scr.appendChild(this.img);
			this.ims = this.img.style;
			if (i < 0) {
				/* ---- particles ---- */
				this.particle = true;
				this.active   = true;
			} else {
				this.moving = true;
				if (p[6] * 1 == 1) this.originFountain = true;
				this.active = false;
				this.startDelay = Math.round(i * (100 / structure.length));			
			}
			/* ---- slide in ---- */
			var sx = p[1] * 20 * (p[7] || 1);
			var sy = p[2] * 5 * (p[7] || 1);
			/* ---- 3D variables ---- */
			this.point3D = {
				x  : sx,
				y  : sy,
				z  : p[3] * 1,
				x0 : p[1] * 1,
				y0 : p[2] * 1,
				z0 : p[3] * 1,
				vx : sx - p[1] * 1,
				vy : sy - p[2] * 1,
				vz : 0,
				w  : 0,
				h  : 0,
				zi : (p[8] || 0) * 1
			}
			/* ---- variables ---- */
			this.id      = i;
			this.xs      = 1;
			this.i       = 0;
			this.frm     = 0;
			this.timeout = 0;
			this.loading = true;
			this.loaded  = false;
			/* --- lissajou --- */
			if (p[9] || p[10]) {
				this.lx  = p[9] * 1;
				this.ly  = p[10] * 1;
				this.sx  = p[11] * 1;
				this.sy  = p[12] * 1;
				this.rx  = p[13] * 1 || (Math.random() * Math.PI);
				this.lis = true;
			}
		}
		/* ==== Particles animation ==== */
		Compo3D.prototype.animParticle = function () {
			var p = this.point3D;
			if (!this.initParticle) {
				this.initParticle = true;
				this.life = Math.random() * 200;
			}
			var a = .5 / this.life--;
			p.x  += p.vx;
			p.y  += p.vy;
			p.z  += p.vz;
			p.vx += (Math.random() * 50 - 25) * a;
			p.vy += (Math.random() * 50 - 25) * a;
			p.vz += -Math.random() * a;
			if (this.life < 0) {
				p.x = p.x0;
				p.y = p.y0;
				p.z = p.z0;
				this.life = 200;
				p.vx = 0;
				p.vy = 0;
				p.vz = 0;
			}
		}
		/* ==== 3D parallax Animation ==== */
		Compo3D.prototype.animate = function () {
			if (this.loaded) {
				if (this.active) {
					var p = this.point3D;
					/* ---- move to position ---- */
					if (this.moving) {
						if (this.frm <= 100) {
							this.i += this.xs;
							p.x -= (p.vx * this.i * .0004);
							p.y -= (p.vy * this.i * .0004);
							if (this.i == 50) this.xs = -1;
							
						} else {
							p.x = p.x0;
							p.y = p.y0;
							this.moving = false;
							/* ---- particles origin ---- */
							if (this.originFountain) {
								for (var i = 0; i < compos.length; i++) {
									var o = compos[i];
									if (o.particle) {
										o.point3D.x0 = p.x0;
										o.point3D.y0 = p.y0;
										o.point3D.z0 = p.z0;
									}
								}
							}
							/* --- kill object --- */
							if (this.remove) {
								scr.removeChild(this.img);
								return false;
							}
							/* --- reset loading bar --- */
							if (this.wt) widthBar = 230;
						}
					}
					/* ---- parallax ---- */
					var x = p.x + camera.x.position;
					var y = p.y + camera.y.position;
					var scale = camera.focalLength / (camera.focalLength + p.z);
					x *= scale;
					y *= scale;
					/* ---- lissajou ---- */
					if (this.lis) {
						x += Math.sin(this.frm * this.sx) * this.lx;
						y += Math.sin(this.rx + this.frm * this.sy) * this.ly;
					}
					/* ---- positioning ---- */
											//debugx++
						//if (debugx == -1){
						//	alert(Math.round(document.body.offsetWidth - this.img.width))
						//}
					if (this.img.propriedadeoclick == 'oclick_portfolio' ||  this.img.propriedadeoclick == 'oclick_paper'  ||  this.img.propriedadeoclick == 'oclick_2009' ){
						this.ims.left = Math.round(document.body.offsetWidth - this.img.width) + 'px';
						if (this.img.propriedadeoclick == 'oclick_2009'){
							this.ims.bottom  = Math.round(20) + 'px';  
						}else{
							this.ims.top = Math.round((-camera.y.position * .9) + y + nh - p.h) + 'px';  
						}
					}else{
						if (this.img.propriedadeoclick == 'oclick_alerta'){
							this.ims.top = '0px';  
							this.ims.left = '0px';  
						}else if (this.img.propriedadeoclick == 'text'){
							if (pos < 20){
								this.ims.left = Math.round(document.body.offsetWidth - 440) + 'px';
							}else{
								this.ims.left = Math.round((-camera.x.position * .9) + x + nw - p.w) + 'px';
							}
							this.ims.top  = Math.round((-camera.y.position * .9) + y + nh - p.h) + 'px';  
						}else{
							this.ims.left = Math.round((-camera.x.position * .9) + x + nw - p.w) + 'px';
							this.ims.top  = Math.round((-camera.y.position * .9) + y + nh - p.h) + 'px';  
						}
					}
					this.frm++;
				} else {
					/* ---- delay ---- */
					this.startDelay--;
					if (this.startDelay < 0) this.active = true;
				}
			} else {
				if (this.loading) {
					/* ---- Image loaded ---- */
					if (this.img.complete) {
						if (!this.particle) loadedImg++;
						this.loading = false;
						this.point3D.w = this.img.width * .5;
						this.point3D.h = this.img.height * .5;
						this.img.style.zIndex = Math.round(1000 - (this.particle ? -1000 : (this.point3D.z0 + this.point3D.zi)));
						/* ---- update loading bar ---- */
						loadingBar.style.width = Math.round(loadedImg / nbrimage * 235) + 'px';
					}
					this.timeout++;
				}
				if (loadedImg == nbrimage) {
					/* ---- Composition loaded ---- */
					loaded = true;
					for (var i = 0; i < compos.length; i++) {
						var o = compos[i];
						o.loaded = true;
						o.loading = false;
						//alert(pos);
						/*if (pos == 5){
							debugx++
							if (debugx == 1){
								piscar('oclick_p01',0)
							}
						}*/
						if (o.remove) { 
							/*if ((o.img.propriedadeoclick == "oclick_paper" && pos == 3) ){ //|| (o.img.propriedadeoclick == "oclick_paper" && pos == 4)
								//alert('bla')
							}else */if ((o.img.propriedadeoclick == "oclick_paper_servicos" && pos == 4) ){ //|| (o.img.propriedadeoclick == "oclick_paper" && pos == 4)
								o.frm = 0;
								o.moving = true; 
							}else if ((o.img.propriedadeoclick == "oclick_blackout") || (o.img.propriedadeoclick == "oclick_paper_servicos") || (o.img.propriedadeoclick == "oclick_fechar") || (o.img.propriedadeoclick == "text")){
									o.frm = 0;
									o.moving = true;
							}else if (pos >= 22 && pos <= 27){
								
							}else if (pos >= 5 && pos <= 21){
								if ((o.img.propriedadeoclick == "oclick_p01") || (o.img.propriedadeoclick == "oclick_p02") || (o.img.propriedadeoclick == "oclick_p03") || (o.img.propriedadeoclick == "oclick_p04") || (o.img.propriedadeoclick == "oclick_p05") || (o.img.propriedadeoclick == "oclick_p06") || (o.img.propriedadeoclick == "oclick_p07") || (o.img.propriedadeoclick == "oclick_p08") || (o.img.propriedadeoclick == "oclick_p09") || (o.img.propriedadeoclick == "oclick_p10") || (o.img.propriedadeoclick == "oclick_p11") || (o.img.propriedadeoclick == "oclick_p12") || (o.img.propriedadeoclick == "oclick_p13") || (o.img.propriedadeoclick == "oclick_p14") || (o.img.propriedadeoclick == "oclick_p15") || (o.img.propriedadeoclick == "oclick_p16") || (o.img.propriedadeoclick == "oclick_p17") || (o.img.propriedadeoclick == "oclick_p18") ){
									//alert('a');
									//return false;
										
								}else if((o.img.propriedadeoclick == "oclick_portfolio_pradosantiago") || (o.img.propriedadeoclick == "oclick_portfolio_conectandovoce") || (o.img.propriedadeoclick == "oclick_portfolio_jleiteseguros") || (o.img.propriedadeoclick == "oclick_portfolio_anacional") || (o.img.propriedadeoclick == "oclick_portfolio_gabrielequipamentos") || (o.img.propriedadeoclick == "oclick_portfolio_centralminasfreios") || (o.img.propriedadeoclick == "oclick_portfolio_cohelp10") || (o.img.propriedadeoclick == "oclick_portfolio_freiosevia") || (o.img.propriedadeoclick == "oclick_portfolio_lotherico") || (o.img.propriedadeoclick == "oclick_portfolio_andara") || (o.img.propriedadeoclick == "oclick_portfolio_oclickbh") || (o.img.propriedadeoclick == "oclick_portfolio_casadovelocimetro") || (o.img.propriedadeoclick == "oclick_portfolio_icm") || (o.img.propriedadeoclick == "oclick_portfolio_plataformaexato") || (o.img.propriedadeoclick == "oclick_portfolio_canilvonbeg") || (o.img.propriedadeoclick == "oclick_portfolio_filhotesbh") || (o.img.propriedadeoclick == "oclick_portfolio_sitedaanarosa") || (o.img.propriedadeoclick == "oclick_portfolio_conectandovoce") || (o.img.propriedadeoclick == "oclick_portfolio_comhelp10")|| (o.img.propriedadeoclick == "oclick_click") ){
									o.frm = 0;
									o.moving = true;
								}
							}else if ((o.img.propriedadeoclick == "oclick_servicos_website") || (o.img.propriedadeoclick == "oclick_servicos_networks") || (o.img.propriedadeoclick == "oclick_servicos_google") || (o.img.propriedadeoclick == "oclick_servicos_app") || (o.img.propriedadeoclick == "oclick_servicos_propaganda") || (o.img.propriedadeoclick == "oclick_reflect_quadrado") || (o.img.propriedadeoclick == "text") || (o.img.propriedadeoclick == "oclick_paper") || (o.img.propriedadeoclick == "oclickbh_passaros") || (o.img.propriedadeoclick == "oclick_fonte") || (o.img.propriedadeoclick == "oclickbh_logo") || (o.img.propriedadeoclick == "oclick_portfolio") || (o.img.propriedadeoclick == "oclick_p01") || (o.img.propriedadeoclick == "oclick_p02") || (o.img.propriedadeoclick == "oclick_p03") || (o.img.propriedadeoclick == "oclick_p04") || (o.img.propriedadeoclick == "oclick_p05") || (o.img.propriedadeoclick == "oclick_p06") || (o.img.propriedadeoclick == "oclick_p07") || (o.img.propriedadeoclick == "oclick_p08") || (o.img.propriedadeoclick == "oclick_p09") || (o.img.propriedadeoclick == "oclick_p10") || (o.img.propriedadeoclick == "oclick_p11") || (o.img.propriedadeoclick == "oclick_p12") || (o.img.propriedadeoclick == "oclick_p13") || (o.img.propriedadeoclick == "oclick_p14") || (o.img.propriedadeoclick == "oclick_p15") || (o.img.propriedadeoclick == "oclick_p16") || (o.img.propriedadeoclick == "oclick_p17") || (o.img.propriedadeoclick == "oclick_p18") ){
								o.frm = 0;
								o.moving = true;
							}else if((o.img.propriedadeoclick == "oclick_portfolio_pradosantiago") || (o.img.propriedadeoclick == "oclick_portfolio_jleiteseguros") || (o.img.propriedadeoclick == "oclick_portfolio_anacional") || (o.img.propriedadeoclick == "oclick_portfolio_gabrielequipamentos") || (o.img.propriedadeoclick == "oclick_portfolio_centralminasfreios") || (o.img.propriedadeoclick == "oclick_portfolio_cohelp10") || (o.img.propriedadeoclick == "oclick_portfolio_freiosevia") || (o.img.propriedadeoclick == "oclick_portfolio_lotherico") || (o.img.propriedadeoclick == "oclick_portfolio_andara") || (o.img.propriedadeoclick == "oclick_portfolio_oclickbh") || (o.img.propriedadeoclick == "oclick_portfolio_casadovelocimetro") || (o.img.propriedadeoclick == "oclick_portfolio_icm") || (o.img.propriedadeoclick == "oclick_portfolio_plataformaexato") || (o.img.propriedadeoclick == "oclick_portfolio_canilvonbeg") || (o.img.propriedadeoclick == "oclick_portfolio_filhotesbh") || (o.img.propriedadeoclick == "oclick_portfolio_sitedaanarosa") || (o.img.propriedadeoclick == "oclick_portfolio_conectandovoce") || (o.img.propriedadeoclick == "oclick_portfolio_comhelp10")|| (o.img.propriedadeoclick == "oclick_click") ){
								o.frm = 0;
								o.moving = true;
							}
						}
					}
				}
				if (this.timeout > 1000) {
					this.remove = true;
					this.img.style.display = "none";
					nbrimage--;
				}
			}
			return true;
		}
		/* ==== position html ==== */
		var position = function (param) {
			var i = 0, o;
			while( o = param[i++] ) {
				var id = document.getElementById(o[0]) || o[0];
				if (o.length > 3) {
				   /*Largura da Apresentao 
					id.style.width  = Math.round(o[3]) + "px";
					id.style.height = Math.round(o[4]) + "px";
					/*Largura da Apresentao*/
					id.style.width  = document.body.offsetWidth+"px";
					id.style.height = document.body.offsetHeight+"px"; /*Largura da Apresentao*/
				}
				id.style.left = "0px";
				id.style.top  = "0px";
				/*
				id.style.left = Math.round(o[1]) + "px";
				id.style.top  = Math.round(o[2]) + "px";
				*/
			}
		}
		/* ==== Inject new structure ==== */
		var loadStructure = function (pos) {
			/*Minha adaptação*/
			if (pos == 3 || pos == 4){
				for (var i = 0; i < compos.length; i++) {
					var o = compos[i];
					if (o.img.propriedadeoclick == "oclick_paper"){
						var encontrado = "sim"
					}
				}
				if (encontrado){
					structure = composDef[pos].split(";");
				}else{
					if (pos == 3){
						//composDef[pos] = "text,0,-130,0,servicos;oclick_paper,0,80,0;"
					}
					if(pos == 4){
						composDef[pos] = "text,0,-130,0,contato;oclick_paper,0,80,0;"
					}
					structure = composDef[pos].split(";");
				}
			}else{
				structure = composDef[pos].split(";");
			}
			
			for (var i = 0; i < structure.length; i++) {
				var p = structure[i].replace(/^\s+/g,'').replace(/\s+$/g,'').split(",");
				if (p != "") compos.push(new Compo3D(i, p));
			}
		}
		/* ==== switch to new image (on click) ==== */
		var transition = function (p) {
			if (loadedImg == nbrimage) {
				widthBar = 0;
				loadingBar.style.width = "0px";
				if (p) pos = p - 1; else pos = ++pos % nbrCompos;
				var j = 0;
				for (var i = 0; i < compos.length; i++) {
					var o = compos[i];
						if (!o.particle) {
									o.remove = true;
								}
				}
				loadStructure(pos);
			}
		}
		/* ==== Initialize image structures ==== */
		var initScript = function () {
			/* --- create particles --- 
			for (var i = 0; i < 40; i++)
				compos.push(new Compo3D(-1, [
					Math.random()>.7 ? "sphere_moy_v3" : "sphere_min_v3", -999, -999, 40, '', '', 1
				]));
			/* --- decode HTML structure --- */
			var d = document.getElementById("data");
			if (d) {
				nbrCompos = 0;
				for (var i = 0, k = 0; i < d.childNodes.length; i++) {
					if (d.childNodes[i].nodeType == 1) {
						var c = composDef[nbrCompos++] = d.childNodes[i].innerHTML;
						/* ---- color ---- */
						c = c.split(";");
						c = c[c.length - 2].split(',');
						if (c[c.length - 1] != "") nav[k++] = c[c.length - 1];
						if (obak == "") obak = c[c.length - 1];
					}
				}
			}
			/* --- load first compo --- */
			loadStructure(0);
		}
		////////////////////////////////////////////////////////////////////////////
		/* ==== DOM events ==== */
		function addEvent (o, e, f) {
			if (window.addEventListener) o.addEventListener(e, f, false);
			else if (window.attachEvent) r = o.attachEvent('on' + e, f);
		}
		/* ==== screen position and dimensions ==== */
		function resize() {
			/* --- resize --- */
			var h = Math.max(200, Math.min(700, document.body.offsetHeight));
			var w = Math.max(320, Math.min(1000, document.body.offsetWidth));
			nx = Math.round(30 + (document.body.offsetWidth - w) * .5);
			ny = Math.round(50 + (document.body.offsetHeight - h) * .5);
			nw = (w - 60) * .5;
			nh = (h - 100) * .5;
			/* --- borders --- */
			document.getElementById("design").style.visibility = "visible";
			position([
				[scr, nx, ny, w - 60, h - 100],
				["ILB_bar", nx + nw - 118, 12 + ny + nh * 2]
			]);
			return false;
		}	
		/* ==== browser events ==== */
		var initEvents = function () {
			/* ---- mouse move ---- */
			if (movimentar_pelo_mouse){
				addEvent(scr, 'mousemove', function (e) {
					if (window.event) e = window.event;
					xm = e.clientX;
					ym = e.clientY;
				});
			}
			/* ---- screen resize ---- */
			resize();
			addEvent(window, 'resize', resize);
			scr.onselectstart = function () { return false; }
			scr.ondrag        = function () { return false; }
			scr.ondblclick    = function () { return false; }
		}
		////////////////////////////////////////////////////////////////////////////
		/* ==== main loop ==== */
		var run = function () {
			/* --- move camera --- */
			camera.x.move(xm - nw - nx, .1);
			camera.y.move(ym - nh - ny, .1);
			/* --- loop through image --- */
			var i = 0, o;
			while( o = compos[i++] ) {
				if (o.particle) o.animParticle();
				if (!o.animate()) compos.splice(--i, 1);
			}
			/* --- reset loading bar --- */
			if (widthBar) {
				widthBar *= .9;
				if (widthBar < 1) widthBar = 0;
				loadingBar.style.width = Math.round(widthBar) + "px";
			}
			/* --- loop --- */
	    	setTimeout(run, 16);
		}
		return {
			////////////////////////////////////////////////////////////////////////////
			/* ==== initialize script ==== */
			init : function () {
				addEvent(window, 'load', function () {
					/* ---- init script ---- */
					if (!document.getElementById('ie6')) {
						scr = document.getElementById("screen");
						loadingBar = document.getElementById('ILB_bar');
						initEvents();
						initScript();
						run();
					}
				});
			},
			/* ---- extrenal access ---- */
			button : function (o, src, i) {
				if (i != pos) {
					if (!src) src = "b_" + nav[pos];
					o.src = document.getElementById(src).src;
				}
			},
			next : function () {
				transition();
			},
			goto : function (p) {
				if (p != pos) transition(p + 1);
			}
		}

	}();
	
	/* ==== start script ==== */
	m3D.init();
