
$(function() {
	
	
    $(".title-bar a").click( function(){
        $('#daten-telefonbuch').animate({width: "0px", left: "0px"}, { queue:false, duration:400 });
        $('#daten-telefonbuch').css("visibility","hidden");
       // $(this).animate({width: maxWidth+"px"}, { queue:false, duration:400});
       
     });
	
    /*
    var bindAjaxStatus = function() {
	   
	    $('div.titlebar').ajaxStart(function() {
	    	$(this).css('background',"url(/telefonbuch/images/ajax-loading.gif) no-repeat");
	    }).ajaxStop(function() {
	    	$(this).css('background',"url(/telefonbuch/images/imgBackground.jpg) no-repeat");
	    });
    }
    */
   var sendItemLink = function() {
	   var $href= $(this).attr('href');
	   $.ajax({
		    type: "GET",
		    url: $href,
		    dataType: "html",
		    cache: false,
		    success: function(data) {
		    	$('#contact-data-container').attr('innerHTML', data); 
		    },
		    error: function (XMLHttpRequest, textStatus, errorThrown) {
		        $("#contact-data-container").html(XMLHttpRequest.responseText);
		    }
		});
	   return false;
   }
    
   
	$('#telefonbuch-form').submit( function() {

		
		$('#daten-telefonbuch').animate({width: "400px", left: "-401px"}, { queue:false, duration:400 });
		$('#daten-telefonbuch').css("visibility","visible");
		
		//bindAjaxStatus();
		
		var $begriff = escape( $('input[name="search-item"]').val());
		//$begriff = escape($begriff);
		
		$.ajax({
		    type: "GET",
		    url: "/portal/Webmaster/telefonbuch_suche.jsp?search-item=" + $begriff,
		    dataType: "html",
		    cache: false,
		    success: function(data) {
		    	//alert(data);
		    	$('#contact-data-container').attr('innerHTML', data); 
		    	//$('#contact-data-container').html(data);
		    	$('#contact-data-container a.search-item-link').each(function() {
		    		$(this).click(sendItemLink);
		    	});
		    	
		    },
		    error: function (XMLHttpRequest, textStatus, errorThrown) {
		        $("#contact-data-container").html(XMLHttpRequest.responseText);
		    }
		});

		return false;
	});
	
	
});
