// Jquery init event
$(document).ready(function(){
   //hide_focus("#left_col .menu_block *");
	 handle_js_submit_form();

	 setEqHeightCols();

	 $(".js_alt_submit_btn").hide();
});


//
// This function hide focut
//
function hide_focus(elements2Listen4)
{
	$(elements2Listen4).focus( function() { this.hideFocus = true; $(this).css("-moz-outline-style", "none"); } );
}


//
// This function handle form submit buttons that are not inputs.
// Shows them, then submit parent form when clicked
//
function handle_js_submit_form()
{
	$(".js_submit_btn").css("display", "block").click( function() { $(this).parents("form").submit(); } );
}



//
// This function handle a menu:
// Listen for a click on specific elements (through css selectors)
// then toggle the related submenu
//
function handle_menu(Menu2Listen, menuItem)
{
	$(Menu2Listen + " " + menuItem).click( function() { $(this).parent(Menu2Listen).toggleClass("current"); } );
}

function sortNumber(a,b)
{
  return a - b
}

//
// This function make the content cols to have the same height
//
function setEqHeightCols()
{
	h1 = $("#left_col .welcome_block");
	h2 = $("#center_col .main_misc_block").eq($("#center_col .main_misc_block").length-1);
	h3 = $("#right_col .main_misc_block").eq($("#right_col .main_misc_block").length-1);


	if( h3.height() != null ) {
	  heights = new Array(h1.height(), h2.height(), h3.height());
  }
  else {
    heights = new Array(h1.height(), h2.height());
  }

  //alert(heights);

	heights.sort(sortNumber);
	heights.reverse();

	max_height = heights[0];

	if( h3.height() == max_height )
    h_today_block2 = $("#right_col #today_infos_block").height() + 10;
  else
    h_today_block2 = 0;

	// New height for the right col last block
	if ( $("#right_col").length != 0)
	{
		if ( $("#right_col #today_infos_block").length != 0 && h3.height()!=max_height ) h_today_block = $("#right_col #today_infos_block").height() + 10;
		else h_today_block = 0;

		//alert( h3.height()+'!='+max_height+'\n'+h_today_block);

		if ( $("#right_col #press_release_block").length == 0 ){
			new_h3 = max_height - $("#right_col .main_misc_block .top").eq($("#right_col .main_misc_block").length-1).height() - $("#right_col .main_misc_block .bottom").eq($("#center_col .main_misc_block").length-1).height() - h_today_block;
			$("#right_col .main_misc_block .content").eq($("#right_col .main_misc_block .content").length-1).height(new_h3+65);
		}else{
			new_h3 = max_height - $("#right_col .main_misc_block .top").eq($("#right_col .main_misc_block").length-1).height() - $("#right_col .main_misc_block .bottom").eq($("#center_col .main_misc_block").length-1).height() - h_today_block;
			$("#right_col .main_misc_block .content").eq($("#right_col .main_misc_block .content").length-1).height(new_h3);
		}
	}

  //alert( h3.height()+'=='+max_height+'\n'+h_today_block);

	// New height for the left col main block
	new_h1 = max_height - $("#left_col .welcome_block .top").height() - $("#left_col .welcome_block .bottom").height() + h_today_block2;
	$("#left_col .welcome_block .content").height(new_h1 + 10);

	// New height for the center col last block
	new_h2 = max_height - $("#center_col .main_misc_block .top").eq($("#center_col .main_misc_block").length-1).height() - $("#center_col .main_misc_block .bottom").eq($("#center_col .main_misc_block").length-1).height() + h_today_block2;
	$("#center_col .main_misc_block .content").height(new_h2);

	//alert( "max_height "+max_height+'\n'+"new_h1 "+new_h1+'\n'+"new_h2 "+new_h2+'\n'+"new_h3 "+new_h3 );
}