$(document).ready(function(){
    
    menu.init();
    
    var contentHeight = $("#content").height();
   // alert(contentHeight);
    $("#sidebarLeft").css({height:""+(contentHeight-8)+"px"});
     $("#sidebarRight").css({height:""+(contentHeight-8)+"px"});


    catAnnunci();
    $(".inserisci").click(function(){
         $(".inserisci").fadeOut("slow");
         $(".cerca").fadeIn("slow");
         $(".pform").fadeIn("slow");
         $(".formText").fadeIn("slow");
         $(".newsearch").fadeOut("slow");
         $(".queryBox").remove();
});
    $(".cerca").click(function(){
         $(".inserisci").fadeIn("slow");
         $(".cerca").fadeOut("slow");
         $(".formText").fadeIn("slow");
         $(".pform").toggle();
         $(".queryBox").remove();
});
    $("#pannunci").click(function(){
        $("#pannunci").val("");
});
    $(".newsearch").click(function(){                
        $(".queryBox").remove();
        $(".pform").toggle();
        $(".newsearch").fadeOut("slow");
        $("inserisci").fadeIn("slow");
        $(".formText").fadeIn("slow");
});
    if ($(".questions").is("div")){
            elScroll();
}
    if($.browser.msie){
        $("#empty").css({height:"53px"});
     }  
          
    $("#mapsearch").click(function(){
        $("#mapsearch").val("");
});
    $(".resetMap").click(function(){
        $(".address").remove();
        $(".resetMap").remove();
        var mapForm = "";
        mapForm += "<form id=\"mapform\" name=\"mapform\" method=\"get\" action=\"map.php\">";
        mapForm += "<input type=\"text\" name=\"mapsearch\" value=\"Cerca\"  style=\"top:-5px;\" id=\"mapsearch\" >";
        mapForm += "<input type=\"image\" src=\"http://robanostra.homeftp.net/projects/area/wordpress/wp-content/themes/area/imgs/search.gif\" name=\"submit\" style=\"top:-2px;left:5px;\" id=\"submap\" /><form>";
        $(".entry").append(mapForm);
});
    
    $("#subaanunci").click(function(){
        $.ajax({
        type: "POST",
        url: "annuncisearch.php",
        data: "kind="+$("#kind").val()+"&pannunci="+$("#pannunci").val(),
        success: function(msg){
        $(".newsearch").fadeIn("slow");
        $(".inserisci").fadeIn("slow");
        $(".formText").fadeOut("slow");
        $(".pform").toggle();
        $(".entry").append(msg);   
         }
 });
        $("#pannunci").val("");
        return false;
});
    
});//////CLOSE DOCUMENT READY FUNCTION///////////////////////////////

function elScroll(){
        var pageScrl = $(document).scrollTop();
        var container_Scrl = $('#content').offset({scroll:false});
		var fm_Scrl = $('.questions').offset({scroll:false});
		var amountToTop=pageScrl-0-container_Scrl.top;
		if(amountToTop<0){
			amountToTop=30;
			}
        $('.questions').animate({top: amountToTop},function(){
                        window.setTimeout('elScroll()', 200)
        });
}

function catAnnunci(){
   var el = $(".boxes").find("span");
   el.click(function(){
   var catKind =  $(this).attr("class");
   var catWhat = $(this).text();
   if ($(".queryBox").is("div")){
        $(".queryBox").remove();
    }
   $.ajax({
        type: "POST",
        url: "annuncicatsearch.php",
        data: "kind="+catKind+"&what="+catWhat,
        success: function(msg){
            $(".newsearch").fadeIn("slow");
            $(".inserisci").fadeIn("slow");
            $(".formText").fadeOut("slow");
            $(".pform").fadeOut("slow");
            $(".entry").append(msg);   
        }
   });
   return false;
});
}

var menu = {
 startImage : '',
 init : function(){
 $("#menu>div>a").hover(function(){
 var img= $(this).find('img').eq(0).attr("src");
 startImage=img;
 var splitImageOn=img.split("_");
 if (splitImageOn[splitImageOn.length-1]!="on.gif"){
 $(this).find('img').attr({src:splitImageOn[0]+"_on.gif"});
 //alert(startImage+"  "+splitImageOn[0]);
 }
 },
 function(){
 $(this).find('img').attr({src:startImage});
  
 });

 }
 
}