var images = new Array();

window.addEvent('domready', function() {
	var url = "/quem-somos/_ajax/";
	
	new Ajax(url, {
		method: 'get',
		update: $('sub-quem-texto'),
		onComplete: function() {
			scrollQuem = new Fx.Scroll('scroll_quem_cont', {
				wait: false,
				duration: 500,
				transition: Fx.Transitions.linear
			});
		}
		}).request();

	var url = "/clientes/_ajax/";
	
	new Ajax(url, {
		method: 'get',
		update: $('sub-clientes-texto'),
		onComplete: function() {
			scrollClientes = new Fx.Scroll('scroll_clientes_cont', {
				wait: false,
				duration: 500,
				transition: Fx.Transitions.linear
			});
		}
		}).request();

	var url = "/servicos/_ajax/";
	
	new Ajax(url, {
		method: 'get',
		update: $('sub-servicos-texto'),
		onComplete: function() {
			scrollServicos = new Fx.Scroll('scroll_servicos_cont', {
				wait: false,
				duration: 500,
				transition: Fx.Transitions.linear
			});
		}
		}).request();

	if ($('texto-equipe-list')) {
		var url = "/quem-somos/equipe/_ajax/";
		
		new Ajax(url, {
			method: 'get',
			update: $('texto-equipe-list'),
			onComplete: function() {
				scrollEquipe = new Fx.Scroll('scroll_equipe_cont', {
					wait: false,
					duration: 500,
					transition: Fx.Transitions.linear
				});
			}
			}).request();
	}

	var TipsEquipe = new Tips($$('#thumbs img'), {
		initialize:function(){
			this.fx = new Fx.Style(this.toolTip, 'opacity', {duration: 500, wait: false}).set(0);
		},
		onShow: function(toolTip) {
			this.fx.start(1);
		},
		onHide: function(toolTip) {
			this.fx.start(0);
		}
	});
	var TipsEquipe = new Tips($$('#thumbs-clientes img'), {
		initialize:function(){
			this.fx = new Fx.Style(this.toolTip, 'opacity', {duration: 500, wait: false}).set(0);
		},
		onShow: function(toolTip) {
			this.fx.start(1);
		},
		onHide: function(toolTip) {
			this.fx.start(0);
		}
	});
	
});

var first_quem = true;
var first_servicos = true;
var first_clientes = true;

function submenu_mouseout(menu_name){
	if (menu_name == 'quem')
		first_quem = false;
	if (menu_name == 'servicos')
		first_servicos = false;
	if (menu_name == 'clientes')
		first_clientes = false;
	document.getElementById('sub-'+menu_name).style.display='none';
	document.getElementById('sub-'+menu_name+'-texto').style.display='none';
	document.getElementById(menu_name+'-anchor').className='';
	document.getElementById('sub-'+menu_name+'-nav-down').style.display='none';
	document.getElementById('sub-'+menu_name+'-nav-up').style.display='none';
	document.getElementById('scroll_'+menu_name+'_cont').style.display='none';
}

function submenu_mouseover(menu_name, from){

	if (   (first_quem && menu_name == 'quem' && from == 'sub' ) 
		|| (first_servicos && menu_name == 'servicos' && from == 'sub') 
		|| (first_clientes && menu_name == 'clientes' && from == 'sub') ) {
		qqcoisa=1;
	} else {
		document.getElementById('sub-'+menu_name).style.display='block';
		document.getElementById('sub-'+menu_name+'-texto').style.display='block';
		document.getElementById(menu_name+'-anchor').className=menu_name+'-hover';
		document.getElementById('scroll_'+menu_name+'_cont').style.display='block';
		if ( document.getElementById('sub-'+menu_name+'-texto').offsetHeight > document.getElementById('scroll_'+menu_name+'_cont').offsetHeight ) {
			document.getElementById('sub-'+menu_name+'-nav-down').style.display='block';
			document.getElementById('sub-'+menu_name+'-nav-up').style.display='block';
		}
	}
}

var incr_cliente = 0;
var incr_servicos = 0;
var incr_equipe = 0;

