google.setOnLoadCallback(function() {
	jQuery(function($) {
		$.getScript(jsPath+'jquery.metadata.js',function(){ //1
		$.getScript(jsPath+'scrollable.js',function(){ //2
		$.getScript(jsPath+'autoscroll.js',function(){ //3
			//Chama o main
			main();
		}); //3
		}); //2
		}); //1
	});
});

function main() {
	$ = jQuery.noConflict();
	$('#newsletter input[type=submit]').addClass("btEnviar");	
	$('input[type=checkbox]').css("margin","0");

	$('.vcard img').addClass('avatar avatar-40 photo').width(40).height(40);

	/* Colorbox para todos os links de imagem e youtube */
//	$('a[href$="jpg"]').each(function(){
//		$(this).attr('title',$(this).next().html())
//	});
//	$('a[href$="jpg"]').attr('title',$('a[href$="jpg"]').next().html())
//	$('a[href$="jpg"]').colorbox({rel:'group1'});
//	$('a[href*="youtube.com"]').colorbox({iframe:true, innerWidth:425, innerHeight:344});
	/** :hover effect on main menu**/
	$('#menu-topo li:has("ul")')
		.addClass("parent-item")
		.mouseover( function(){ $(this).children('ul').css({ 'display' : 'block' }); })
		.mouseout( function(){ $(this).children('ul').css({ 'display' : 'none' }); });
	
	/** Tooltip **/
	$('#colunistas li>a, #eventos li>a').mouseenter(function() {
		$(this).next().stop(true,true).delay(1000).fadeIn('fast');
	}).mouseleave(function() {
		$(this).next().stop(true,true).fadeOut('fast');
	});
	/** Slideshow **/
	$(".scrollable").scrollable({
		size: 1,
		circular:true
	}).autoscroll(3000);

//	$(".pictures .big .slider").width($(".pictures .big .slider .gallery-item").length * $(".pictures .big .slider .gallery-item").width());
//	$(".pictures .big").scrollable({
//		items: '.slider',
//		size: 1
//	});

//	scrollGalerias = $(".pictures .big").data("scrollable");

	$(".gallery .mask a").unbind('click').click(function(){
		var objThis = this
		$('.pictures .big .slider .gallery-item').fadeOut('normal',function(){
			$(".pictures .big .slider .gallery-item .gallery-icon img").attr('src', $(objThis).find('img').metadata().image).load(function(){
				$('.pictures .big .slider .gallery-caption').html($(objThis).find('img').metadata().legenda);
				$('.pictures .big .slider .gallery-creditos').html($(objThis).find('img').metadata().creditos);
				$('.pictures .big .slider .gallery-item').fadeIn('normal');
			});
		});
		//scrollGalerias.seekTo($(".gallery .mask a").index(this))
		return false;
	});
	
	$(".gallery .mask").scrollable({
		items: '.slider',
		size: 3,
		onBeforeSeek: function(a,b){
			try{
				a = $(".gallery .mask").data("scrollable");
				if (($(".gallery .mask .slider .gallery-item").length-a.getConf().size+1) == b){
					return false;
				}
			}catch(e){}
		}
	});
	
	$('.pictures .prev').click(function(){
		indice = $(".gallery .mask img").index($(".gallery .mask a img[class*='" + $(".pictures .big .slider .gallery-item .gallery-icon img").attr('src') + "']"));
		$(".gallery .mask").data("scrollable").prev();
		$(".gallery .mask a:eq(" + (indice - 1) + ")").click();
	});

	$('.pictures .next').click(function(){
		indice = $(".gallery .mask img").index($(".gallery .mask a img[class*='" + $(".pictures .big .slider .gallery-item .gallery-icon img").attr('src') + "']"));
		$(".gallery .mask").data("scrollable").next();
		$(".gallery .mask a:eq(" + (indice + 1) + ")").click();
	});

	$(".capas").scrollable({
		items: '.slider',
		size: 1,
		circular: true
	}).autoscroll(3000);
}// Fim do main
