var mouseOverEvents = 0;
var menuOld = '';
var menuNew = '';
var menuBoxOld = '';
var menuBoxNew = '';
var newsOld = '';
var newsNew = '';
var testiShow = 0;
var hiding = new Array();
var current_page_id = ''
var newsHover = '';
var newsTime = null;
var newsDisplayed = '';
var newsTimer = 0;

var home_left_side_tab = 'tab_Technology';
var home_left_side_newtab = '';
var home_left_side_timer = 0;

var hide_after_2_seconds_id = '';
var hide_after_2_seconds_timer = 0;

if(typeof(first_news) != 'undefined')
{
	newsHover = first_news;
	var new_elem = document.getElementById('mark_' + newsHover);
	if(new_elem != null) {
		new_elem.style.backgroundImage = 'url(images/listILGreen_small_active.gif)';
		$("#"+newsHover).css("font-weight", "bold");
	}
	newsDisplayed = newsHover;
}

var win=null;
function NewWindow(mypage,myname,w,h,scroll,pos)
{
if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
win=window.open(mypage,myname,settings);
}

function HideAfter2Seconds()
{
	//alert('a');
	
	if(hide_after_2_seconds_id != ''){
		hide_after_2_seconds_timer--;
		if(hide_after_2_seconds_timer == 0){
			$("#"+hide_after_2_seconds_id ).hide("slide", { direction: "up" }, 500);
			menuOld  = '';
			menuNew = '';
			hide_after_2_seconds_id = '';
		}
	}
	
	setTimeout("HideAfter2Seconds()", 100);
}
setTimeout('HideAfter2Seconds()', 100);

