// Top navigation menu
var menu_timerID=0;
$(function(){
	$(".menu-item").hover(function(){
		if(menu_timerID!=0){
			window.clearTimeout(menu_timerID);
			$(".drop-menu").slideUp('normal');
		}
		$menu = $(this).parent().parent().find(".drop-menu");
		if($menu.length==1) $menu.slideDown('normal');
	}, function(){
		menu_timerID=window.setTimeout(function(){
			$(".drop-menu").slideUp('normal');
		}, 280);
	});
	
	$(".drop-menu").hover(function(){
		window.clearTimeout(menu_timerID);
	},function(){
		$(this).slideUp('normal');
	});
	$('.menu-item').css('text-decoration', 'none');
	
	/* Home page top banner */
	$(".head_banner").find("img").css("display",'block');
	$(".head_banner").cycle({
		fx: 'fade',
		speed:  5500,
		timeout:  2000,
		random:  1
	});
	
	/* ADD TO FAVEROTIES BUTTON */
	$('#addToFavorites').bind('click', function(){
		if (document.all)
	      {
		      window.external.AddFavorite("http://www.natali.co.il","Natali")
	      }else if(window.sidebar){
	      	window.sidebar.addPanel(document.title,location.href,'');
	      }

	});
	/*SCREENER FOR EMPLOYEE SECTION*/
	$('#employeeSection').bind('click', function(){
		$('#screener').show();
		$('#main-menu').css('z-index', '50');
		
		$('.loginClose').bind('click', function(){
			$('#main-menu').css('z-index', 'auto');
			$('#screener').hide();
		});
	});
	
	$('#changeFontSize').bind('click', function(){
		changeFontSize();
	});
	
	$('#enterButt').bind('click', function(){
		doLogin();
	});
	
	function changeFontSize(){
		$.post('/_ajax/ajax.index.php', {'file': 'changeFontSize'}, function(data) {
			$('#fontSize').attr('href',data);
		});
	/*	changeCss Function is in headers Due the langs Changes.*/
	}
	
	function doLogin(){
		//alert("fromwhere: "+fromwhere);
		objUsername = $('.login td > #username');
		objPass  = $('.login td > #password');
		
		if (objUsername.val()){
			if (objPass.val() != ''){
			saverequest(); // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>   the AJAX call 
			}else{
			alert("יש להזין סיסמא");
			objPass.focus();			
			}
		}else{  
			alert("יש להזין שם משתמש");
			objUsername.focus();
		}
	}
	
	function saverequest(){
		//alert (fromwhere)
		$.post('/_ajax/ajax.index.php', {'file': 'login.enter', 'username': objUsername.val(), 'pass': objPass.val()}, function(data) {
			loginData(data);
		});
	}
	
	
	function loginData(data){
		if (data.length > 2){
			var emp_btn = $('#employeeSection');
			if(typeof console != 'undefined') {
				console.log($('#screener'));
			}
			/*$('#screener').hide();
			emp_btn.attr('onclick', '');
			emp_btn.trigger('click');*/
			document.location.href = "/employees";
		}else{
			alert('הפרטים שהוזנו אינם נכונים');
			return false;	
		}
	
	}
});