function submenu_scroll_down(menu_name) {
	if (menu_name == 'clientes') {
		if (incr_cliente <= ( document.getElementById('sub-'+menu_name+'-texto').offsetHeight - document.getElementById('scroll_'+menu_name+'_cont').offsetHeight ) ) {
			incr_cliente += 70;
			scrollClientes.scrollTo(0,incr_cliente);
		}
	}
	if (menu_name == 'servicos') {
		if (incr_servicos <= ( document.getElementById('sub-'+menu_name+'-texto').offsetHeight - document.getElementById('scroll_'+menu_name+'_cont').offsetHeight ) ) {
			incr_servicos += 70;
			scrollServicos.scrollTo(0,incr_servicos);
		}
	}

	if (menu_name == 'equipe') {
		if (incr_equipe <= ( document.getElementById('texto-equipe-list').offsetHeight - document.getElementById('scroll_equipe_cont').offsetHeight) ) {
			incr_equipe += 70;
			scrollEquipe.scrollTo(0,incr_equipe);
		}
	}

}

function submenu_scroll_up(menu_name) {
	if (menu_name == 'clientes') {
		if (incr_cliente >= 70) {
			incr_cliente -= 70;
			scrollClientes.scrollTo(0,incr_cliente);
		}
	}

	if (menu_name == 'servicos') {
		if (incr_servicos >= 70) {
			incr_servicos -= 70;
			scrollServicos.scrollTo(0,incr_servicos);
		}
	}

	if (menu_name == 'equipe') {
		if (incr_equipe >= 70) {
			incr_equipe -= 70;
			scrollEquipe.scrollTo(0,incr_equipe);
		}
	}
}


var moving = false;
var currentpos=0;
var currentthumbpos=0;
var moveamount=106;
var thumbnailnum;
var maxthumbvisible = 5;
var transspeed=150;

var atual;
var tipo_atual;

function checkbutton(mynum){
	if ( mynum == 0 ) {
		mm_shl('back','hidden');
		mm_shl('more','visible');
	} else if ( mynum < thumbnailnum - maxthumbvisible ) {
		mm_shl('back','visible');
		mm_shl('more','visible');
	} else {
		mm_shl('back','visible');
		mm_shl('more','hidden');
	}
}
function checknext(mynum){
	thumbmax=(Number(thumbnailnum)-1);
	if ( mynum < 1 ) {
		mm_shl('prev','hidden');
		mm_shl('next','visible');
	} else if ( mynum <  thumbmax ) {
		mm_shl('prev','visible');
		mm_shl('next','visible');
	} else {
		mm_shl('prev','visible');
		mm_shl('next','hidden');
	}
}

function mm_shl() { //v6.0
	var obj,args=arguments;
	if ((obj=MM_findObj(args[0]))!=null) {
		if (obj.style) {
			obj=obj.style;
		}
		obj.visibility=args[1];
	}
}


function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function addposition(addwidth){
	if ( !moving ) {
		 // if animagic is still moving the image..don't update the current position till it's done
		if(addwidth=="minus"){
			currentpos-=1;
		}else if(addwidth=="plus"){
			currentpos+=1;
		}
	}
	return currentpos;
}
function movethumbs(way){
	if(way=='plus'){
		move=(currentthumbpos+moveamount);
		var movethumbs = new Fx.Styles('thumbgall', {duration: transspeed, transition: Fx.Transitions.quadOut});
		movethumbs.start({ left: [currentthumbpos, move]});
		currentthumbpos+=moveamount;
	}else if(way=='minus'){
		move=(currentthumbpos-moveamount);
		var movethumbs = new Fx.Styles('thumbgall', {duration: transspeed, transition: Fx.Transitions.quadOut});
		movethumbs.start({ left: [currentthumbpos, move]});
		currentthumbpos-=moveamount;
	}
}
function over_equipe(id, tipo) {
	obj = document.getElementById(id);
	if (tipo == 'equipe01') {
		obj.style.background="url(/media/fundo_equipe01.jpg) no-repeat -2px -115px"
	}
	if (tipo == 'equipe02') {
		obj.style.background="url(/media/fundo_equipe02.jpg) no-repeat -2px -113px"
	}
	if (tipo == 'equipe03') {
		obj.style.background="url(/media/fundo_equipe03.jpg) no-repeat -1px -115px"
	}
	if (tipo == 'equipe04') {
		obj.style.background="url(/media/fundo_equipe04.jpg) no-repeat 0px -113px"
	}
}
function out_equipe(id, tipo) {
	if (id != atual) {
		obj = document.getElementById(id);

		if (tipo == 'equipe01') {
			obj.style.background="url(/media/fundo_equipe01.jpg) no-repeat -2px -2px"
		}
		if (tipo == 'equipe02') {
			obj.style.background="url(/media/fundo_equipe02.jpg) no-repeat -2px 0px"
		}
		if (tipo == 'equipe03') {
			obj.style.background="url(/media/fundo_equipe03.jpg) no-repeat -1px -2px"
		}
		if (tipo == 'equipe04') {
			obj.style.background="url(/media/fundo_equipe04.jpg) no-repeat"
		}
	}
}