$(document).ready(function(){
	

	function HidingDone(id)
	{
		//alert(id);
		for(var i=0;i<hiding.length;i++)
			if(hiding[i] == id){
				hiding.splice(i, 1);
				return;
			}
	}	

	

	$("#sfMenu a").mousemove(function(e) {
		// this is for skip the first mouse move when a page is loaded
		mouseOverEvents++;
		if(mouseOverEvents < 4 ){
			return;
		}
		if (document.getElementById("selectedMenu")!=null){
			current_page_id = document.getElementById("selectedMenu").value;
		}		
		if(menuNew == '' || $(this).attr("id") != menuOld){
			// check if the element is in the hiding list
			// if found, ignore this event, else, show it
			for(var i=0;i<hiding.length;i++)
				if(hiding[i] == $(this).attr("id")+"_logo"){
					return;
				}
			// show current selected menu
			if (current_page_id != $(this).attr("id"))
				$("#"+$(this).attr("id")+"_logo").show("slide", { direction: "up" }, 500);
		}	
		menuNew = $(this).attr("id");

		if (menuOld != menuNew) {
			// hide previous selected menu
			//alert('a');
			var tmp = menuOld+"_logo";
			if (current_page_id != menuOld){
				hiding.push(tmp);
				$("#"+menuOld+"_logo").hide("slide", { direction: "up" }, 500, function(){ HidingDone(tmp); });	
			}
			hide_after_2_seconds_id = '';
			menuOld  = '';
		}
		var xId =menuOld;	
		menuOld = menuNew;

		// display right part of the page
		menuBoxNew = $(this).attr("id") + '_logo';
		if(menuBoxNew != menuBoxOld){		// EIS
			$("#right_"+menuBoxNew).show("slide", { direction: "right" }, 500);
			$("#right_"+menuBoxOld).hide("slide", { direction: "right" }, 500);
			menuBoxOld = menuBoxNew;
		}	
	});

	$("#sfMenu .dropLogo").mouseout(function(e) {
		menuBoxNew = $(this).attr("id");
		var right_panel = document.getElementById('right_' + menuBoxNew);
		if (document.getElementById("selectedMenu")!=null){
			current_page_id = document.getElementById("selectedMenu").value;
		}		

		// test if exists the right pannel
		if(right_panel == null){
			// if not exists, we are not on the main page, so hide the logo
			var tmp = menuBoxNew;
			if (current_page_id != $(this).attr("id")){
				hiding.push(tmp);
				$("#"+menuBoxNew).hide("slide", { direction: "up" }, 500, function(){ HidingDone(tmp); });
			}
			menuOld  = '';
			menuNew = '';
		}else{
			hide_after_2_seconds_timer = 20;
			hide_after_2_seconds_id = menuBoxNew;
		}
	});

	$("#currLogo").mouseover(function(e) {
		if (document.getElementById("selectedMenu")!=null){
			current_page_id = document.getElementById("selectedMenu").value;
		}		
		if(menuBoxOld != ''){ 			// EIS
			if((menuOld != '')&&(menuOld != current_page_id))
				$("#"+menuOld+"_logo").hide("slide", { direction: "up" }, 500);
			$("#right_"+menuBoxOld).hide("slide", { direction: "right" }, 500);
			menuOld = ''; 			// EIS
			menuBoxOld = ''; 		// EIS
			hide_after_2_seconds_id = '';
		}					// EIS
	});

	/*news items*/
	if(typeof(first_news) != 'undefined')
	{
		if(first_news != null)
		{
			//newsHover = first_news;
			//OnNewsTimer();
		}
	}
	function OnNewsTimer()
	{
		// we have something to display here
		//if (!testiShow) { 
		//	$("#testimonialContent").hide("blind", { direction: "horizontal" }, 500);
		//	testiShow = 1;
		//}
		if(newsDisplayed != newsHover){
			if(newsDisplayed != ''){
				$("#ni_"+newsDisplayed).slideUp();
				var old_elem = document.getElementById('mark_' + newsDisplayed);
				if(old_elem != null) {
					old_elem.style.backgroundImage = 'url(images/listILGreen_small.gif)';
					$("#"+newsDisplayed).css("font-weight", "normal");
				}
			}
			$("#ni_" + newsHover).delay(100).slideDown();
			var new_elem = document.getElementById('mark_' + newsHover);
			if(new_elem != null) {
				new_elem.style.backgroundImage = 'url(images/listILGreen_small_active.gif)';
				$("#"+newsHover).css("font-weight", "bold");
			}
			newsDisplayed = newsHover;
		}
	}

	$("#lnList a").mouseover(function(e) {
		if(newsHover == $(this).attr("id"))
			return;
		newsHover = $(this).attr("id");
		newsTimer = setTimeout(OnNewsTimer, 500);
	});
	$("#lnList a").mouseout(function(e) {
		newsHover = '';
		if(newsTimer != 0)
			clearTimeout(newsTimer);
		newsTimer = 0;
	});
	$("#lnList a").click(function(e) {
		if(newsDisplayed == $(this).attr("id"))
			return;
		newsHover = $(this).attr("id");
		if(newsTimer != 0)
			clearTimeout(newsTimer);
		newsTimer  = 0;
		OnNewsTimer();
	});


//-----------------------------------------------
	function HomeLeftSideSelectTab()
	{
		if(home_left_side_newtab == '')
			return;

		// hide previous tab
		//document.getElementById(home_left_side_tab).style.display = 'none';
		document.getElementById('a_' + home_left_side_tab).className = 'noUnderlinesTab';
		$("#" + home_left_side_tab ).slideUp(250);
		// show current tab
		//document.getElementById(home_left_side_newtab ).style.display = 'block';
		document.getElementById('a_' + home_left_side_newtab ).className = 'noUnderlinesTabSelected';
		$("#" + home_left_side_newtab ).delay(250).slideDown();

		home_left_side_tab  = home_left_side_newtab ;
	}	
	
	$("#tabsHomePage a").mouseover(function(e) {
		var tab = $(this).attr("id");
		home_left_side_newtab = tab.substring(2);
		if(home_left_side_newtab == home_left_side_tab)
			return;
		if(home_left_side_timer != 0)
			clearTimeout(home_left_side_timer);
		home_left_side_timer = setTimeout(HomeLeftSideSelectTab, 500);

		//HomeLeftSideSelectTab();
	});
	$("#tabsHomePage a").mouseout(function(e) {
		home_left_side_newtab = '';
		if(home_left_side_timer != 0)
			clearTimeout(home_left_side_timer);
		home_left_side_timer = 0;
	});
	$("#tabsHomePage a").click(function(e) {
		var tab = $(this).attr("id");
		home_left_side_newtab = tab.substring(2);
		if(home_left_side_newtab  == home_left_side_tab)
			return;
		if(home_left_side_timer != 0)
			clearTimeout(home_left_side_timer);
		home_left_side_timer = 0;
		HomeLeftSideSelectTab();
	});
//-----------------------------------------------
});

