// JavaScript Document
// exibe o erro na página em um alert
function error(msg, url, line){
	//return true;
	alert(
		"Erro na página \n\n"	+
		"Error:	" + msg + "\n"	+
		"URL:	" + url + "\n"	+
		"Line:	" + line
	);
}
//window.onerror = error;

browser=navigator.appName;
//alert(browser);
//----------------------------------------------------------------------------------------------------
//atacha o flash em uma div
//                   1obr 2obr   3obr    4opc	 5opc	6opc   7opc   	8opc
function attachFlash(url, width, height, target, wmode, scale, quality, vars){
	var content; identity = url.split("."); identity = identity[0]; 
	if(!target) { document.write("<div id=\"id_"+ identity +"\"></div>"); target = "id_"+ identity;}
	if(!quality)quality	= "best";
	target = document.getElementById(target);
	content =  "<object id=\"" + identity + "\" width=\"" + width + "\" height=\"" + height + "\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\">";
  content += "<param name=\"allowScriptAccess\" value=\"sameDomain\" />";
	content +=  "<param 	name=\"movie\" value=\"" + url + "?" + vars +"\">";
  content +=  "<param 		name=\"quality\" value=\"" + quality + "\">";
	content +=  "<param 	name=\"wmode\" value=\"" + wmode + "\" /> ";
	content +=  "<param 	name=\"bgcolor\" value=\"#ffffff\" /> ";
  content +=  "<embed 		name=\"" + identity + "\" src=\"" + url + "?" + vars +"\"  width=\"" + width + "\" height=\"" + height + "\" wmode=\"" + wmode + "\" scale=\"" + scale + "\" quality=\"" + quality + "\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\"></embed>";
	content +=  "</object>";
	target.innerHTML = content;
}
//----------------------------------------------------------------------------------------------------
function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}
//----------------------------------------------------------------------------------------------------
function setScrollXY(x, y) {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    if(y >= 1) window.pageYOffset = y;
    if(x >= 1) window.pageXOffset = x;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
     if(y >= 1) document.body.scrollTop = y;
   	 if(x >= 1) document.body.scrollLeft = x;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    if(y >= 1) document.documentElement.scrollTop = y;
    if(x >= 1) document.documentElement.scrollLeft = x;
  }
}
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////
var indice_atual = -1;
var indice_banner = 0;
var indice_banner_obj = "";
var banner_intervalo = "";
clearInterval(banner_intervalo);
function banner_dinamico(){
	setTimeout(function(){
		$('.banner_dinamico').find('.banner_thumbs').find('li').each(function(i){
			$(this).css({'marginLeft':-(100+((i+1)*20))+'px'});
			$(this).bind('mouseup', function(e){
						//alert(000000000);
					if(indice_banner_obj != i){
						indice_banner_obj = i;
						indice_banner = i;
						//alert(11111111111111);
						$('.banner_dinamico').find('.banner_paineis').find('li').not("li:eq("+indice_banner+")").animate({'top':(0)+'px', 'marginLeft':(-520)+'px'},{duration: 540, easing:"easeInOutCubic"});
						$('.banner_dinamico').find('.banner_paineis').find('li:eq('+indice_banner+')').stop().css({'marginLeft':(520)+'px'}).animate({ 'marginLeft':'-'+(0)+'px'},{duration: 480, easing:"easeInOutCubic"});
						
						$('.banner_dinamico').find('.banner_thumbs').find('li').stop().animate({ opacity:.85 },{duration: 180, easing:"easeOutCubic"});
						$('.banner_dinamico').find('.banner_thumbs').find('li:eq('+indice_banner+')').stop().animate({ opacity:1 },{duration: 180, easing:"easeOutCubic"});
						$('.banner_dinamico').find('.banner_painel').find('.titulo').hide(100);
						$('.banner_dinamico').find('.banner_painel_'+i).find('.titulo').show(250);
						clearInterval(banner_intervalo);
						inicia_banner_troca();
					}
			});		
			$(this).stop().animate({ opacity:.85, "marginLeft":"0px" },{duration: 420, easing:"easeOutCubic", complete:function(p){
				$(this).bind('mouseover', function(e){
					$(this).find('.banner_preview').show();
					$(this).stop().animate({ opacity:1 },{duration: 80, easing:"easeInCubic"});
				});	
				$(this).bind('mouseout', function(e){					
					$(this).find('.banner_preview').hide();
					if(i != indice_banner)  $(this).stop().animate({ opacity:.85 },{duration: 80, easing:"easeOutCubic"}); });																						  
			} });
		});
		$('.banner_dinamico > .banner_thumbs').show();
		$('.banner_dinamico > .back_titulo').stop().animate({ opacity:.85 },{duration: 220, easing:"easeOutCubic", complete:function(p){  } });
		$('.banner_dinamico').find('.banner_painel_0').find('.titulo').show(300);	
	}, 300)
	/*
	$('.banner_dinamico').find('.banner_paineis').find('li').each(function(i){
		$(this).css({'marginTop':-450+((i+1)*10)+'px'});	
		$(this).stop().animate({ opacity:1, "marginTop":"0px" },{duration: 420, easing:"easeOutCubic", complete:function(p){  } });
	});*/
//	$('.banner_dinamico').find('.banner_paineis').css({'marginTop':-(($('.banner_dinamico').find('.banner_paineis').find('li').size()+1)*268)+'px'});
	$('.banner_dinamico').find('.banner_paineis').stop().animate({ opacity:1, "marginTop":"0px" },{duration: 1020, easing:"easeOutCubic", complete:function(p){  } });	
		$('.banner_dinamico').find('.banner_thumbs').find('li:eq('+indice_banner+')').stop().animate({ opacity:1 },{duration: 180, easing:"easeOutCubic"});
	$('.banner_dinamico > img').show();
	inicia_banner_troca();
}
function inicia_banner_troca(){
	banner_intervalo = setInterval(function(e){
		if(indice_banner >= $('.banner_dinamico').find('.banner_thumbs').find('li').size()) indice_banner = -1;
		indice_banner++;
		//indice_atual = -1;
		$('.banner_dinamico').find('.banner_thumbs').find('li').stop().animate({ opacity:.85 },{duration: 180, easing:"easeOutCubic"});
		$('.banner_dinamico').find('.banner_thumbs').find('li:eq('+indice_banner+')').stop().animate({ opacity:1 },{duration: 180, easing:"easeOutCubic"});
		$('.banner_dinamico').find('.banner_thumbs').find('li:eq('+indice_banner+')').mouseup();
		//alert($('.banner_dinamico').find('.banner_thumbs').find('li:eq('+indice_banner+')'));
	}, 5000);
}
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////
//----------------------------------------------------------------------------------------------------
function loadAjax($pag, $box, $dados){
	window.scrollBy(0,0);
	$.ajax({
		type: "GET",
		url: $pag,      
		global: false,
		data: $dados,
		dataType: "html",
	  success: function(content){
		//alert( ">>>>>>>>>>>>>>>>>>: " + content );
		$($box).html(content);
		// $("#box_Right").html(content);
		}
	});
}
//----------------------------------------------------------------------------------------------------
function defaultMsg(obj, defaultVal){
	if(obj.value == defaultVal) obj.value = '';
	obj.defaultVal = defaultVal;
	obj.onblur = function(){
		if(!this.value) this.value = this.defaultVal;
	}
}
//----------------------------------------------------------------------------------------------------
function aplicaEventos(){
	$tds = $("#TABELA_MES").find("td");
	$tds.each(function(i){
		var $curobj	=	$(this);
		this._heightI	=	$(this).find('ul').outerHeight();
		$sub =  $(this).children("ul").hide();
		$sub.css({ display:"none",opacity: 0});
		$curobj.hover(
			function(p){
				$sub =  $(this).parent().find("ul");
				$sub =  $(this).children("ul");
				this.left = $curobj.offset().left + 28;
				this.top = $curobj.offset().top - 10;
				//alert($sub.css("opacity"));
				if(1 == 1){
					$sub.css({left:this.left+"px",top:this.top+"px", height: 0, padding:5, display:'block', visibility:'visible',opacity: 0}).stop().animate({ 
								height:this._heightI+"px",
								opacity: 1
								}, {duration: 350, easing:"easeOutSine", complete:function(p){ }}  );
				}
				else{
					$sub.stop().animate({ 
								height:0+"px",
								opacity: 0
								}, {duration: 350, easing:"easeOutSine", complete:function(p){ }}  );
				}
			},
			function(){
				
				$sub =  $(this).children("ul").stop().hide();
				/*$sub.stop().animate({ 
							height:0, 
							padding:0,
							opacity:0.5
							}, {duration: 100, easing:"easeOutSine", complete:function(p){ $sub.css({display:'none', visibility:'hidden'}) }}  );
			*/}
			
		);

		$sub.hover(
			function(p){ },
			function(p){
				$sub =  $(this).stop();
				$sub.stop().animate({ 
							height:0,
							padding:0,
							opacity: 1
							}, {duration: 100, easing:"easeOutSine", complete:function(p){  $sub.css({display:'none', visibility:'hidden'}) }} );
			}
		);
	});
}
//----------------------------------------------------------------------------------------------------
var genMenu={
velocidade: {inicial:96, final:360},
	criaMenu:function(structure){
		jQuery(document).ready(function($){
			var leftDefault = (structure == "MENU")? 0 : 0;
			var $mainmenu	=	$("#"+structure+">ul");
			var $headers	=	$mainmenu.find("div").parent();
			$headers.each(function(i){
				var $curobj	=	$(this);
				var $subul	=	$(this).find('div:eq(0)');
				this.quantidade	= 	$(this).find('div').size();
				this.largura = (150 * this.quantidade);
				
				
				this._dimensions	=	{w:this.offsetWidth, h:this.offsetHeight, subulw:$subul.outerWidth(), subulh:$subul.outerHeight()};
				this.isheader	=	$curobj.parents("ul").length==1	? true : false;			
				if(!this.isheader){
					$curobj.css({'zindex':'5','backgroundImage':'url('+ PATH +'img/bullet2.gif)' });
					if((($curobj.offset().left+303)>$(window).width())){$curobj.css({'z-index':'555','backgroundImage':'url('+ PATH +'img/bullet2.gif)' });}
				}

				this._widthI	=	$curobj.children("div").outerWidth();
			
				this._offsets	=	{left:$(this).offset().left, top:($(this).offset().top-40)};	
				
				var menuleft	=	this.isheader? ($curobj.offset().left +leftDefault) : (172);
				var $targetul	=	$curobj.children("div");
				////////////////////////////////////////////////////////////////if (resposta.is(':visible')) {
				$curobj.hover(
					function(e){
						if(this.isheader) $(this).css({'backgroundColor':'#7bb622'});
						var $targetul	=	$(this).children("div").hide();
						this._offsets	=	{left:$(this).offset().left, top:($(this).offset().top-40)};
						var menuleft	=	this.isheader? (0) : (172);
						menuleft			=	((this._offsets.left+303)>$(window).width())? (this.isheader? menuleft : -(172)) : menuleft;
						
						if(!this.isheader){ if((($curobj.offset().left+303)>$(window).width())){$curobj.css({'backgroundImage':'url('+ PATH +'img/bullet2.gif)' });} }
						
						if(this.isheader) $velo = 0;
						else { $velo = 100; if(browser == 'Microsoft Internet Explorer') $velo = 0;  }
						$targetul.css({left:menuleft+"px"}).stop(true, true).show($velo);	

					},
					function(e){
						if(this.isheader) $(this).css({'backgroundColor':'#68a3be'}); 
						var $targetul	=	$(this).children("div:eq(0)");
						
						if(browser == 'Microsoft Internet Explorer') $velo = 150;
						else $velo = 360;
						$targetul.stop(true, true).hide($velo);		

					}
				)
			}) 
			$mainmenu.find("div").css({display:'none', visibility:'visible'});
		})
	}
}

