var mouseOverEvents = 0;
var menuOld = '';
var menuNew = '';
var menuBoxOld = '';
var menuBoxNew = '';
var newsOld = '';
var newsNew = '';
var testiShow = 0;
var hiding = new Array();

var newsHover = '';
var newsTime = null;
var newsDisplayed = '';
var newsTimer = 0;

$(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(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;
				}
			$("#"+$(this).attr("id")+"_logo").show("slide", { direction: "up" }, 500);
		}	
		menuNew = $(this).attr("id");

		if (menuOld != menuNew) {
			var tmp = menuOld+"_logo";
			hiding.push(tmp);
			$("#"+menuOld+"_logo").hide("slide", { direction: "up" }, 500, function(){ HidingDone(tmp); });	
			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);

		// 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;
			hiding.push(tmp);
			$("#"+menuBoxNew).hide("slide", { direction: "up" }, 500, function(){ HidingDone(tmp); });
			menuOld  = '';
			menuNew = '';
		}
	});

	$("#currLogo").mouseover(function(e) {
		//alert('c');
		if(menuOld != ''){ 			// EIS
			$("#"+menuOld+"_logo").hide("slide", { direction: "up" }, 500);
			$("#right_"+menuBoxOld).hide("slide", { direction: "right" }, 500);
			menuOld = ''; 			// EIS
			menuBoxOld = ''; 		// EIS
		}					// EIS
	});

	/*news items*/
	function OnNewsTimer()
	{
		// we have something to display here
		if (!testiShow) { 
			$("#testimonialContent").hide("blind", { direction: "horizontal" }, 500);
			testiShow = 1;
		}
		if(newsDisplayed != '')
			$("#ni_"+newsDisplayed).hide("slide", { direction: "left" }, 500);
		$("#ni_" + newsHover).delay(100).slideDown();
		newsDisplayed = newsHover;
		newsTimer = 0;
	}

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

	
});