$(document).ready(function(){
   $('.menu a[href=#modal]').click(function(){
			
			ModalWindow('http://www.atilaerosi.com.br/index3.html','iframe');													 
		})
	 
	 $('.menu ul').css({'display':'none'});
		$('.sub a').click(function(){
			$(this).parent('li.sub').children('ul').slideToggle();													 
		});
		$('.menu').slideUp(800);
		$('.expande-menu').click(function(){
			var easing = 'swing';
			var tempo = 500;
			$('.menu:not(:animated)').slideUp(tempo, easing);
			$(this).parents('div[class*=titulo]').next('.menu:not(:animated)').slideDown(tempo, easing);
			//alert('feito');
		});
		var heightNoticias = $('.noticias').height();
		var heightArtigos = $('.artigos').height();
		if(heightNoticias > heightArtigos){
				$('.artigos').height(heightNoticias);
			}
			
		if($('.artigos').height() >= $('.primeiroContato').height()){
				
			}else{
				$('.artigos').height($('.primeiroContato').height());
			}
			
			
			
			
});
hs.graphicsDir = 'highslide/graphics/';
hs.align = 'center';
hs.transitions = ['expand', 'crossfade'];
hs.outlineType = 'rounded-white';
hs.fadeInOut = true;
hs.dimmingOpacity = 0.75;
// define the restraining box
hs.useBox = false;
hs.width = "";
hs.height = "";
// Add the controlbar
hs.addSlideshow({
    //slideshowGroup: 'group1',
    interval: 5000,
    repeat: false,
    useControls: true,
    fixedControls: 'fit',
    overlayOptions: {
        opacity: 1,
        position: 'bottom center',
        hideOnMouseOut: true
    }
});

function centralizaDiv(id, vel)
{
    var left = ((parseInt($(document.body).width()) - parseInt($(id).width()))/2)-15;
		//var documento = $('body').height();
		//var janela = $(window).height();
		//if(documento > janela){
		//	var dif = (documento - janela);
			//var top = ((parseInt($('body').height()) - parseInt($('#'+id).height()))/2)-15;
		//}else{
			var top = ((parseInt($(window).height()) - parseInt($(id).height()))/2)-15;
		//}
		
		
    $(id).stop().animate({
        'left': left<0?0:left,
        'top': top<0?0:top
        }, vel, 'swing');
}

function setFundoSize(id){
	if($('body').height() <= $(window).height()){
		altura = $(window).height();
	}else{
		altura = $('body').outerHeight();
	}
	
	$(id).height(altura);	
}

function ModalWindow(dados,metodo,titulo,width,height){
	//var conteudo = $(dados).html();
	//tipos = normal, ajax, iframe;
	var metodo = metodo || 'normal';
	var conteudo = '';

	//cria o objeto #fundo
	$('<div/>',{
		id:'fundo'		
	}).appendTo('body');

	//cria o objeto #window
	$('<div/>',{
		id:'window'		
	}).appendTo('body');
	
	//seta o tamanho de #fundo
	setFundoSize('#fundo');
	
	//seta os tamanhos da janela SE houver...
	(width)?$('#window').css({'width':width}):'';
	(height)?$('#window').css({'height':height}):'';
	
	$('#window').html('<p>'+titulo+'<a class="close" href="#"><img src="images/close.png" /></a></p><div id="content"></div>');
	centralizaDiv('#window',300);
	
	//verifica o tipo de metodo usado
	if(metodo == 'normal'){
			conteudo = $(dados).html();
			$('#window #content').html(conteudo);
		}else if(metodo == 'ajax'){
			$.get(dados,function(data){
				$('#window #content').html(data);										 
			});
			$('#window #content').html(conteudo);
		}else if(metodo == 'iframe'){
			$('#window #content').html('<iframe src='+dados+' frameborder="0"></iframe>');
			$('#window #content iframe').width($('#window').width()).height($('#window').height()-25).attr('src',dados);
		}
			
	//faz a animação para exibir #fundo e #window
	$('#fundo').slideDown();
	$('#window').slideDown();
	
	//metodo de fechar do botao CLOSE
	$('.close').click(function(){
		$('#fundo').slideUp().remove();																							
		
		$('#window').slideUp().remove();																							
	});
	
	return false;
}



$(window).bind('resize', function(){
    centralizaDiv('#window', 300);
		setFundoSize('#fundo')
});