// aplicando menu
genMenu.criaMenu("MENU");
//----------------------------------------------------------------------------------------------------
function preparaMenu(){
				// aplicando menu
				//genMenu.criaMenu("LISTA_CATEGORIAS");
				$listas = $("#MENU_VERTICAL").find('p');
				$listas.each(function(i){
					$bt = $(this);
				//	if($bt.find('ul')){ $bt.css({ "cursor":"pointer" }); }
					$bt.unbind("mouseup");
					//$bt.next('div').removeClass("aberto");
					//$bt.next('div').addClass("normal");
					//$bt.mouseover(function(e){ alert($(this).next('div')); })
					$bt.bind("mouseup", function(e){
							$listaInt = $(this).next('div');
							if($listaInt){
								//alert($listaInt.height());
							//	if($listaInt.is(':hidden')){ $(this).parent().parent().find('div').slideUp('slow', function(f){  $(this).removeClass("aberto"); });
								if($listaInt.is(':hidden')){ $(this).parent().parent().find('div').slideUp('slow', function(f){  }); }								
								//alert($listaInt);
								//$listaInt.removeClass("aberto");
								$listaInt.show('slow');
								//else{ if($listaInt.stop().slideUp('slow'))	$listaInt.stop().slideUp('slow', function(r){ $listaInt.css({ "display":"none" }); });		}
							}
					});
				})			
	}
