function getMaxIndex(img){
	var max = 0;
	var maxImg;
	img.each(function(e){
		if(jQuery(this).css('z-index') > max){
			max = jQuery(this).css('z-index');
			maxImg = jQuery(this);
		}
	});
	return maxImg;
}

jQuery(function(){
	//add core
	jQuery.fn.exists = function(){return jQuery(this).length>0;}

	// add first and last to list items
	jQuery('ul li:first-child').addClass('first');	
	jQuery('ul li:last-child').addClass('last');
	
	
	jQuery('img.foto').each(function(){
		var text = jQuery(this).attr('title');
		jQuery(this).removeAttr('title');
		
		var style = jQuery(this).attr('style');
		jQuery(this).removeAttr('style');
		
		var img = jQuery('<div>').append(jQuery(this).clone()).html();
		jQuery(this).replaceWith('<div class="foto-content" style="'+style+'">'+img+'<p>'+text+'</p></div>');
	
	});
	
	/* footer sitemap */
/*	jQuery('#footer').prepend('<h3>Mapa do Site</h3>'); */

	/* photos */
	
function randOrd(){
  return (Math.round(Math.random())-0.5);
}
	
	
	if(jQuery('.home .fotos').exists()){
		var min = '218px';
		var max = '238px';
		var img = jQuery('.fotos img');
		
		img.removeAttr('width');
		img.removeAttr('height');
		
		img.css({'width':min});
		img.css({'position':'absolute'});		
		
		img.sort(randOrd);
		
		
		jQuery(img[3]).css({'left': '0', 'z-index':5});
		jQuery(img[2]).css({'left': '140px','z-index':4});
		jQuery(img[1]).css({'left': '320px','top':'2px','z-index':3});
		jQuery(img[0]).css({'left': '420px','top':'6px','z-index':2});		
		
		for(var i=4;i < img.length;i++){
			jQuery(img[i]).remove();
		}
		
		/* img.hover(function(){
			var i = jQuery(this).css('z-index');
			var maxImg = getMaxIndex(img);
			var m = maxImg.css('z-index');
			if(i < m){
				jQuery(this).css({'z-index': m});
				maxImg.css({'z-index': m-1});
			}
			jQuery(this).animate({'width':max},200)
		}, function(){
			jQuery(this).animate({'width': min},200)
		}); */
	}

	/* gallery */
/*	jQuery('.imageSlider li').append('<div class="corner-tl corner"></div><div class="corner-tr corner"></div><div class="corner-bl corner"></div><div class="corner-br corner"></div>'); */

});


