$(document).ready( function () {
	
	var img = 0 ;
	
	// simular max-width
	$('img').each( function () {
		url = $(this).attr('src')
		$(this).attr('id','img'+img)
		$.get(
			'wp-content/themes/cuducos_v8/imagesize.php',
			{ image_url: url, id: img },
			function(data) {
				if (data.indexOf('Image not found') < 0) {
					w = data.substr(0,data.indexOf('x'))
					h = data.substring(data.indexOf('x')+1,data.lastIndexOf('x'))
					id = data.substr(data.lastIndexOf('x')+1)
					if(w > 250) {
						h = (h/w) * 250
						$("#img"+id).attr('width','250')
						$("#img"+id).attr('height',h)
					}
				} else {
					//alert(data)
				}
			}
		 )
		img += 1
	})	
	
	// pega altura do div mais alto
	var maxHeight = 0
	$('.coluna').each( function () { if ($(this).height() > maxHeight) maxHeight = $(this).height() } )
	$('.coluna').css('height',(maxHeight+270)+'px')
	$('#geral').css('height',(maxHeight+260)+'px')
	
	// arruma largura do #geral
	var numCols = $('.coluna').size()+1
	var geralWidth = (numCols*280)
	$("#geral").css('width',geralWidth+"px")
	
	//arquivo
	$("#m").change( function () {
		location.href = $("#m :selected").attr('value')
	})
	
	// ajax
	$("#lastfm").ajaxStart( function () { fAjaxLoading() } )
	$("#flickr").ajaxStart( function () { fAjaxLoading() } )
	$("#lastfm").load('wp-content/themes/cuducos_v8/lastfm.php');
	$("#flickr").load('wp-content/themes/cuducos_v8/flickr.php');
	
})

function fAjaxLoading () {
	$("#lastfm").html('<p class="ajaxloading"><img src="wp-content/themes/cuducos_v8/ajaxloading.gif" alt"Carregando..." /><p>')
	$("#flickr").html('<p class="ajaxloading"><img src="wp-content/themes/cuducos_v8/ajaxloading.gif" alt"Carregando..." /><p>')
}