function out_atual() {
	obj = document.getElementById(atual);
	if (tipo_atual == 'equipe01') {
		obj.style.background="url(/media/fundo_equipe01.jpg) no-repeat -2px -2px"
	}
	if (tipo_atual == 'equipe02') {
		obj.style.background="url(/media/fundo_equipe02.jpg) no-repeat -2px 0px"
	}
	if (tipo_atual == 'equipe03') {
		obj.style.background="url(/media/fundo_equipe03.jpg) no-repeat -1px -2px"
	}
	if (tipo_atual == 'equipe04') {
		obj.style.background="url(/media/fundo_equipe04.jpg) no-repeat"
	}
}


function getEquipe(url,id,tipo) {
	out_atual();
	over_equipe(id, tipo);
	atual = id;
	tipo_atual = tipo;
	new Ajax(url, {
		method: 'get',
		update: $('equipe-content')
	}).request();		
}


function over_cliente(id, tipo) {
	obj = document.getElementById(id);
	if (tipo == 'cliente01') {
		obj.style.background="url(/media/fundo_cliente01_novo.jpg) no-repeat 0px -109px"
	}
	if (tipo == 'cliente02') {
		obj.style.background="url(/media/fundo_cliente02_novo.jpg) no-repeat 0px -111px"
	}
	if (tipo == 'cliente03') {
		obj.style.background="url(/media/fundo_cliente03_novo.jpg) no-repeat 0px -106px"
	}
	if (tipo == 'cliente04') {
		obj.style.background="url(/media/fundo_cliente04_novo.jpg) no-repeat 0px -107px"
	}
}
function out_cliente(id, tipo) {
	if (id != atual) {
		obj = document.getElementById(id);

		if (tipo == 'cliente01') {
			obj.style.background="url(/media/fundo_cliente01_novo.jpg) no-repeat"
		}
		if (tipo == 'cliente02') {
			obj.style.background="url(/media/fundo_cliente02_novo.jpg) no-repeat"
		}
		if (tipo == 'cliente03') {
			obj.style.background="url(/media/fundo_cliente03_novo.jpg) no-repeat"
		}
		if (tipo == 'cliente04') {
			obj.style.background="url(/media/fundo_cliente04_novo.jpg) no-repeat"
		}
	}
}

function out_atual_cliente() {
	obj = document.getElementById(atual);
	if (tipo_atual == 'cliente01') {
		obj.style.background="url(/media/fundo_cliente01_novo.jpg) no-repeat"
	}
	if (tipo_atual == 'cliente02') {
		obj.style.background="url(/media/fundo_cliente02_novo.jpg) no-repeat"
	}
	if (tipo_atual == 'cliente03') {
		obj.style.background="url(/media/fundo_cliente03_novo.jpg) no-repeat"
	}
	if (tipo_atual == 'cliente04') {
		obj.style.background="url(/media/fundo_cliente04_novo.jpg) no-repeat"
	}
}


function getCliente(url,id,tipo) {
	out_atual_cliente();
	over_cliente(id, tipo);
	atual = id;
	tipo_atual = tipo;
	new Ajax(url, {
		method: 'get',
		update: $('equipe-content')
	}).request();		
}



