$(document).ready(	function(){
	//Main menu	
	$(".boutonNormal").hover(
		function () {			
			$(this).children('ul:first').css("visibility", "visible");
			//console.log($(this).children('ul:first').html());	
		},
		function () {
			$(this).children('ul:first').css("visibility","hidden");
			//console.log("out");
		}
	)
	
	//Vertical menu
	$(".verticalBoutonNormal").hover(
		function () {			
			$(this).children('ul:first').css("display", "block");
			//console.log($(this).children('ul:first').html());	
		},
		function () {
			$(this).children('ul:first').css("display","none");
			//console.log("out");
		}
	)
	
	//Move login box, show it
	if ($("#homeMenu").length > 0)
	{
		$("#lilogin").remove().appendTo("#homeMenu");
		//console.log("Am gasit homeMenu");
	}
	if ($("#menu").length > 0)
	{
		$("#lilogin").remove().appendTo("#menu");
		//console.log("Am gasit menu");
	}	
	$("#lilogin").css("display", "block");

	// -------------------------------------------------
	// NEWS REFACTORING SUPER-CODE
	// -------------------------------------------------
	
	var news_number = 0;
	var split_column = 0;
	var lx = 0;
	
	function exchangeNode( node1, node2 )
	{
		var tmpNode = $(".news-catmenu-NO").get(node1).innerHTML;
		$(".news-catmenu-NO").get(node1).innerHTML = $(".news-catmenu-NO").get(node2).innerHTML;
		$(".news-catmenu-NO").get(node2).innerHTML = tmpNode;
	}
		
	function isEven(value){
		if (value%2 == 0)
			return true;
		else
			return false;
	}
	
	// prepare right items
	function news_process_step1( middle )
	{
		var px = 1;
		var py = middle;
		
		while (px < py)
		{
			exchangeNode(px, py++);
			px += 2;
		}		
	}
	
	//news_number = $(".news-catmenu-NO").children();
	//alert(news_number);
	
	news_number = $(".news-catmenu-NO").size();
	split_column = Math.round(news_number / 2);

	// save left list
	var listArray = new Array();
	for (i=0; i < split_column; i++)
	{
		listArray[i] = $(".news-catmenu-NO").get(i).innerHTML;
	}

	news_process_step1( split_column );

	var cbx = 0;
	for (i=0; i < split_column; i++)
	{
		$(".news-catmenu-NO").get(cbx).innerHTML = listArray[i];
		cbx += 2;
	}
	
	var position = 0;
	for (i=0; i < news_number; i++)
	{
	//	console.log ("Stirea " + i);
	//console.log ("Continut " + $("#hidden_news").children().get(i).innerHTML  );
	//	console.log ("Continut " + $(".news-catmenu-NO").get(i).innerHTML  );
  		if (position == 0)
		{
			// left column
			var xx = "<li id='cat-left'>"+ $(".news-catmenu-NO").get(i).innerHTML +"</li>";
			$(".news-catmenu-NO").get(i).innerHTML = xx;		
			position = 1;
		} 
			else
		{
			// left column
			var xx = "<li id='cat-right'>"+ $(".news-catmenu-NO").get(i).innerHTML +"</li>";
			$(".news-catmenu-NO").get(i).innerHTML = xx;		
			position = 0;
		} 

	}	
	// change the selection text
	if ( $("div.news-catmenu").get(0) )
	{
		var content = $("div.news-catmenu").get(0).innerHTML;
		// IE 6.0 workaround
		var nMax = Math.max( content.indexOf("</A>"), content.indexOf("</a>") );
		$("div.news-catmenu").get(0).innerHTML = "<div class='news-header-text'>Choose the news by countries: </div>"  + content.substr( nMax + 4, content.length);
	}
	
	// -------------------------------------------------------
	// NEWS LIST REFACTORING SUPERCODE
	// -------------------------------------------------------
	
  if ( $("div.news-toberemoved").get(0) ) 
	{
		var content = $("div.news-toberemoved").get(0).innerHTML;
		var title = $("h1.news-list-category").get(0).innerHTML;
		var newcontent = title.substr(0, title.length - 2) + ' '+ content;
		$("div.news-toberemoved").empty();
		$("h1.news-list-category").get(0).innerHTML = newcontent;
		$("h1.news-list-category").css("text-transform", "uppercase");
	} else
	{
    	if ( $("h1.news-list-category").get(0) ) 
        { 
          $("h1.news-list-category").get(0).innerHTML = "";
        }
  }
	
	//Centering divs...
	//bwidth = $("body").width();
	//pwidth = $("div#page").width();
	//console.log("body width: "+bwidth);
	//console.log("#page width: "+pwidth);
	//left = (bwidth - pwidth)/2;
	//console.log("left: "+left);
	//if ($("div#page").length > 0)
	//{
		//$("div#page").css("position", "absolute");
		//$("div#page").css("left", left);
	//}
})