var J = jQuery.noConflict();

J(document).ready(function(){
	
	//Pseudo Classes
	J('#Menu > ul > li:last').css('background', 'none');
	J('#MenuRodape ul > li:last').addClass('last');
	
	//Menu ul width
	var wUl = 0;
	J('#Menu > ul > li').each(function(){
		wUl+=J(this).outerWidth(true);
	});
	J('#Menu > ul').width(wUl+15);
	
	J('#Menu > ul > li:has(ul)').hover(function(){
		J('ul:first', this).slideDown();
	},function(){
		J('ul:first', this).slideUp();
	});
	
	//Align Paginacao
	var mLeftPag = (J('.Paginacao').parent().width()-J('.Paginacao').outerWidth(true))/2;
	J('.Paginacao').css('right', mLeftPag+'px');
	
	//BlocoDir
	J('.BlocoDir .Conteudo').append('<div class="clear"></div>');
	J('.BlocoDir').append('<div class="footer"></div>');
	/*J('.BlocoDir h3').each(function(){
		var title = J(this).text();
		if (title.length >17) {
			J(this).addClass('bigTitle');
		}
	});*/
	
	//PNGFix
	if (J.browser.version<=6){
		DD_belatedPNG.fix('#Menu ul li, #Menu ul li a, .bgEstrelas, #Corpo, #Rodape, #Rodape .txtRodape, #Rodape .txtRodape .borderRight, #Rodape .marcaRodape, .BlocoDir h3, .BlocoDir .Conteudo, .BlocoDir .footer, #Destaques, .BlocoEsq, .BlocoEsq .Conteudo, .BlocoEsq .footer');
	}
	
	//FIX Image Destaques
	J('#Destaques .DstItem').each(function(){
		J('img:first', this).clone().css({'width':'280px', 'height':'230px', 'float':'left'}).prependTo(this);
		J('img:not(:first)', this).remove();
	});
	
	//Destaques
    J('#Destaques').ListaDestaques();
	
	//Lightbox
	jLightBox();
	
	//TypeFace
	_typeface_js.initialize();
	
});

//Call Lightbox
function jLightBox () {
	J('a[rel^=lightbox]').lightBox({
		imageLoading: 	URLTPL+'images/lightbox-ico-loading.gif',
		imageBtnPrev: 	URLTPL+'images/lightbox-btn-prev.gif',
		imageBtnNext:	URLTPL+'images/lightbox-btn-next.gif',
		imageBtnClose:	URLTPL+'images/lightbox-btn-close.gif',
		imageBlank:		URLTPL+'images/lightbox-blank.gif'
	});
}

//XML Gallery
	function showGallery (xmlPath, max_images, content_tag){
		J(content_tag).html('<p>Carregando galeria...</p>');
		J.ajax({
			type: "GET",
			url: xmlPath,
			dataType: "xml",
			success: function(xml) {
			
				var htmlContent = "<ul class=\"galeria\">";
				
		 		J(xml).find('simpleviewergallery').each(function(){
					var thumbFolder 	= J(this).attr('thumbPath');
					var bigFolder 		= J(this).attr('imagePath');
					var n				= 0;
					J(this).find('image').each(function(){
						n++;
						if (n<=max_images) {
							var fileName	= J(this).find('filename').text();
							var caption		= J(this).find('caption').text();
							
							htmlContent += "<li><a href=\""+bigFolder+fileName+"\" title=\""+caption+"\" rel=\"lightbox[lateral]\"><img src=\""+thumbFolder+fileName+"\" width=\"74\" width=\"74\" /></a></li>";
						}
					});
				});
				
				htmlContent += "</ul>";
				
				J(content_tag).html(htmlContent);
				
				jLightBox(); //Refresh lightbox
			},
			error: function () {
				J(content_tag).html('<p>Ocorreu um erro ao carregar a galeria.</p>');
			}
		});
	}