jQuery(document).ready( function()
{
 posicionarObjetos ();
 jQuery(window).resize(function(){ posicionarObjetos (0); });
 
 //efectoLogo ();
 
 efectoMenu ();

 ajustarAlturas (0);

});

//
// POSICIONAR Y DIMENSIONAR TODOS LOS OBJETOS
//
function posicionarObjetos ( tipo )
{
 var altura = jQuery(window).height();
 var alturaContent = jQuery('#content').height() +12 +12 +20; // top + bottom + footer
 
 if (altura >= alturaContent)
 {
  altura = (altura - alturaContent)/2; 
  jQuery('#footer').css('margin-bottom', altura+'px');
  jQuery('#top').css('margin-top', altura+'px');
 }
  else
 {
  jQuery('#footer').css('margin-bottom', '10px');
  jQuery('#top').css('margin-top', '0px');
 }
 
 if (tipo == 0)
  window.setTimeout( function(){posicionarObjetos (1);},500); 
}


//
// EFECTO DEL LOGO
//
function efectoLogo() {
	jQuery('#logo').hover (
	 function () { jQuery(this).attr('src',templateUrl+'/img/logo-hover.png'); },
	 function () { jQuery(this).attr('src',templateUrl+'/img/logo.png');} );	
}

//
// EFECTO DEL MENU
//
function efectoMenu ()
{
	jQuery('#menu div').hover (
	 function () { jQuery(this).animate({ height: 50, paddingTop: 40 },200); },
	 function () { jQuery(this).animate({ height: 30, paddingTop: 60 },200); } );
}

function ajustarAlturas (tipo)
{
 // Ajusta las alturas del sidebar y el contenido
 var alturaSidebar = jQuery('#sidebar').height();
 var alturaContenido = jQuery('#contenido').height();
 
 //alert(alturaContenido);
 
 alturaContenido = alturaContenido + (jQuery('.post h3').height()+17+3+5);
 
 if ( alturaContenido < alturaSidebar ) 
 {
  jQuery('#contenido').height (alturaSidebar-(jQuery('#sidebar h2').height()+18+3)+20+20);
 }
 else if ( alturaContenido > alturaSidebar )
 {
  // Obtenemos el offset necesario
  if(jQuery.browser.msie)
   incremento = 10;
  else
   var incremento = 30;

	 
  var nuevaAltura = alturaContenido-15;
  jQuery('#sidebar').height (nuevaAltura);
  
  //var nuevaAltura = nuevaAltura-(jQuery('#sidebar h2').height()+18+3)-(jQuery('.post h3').height()+17+3);
  //jQuery('#sidebar').height(nuevaAltura);
 } 

 if (tipo < 10)
   window.setTimeout( function(){ ajustarAlturas (tipo+1); },200);
}