function prepara_busca(){
	sairBusca = "";
	$("#BUSCA").bind("focus", function(e){ defaultMsg(this, 'Buscar:') }) ;
	$("#BUSCA").bind("keydown", function(e){ defaultMsg(this, 'Buscar:') }) ;
	$("#BUSCA").bind("keyup", function(e){ 
	if($(this).attr('value').length >= 2){
		//clearTimeout(sairBusca);
		loadAjax(PATH + "_busca_box.php", "#BUSCA_REF", "busca="+$(this).attr('value'));
		//$("#BUSCA_REF").slideDown('normal');
		//sairBusca = setTimeOut(function(p){ $("#BUSCA_REF").slideUp('normal'); },5000);
	}
	else{
		$("#BUSCA_REF").slideUp('normal');
	}
	}) ;	
}
//----------------------------------------------------------------------------------------------------
function prepara_calendario(){
			if($("#CALENDARIO2")){
				$("#TABELA_MES").css({opacity: 0}).html("<img src=\" "+ PATH +"img/loader.gif\" class=\"loader\">");$("#TABELA_MES").animate({ opacity: 1  },{duration: 50, easing:"easeOutSine"}) ;
				$.ajax({
				   type: "POST",
				   url: "_home.calendario.php",      
				   global: false,
				   data: "name=John&location=Boston",
				   dataType: "html",
				   success: function(content){
					 //alert( ">>>>>>>>>>>>>>>>>>: " + content );
					 $("#TABELA_MES").html(content);
				  	$("#TABELA_MES").css({opacity: 0}).stop().animate({ opacity: 1  },{duration: 180, easing:"easeOutSine", complete:function(p){ aplicaEventos(); } });
					// aplicaEventos();
				   }
				 });	
			}
}
//----------------------------------------------------------------------------------------------------
jQuery(document).ready(function($){
		//	prepara_calendario();
		if($('#COMUNICADO').length >= 1){
			c_atual = 0; 
			setInterval(function(){
				c_atual++;
				if(c_atual >= 2) c_atual = 0;
				$("#COMUNICADO").find('ul').animate({ 
					"margin-top": (-c_atual*60)+"px"
				}, {duration: 350, easing:"easeOutSine", complete:function(p){ }}  );;
			}, 4500);
		}
		if($('.banner_dinamico').length >= 1){
				banner_dinamico();	
			}
			if($("#CALENDARIO_VOLTAR")){
				$("#CALENDARIO_VOLTAR").bind("mouseup keyup", function(e){
					$("#TABELA_MES").stop().animate(
											{ opacity: 0  },
											{duration: 100, easing:"easeOutSine", complete:function(p){
											$("#TABELA_MES").html("<img src=\""+ PATH +"img/loader.gif\" class=\"loader\">");$("#TABELA_MES").animate({ opacity: 1  },{duration: 50, easing:"easeOutSine"}) }});
					$.ajax({
					   type: "GET",
					   url: "_home.calendario.php",      
					   global: false,
					   data: "data="+document.data_ant,
					   dataType: "html",
					   success: function(content){
						 	$("#TABELA_MES").animate({ opacity: 0  },{duration: 50, easing:"easeOutSine" });
							setTimeout(function(){
								$("#TABELA_MES").html(content);
								$("#TABELA_MES").css({opacity: 0 }).stop().animate({ opacity: 1  },{duration: 180, easing:"easeOutSine", complete:function(p){ aplicaEventos(); } });
							},50 );
						}
					 });
			   	});
				$("#CALENDARIO_AVANCAR").bind("mouseup keyup", function(e){
					$("#TABELA_MES").stop().animate(
											{ opacity: 0  },
											{duration: 100, easing:"easeOutSine", complete:function(p){
											$("#TABELA_MES").html("<img src=\""+ PATH +"img/loader.gif\" class=\"loader\">");$("#TABELA_MES").animate({ opacity: 1  },{duration: 50, easing:"easeOutSine"}) }});
					$.ajax({
					   type: "GET",
					   url: "_home.calendario.php",      
					   global: false,
					   data: "data="+document.data_prox,
					   dataType: "html",
					   success: function(content){
						 //alert( ">>>>>>>>>>>>>>>>>>: " + content );
						 $("#TABELA_MES").animate({ opacity: 0  },{duration: 50, easing:"easeOutSine" });
						setTimeout(function(){
							$("#TABELA_MES").html(content);
							$("#TABELA_MES").css({opacity: 0 }).stop().animate({ opacity: 1  },{duration: 180, easing:"easeOutSine", complete:function(p){ aplicaEventos(); } });
						},50 );
					   }
					 });
			   	});
			}
			if($("#MENU_VERTICAL")){
				preparaMenu();		
			}
			if($("#imagemPrincipal")){
				$('#imagemPrincipal').lightBox({
					overlayBgColor: '#222',
					overlayOpacity: 0.7,
					imageLoading: 	''+ PATH +'img/loader.gif',
					imageBtnClose: 	''+ PATH +'img/lightbox-btn-close.gif',
					imageBtnPrev: 	''+ PATH +'img/lightbox-btn-prev.gif',
					imageBtnNext: 	''+ PATH +'img/lightbox-btn-next.gif',
					containerResizeSpeed: 390,
					txtImage: 'Imagem',
					txtOf: 'de'
				   });
				$(function() {
					//$('#imagemPrincipal').lightBox();
				});
			}
			
			if($("#GALERIA_1").length > 0){
				$('#GALERIA_1').find('li').find('a').lightBox({
					overlayBgColor: '#222',
					overlayOpacity: 0.7,
					imageLoading: 	''+ PATH +'img/loader.gif',
					imageBtnClose: 	''+ PATH +'img/lightbox-btn-close.gif',
					imageBtnPrev: 	''+ PATH +'img/lightbox-btn-prev.gif',
					imageBtnNext: 	''+ PATH +'img/lightbox-btn-next.gif',
					containerResizeSpeed: 390,
					txtImage: 'Imagem',
					txtOf: 'de'
				   });
				$(function() {
					//$('#imagemPrincipal').lightBox();
				});
			}
			
			
			if($(".lista_items")){
				$(".lista_items").find("h3").bind("mouseup", function(ev){ 
					if(!this.ref) this.ref = "none";
					$descricao = $(this).next("ul");
					if(this.ref == "block"){ $descricao.hide('fast'); this.ref = "none"; }
					else {$descricao.slideDown('fast'); this.ref = "block"}
				});
				// -------------------------------------------------------
				$(".lista_items").find("h4").bind("mouseup", function(ev){ 
					if(!this.ref) this.ref = "none";
					$descricao = $(this).next("ul");
					if(this.ref == "block"){ $descricao.hide('fast'); this.ref = "none"; }
					else {$descricao.slideDown('fast'); this.ref = "block"}
				});
				// -------------------------------------------------------
				$(".lista_items").find("h5").bind("mouseup", function(ev){ 
					if(!this.ref) this.ref = "none";
					$descricao = $(this).next("ul");
					
					if(this.ref == "block"){ $descricao.hide('fast'); this.ref = "none"; }
					else {$descricao.slideDown('fast'); this.ref = "block"}
				});
			}
});
