/*document.onreadystatechange = function(){
	//eliminando tags A no dos boxes se necessário
	for (var i=0; i<document.body.all.length; i++){
		if (document.body.all[i].id == "span_clean"){
			x += document.body.all[i].tagName + "\n";
			removeLinkFromText(document.body.all[i]);
		}
	}
	
}

function removeLinkFromText(oSpan){
	for (var i=0; i<oSpan.all.length; i++){
		x += oSpan.all[i].tagName + "\n";
		
		if (oSpan.all[i].tagName == "A"){
			oText = document.createElement("SPAN");
			oText.innerHTML = oSpan.all[i].innerHTML;
			
			try{oSpan.replaceChild(oText, oDiv.all[i]);}
			catch(x){alert("error on " + oText.innerHTML);}
		}
	}
	
	debug(x);
}

function debug(x){
	wnd = window.open("", "", "");
	wnd.document.write("[" + x + "]");
}
*/



/*document.onreadystatechange = function(){
	//eliminando tags A no texto de apresenação
	for (var i=0; i<document.body.all.length; i++){
		if (document.body.all[i].className == "app"){ alert(document.body.all[i].innerHTML);
			removeLinkFromText(document.body.all[i]); alert(document.body.all[i].innerHTML);
			return false
		}
	}
}

function removeLinkFromText(oDiv){
	for (var i=0; i<oDiv.all.length; i++){
		if (oDiv.all[i].tagName == "A" && oDiv.all[i].id != "app"){
			oLink = oDiv.all[i];
			oText = document.createElement("SPAN");
			oText.innerHTML = oLink.innerHTML ;
			
			try{
				oDiv.replaceChild(oText, oLink);
			}catch(x){
				alert("error on " + oText.innerHTML);
			}
		}
	}
}*/
function module_pagebox_correct_images()
{return;
//	$( 'a' ).click( function(){return false});
	$( 'td[class^=sitemais-modulos-pagina-box][class$=-inferior]' ).each(
			function ()
			{
				var td = $(this); 
				
				$(this).find('img').load(
						function(){
//							$(this).css( 'border', 'solid 1px red');
							$(this).css( 'display', 'inline');
							
							var name = td.attr('name')
							
							if ( name != null )
								var width_max = parseInt( $.rule( '.sitemais-modulos-pagina-vertical .' + td.attr('class') ).css( 'width' ) );
							
							else
								var width_max = parseInt( $.rule( '.' + td.attr('class') ).css( 'width' ) );
							
							if ( td.width() > width_max )
							{
								var final_width = width_max;
								var final_height = 
									parseInt(
										$(this).height() * width_max / $(this).width());
								$(this).css( 'width', final_width + 'px' );
								$(this).css( 'height', final_height + 'px' );
							}
						});
			});
//	$( 'a' ).click( function(){return true;});
}

function fixed_to_large_images()
{
  $( 'td[class^=sitemais-modulos-pagina-box][class$=-inferior]' ).each(
    function()
    {
      var box_width = $(this).width();
      
      if ( $.browser.msie ) 
      {
        var icon = $(this).find( '.icon' );
        var icon_width = 
          icon.length > 0 ? icon.width() : 0;
      }
      else
        var icon_width = 0;


      //alert( $(this).html() );
      //
      //alert(  $(this).width() + ' ' + $(this).outerWidth() + ' ' + $(this).innerWidth() + ' '  );
      //
      //
      //alert( $(this).find( 'img' ).length );

      $(this).find( 'img' ).each(
        function()
        {
          var image_width = $(this).width();
          var image_height = $(this).height();

          if ( image_width > box_width ) 
          {
            var image_new_width = box_width - icon_width;
            var image_new_height =
              Math.floor( image_height*image_new_width/image_width );

            $(this).css( 'width', image_new_width + 'px' );
            $(this).css( 'height', image_new_height + 'px' );

          }
          $(this).css( 'display', 'inline' );



          //alert( $(this).width() + ' ' + $(this).outerWidth()  + ' ' + $(this).innerWidth());
        });
    });

  //$('object').remove();
  //$('embed').remove();
}
$(window).load( fixed_to_large_images );





















