	var max;
    var loginLoaded = false;
	function showArea () {
    	if (loginLoaded){
        	 $('#menu_area').show();
        }else{
   			$.ajax({
                type: "POST",
                cache: false,
                url: '/en/area_login.php',
                success: function(html){
                    loginLoaded = true;
                    $('#menu_area').html(html);
                    $('#menu_area').show();
                }
            });

        }
		
	}
	function hideArea () {
		$('#menu_area').hide();
	}
    
    function slidedx (n) {
    	var s=n*280;
		max=s;
		$('#contenitore_box').animate(
			{ marginLeft: -s }, 
			'slow',
			'swing', function () {
			}
        );

	}
    
	$().ready(function() {
		$('#menu_area').hide();
		$('#res').hide();
        $('#search_close').hide();
        
		$("#search_close").click(function(){
			$('#res').hide();	
            $('#search_close').hide();	
			$('#q').val("");
		});
        
        $("#btleft").click(function(){
        	var margin = parseInt($('#contenitore_box').css("margin-left"));
            var newm=margin+280;
            var m=parseInt(newm) % 280;
            if ( m) {
                return ;
            }

        	if (margin<0) {
                $('#contenitore_box').animate(
                { marginLeft: newm }, 
                    'slow',
                    'swing', function () {
                    }
                );
            }
		});
        
         $("#btright").click(function(){
 
        	var margin = parseInt($('#contenitore_box').css("margin-left"));
            var newm=margin-280;
            var m=parseInt(newm) % 280;
            if ( m) {
                return ;
            }
         	if (-newm<=max) {
                $('#contenitore_box').animate(
                { marginLeft: newm }, 
                    'slow',
                    'swing', function () {
                    }
                );
            }
		});
        
        
        
		$('#q').keyup(function (event) {
			if ($('#q').val().length > 1) {
				$.post("/en/ajax_risultati.php", { q: $('#q').val() },
					function(data){
						if (data) {
							$('#res').html(data);
							$('#res').show();
                            $('#search_close').show();
						} else {
							$('#res').hide();
                            $('#search_close').hide();
						}
					}
				);
			}
			
		});
		
        		$('#area_btn').mouseover(function () { 
			showArea();
		});
        		$('#area_btn').mouseout(function () { 
			$().mousemove(function(e){
				var off = $('#area_btn').offset();
				if ((off.left-e.pageX)<-150|| (off.left-e.pageX)>90 || e.pageY<5 || e.pageY>250) {
					$('#menu_area').hide();
				}
   			}); 

		});
	});


