(function($)
{
    $.fn.listing = function(l)
    {
        l = $.extend({
        active: new Array(),
        listing: true// previous button customization
        }, l || {});
        return this.each(function()
        {
            $('.no_listing').bind('click', function()
            {
                l.listing = false;
            })
            var table = $(this);
            $(".agentur", table).each(function()
            {
                if(this.id)
                    {
                        $(this).bind('click', function()
                        {
                            if(l.listing == true)
                            {
                            var customerId = this.id.replace(/c_/g, '');
                            if(l.active[customerId] != true)
                            {
                                if($('#profile_'+customerId).html() == '')
                                    get_profile(customerId, this);
                                else
                                   $('#profile_'+customerId).show() ;
                                l.active[customerId] = true;
                                
                            }
                            else
                            {
 //                               $('#profile_'+customerId).html('');
                                $('#profile_'+customerId).hide();
                                l.active[customerId] = false;
                                $("td", this).addClass('listing');
                            }
                            }
                        });
                        $(this).bind('mouseover', function()
                        {
                            l.listing = true;
                                $("td", this).each(function()
                                {
                                    var pos  = ' '+$(this).attr('class').indexOf('logo');
                                    if(pos == -1)
                                        $(this).addClass('active_entry');
                                })
                                  //  
                        });
                        $(this).bind('mouseout', function()
                        {
                            $("td", this).removeClass('active_entry');
                        });
                    }
            });

            $('.notepad').bind('click', function()
            {
                var customerId = $(this).attr('name');
                $('#Dialog').load('/branchenbuch/inc/ajax/Merkzettel.php',
                {ajaxpost: {routing: 'Merkzettel',
                            action: 'store',
                            customerId: customerId}},
                            function (responseText, textStatus, XMLHttpRequest)
                            {
                                $('#transparentLayer').show();
$( "#Dialog" ).dialog({
						width: 250,
						resizable: false,
						title: 'Merkzettel',
						close: function()
						{
                                                    $('#transparentLayer').hide();
                    $( "#Dialog" ).html();

							$(this).dialog('destroy');
						},
						buttons: {
							"OK": function()
							{
								$(this).dialog("close");
							}
						}
					});
                            });
            });


            $('.delete').bind('click', function()
            {
                var customerId = $(this).attr('name');
                $('#Dialog').load('/branchenbuch/inc/ajax/Merkzettel.php',
                {ajaxpost: {routing: 'Merkzettel',
                            action: 'delete',
                            customerId: customerId}},
                            function (responseText, textStatus, XMLHttpRequest)
                            {
                                $('#transparentLayer').show();
$( "#Dialog" ).dialog({
						width: 250,
						resizable: false,
						title: 'Merkzettel',
						close: function()
						{
                                                    $('#transparentLayer').hide();
                    $( "#Dialog" ).html();

							$(this).dialog('destroy');
						},
						buttons: {
							"OK": function()
							{
								$(this).dialog("close");
                                                                location.reload();
							}
						}
					});
                            });
            });


        });


/*
$('.lightbox').tooltip({
	track: true,
	delay: 0,
	showURL: false,
	showBody: " - ",
	extraClass: "pretty",
	fixPNG: true,
//	opacity: 0.95,
	left: -250,
        top: -150
});

*/

function get_profile(Id, tr)
{
        $('#profile_'+Id).load('/branchenbuch/inc/ajax/get_profile.php',
        {ajaxpost: {routing: 'get_profile',
                    customerId: Id}},
        function (responseText, textStatus, XMLHttpRequest)
        {
            $("td", tr).removeClass('listing');
            $(".prettyPhoto").prettyPhoto({animationSpeed:'fast'});
          $('#close_layer').bind('click', function()
          {
            $('#transparentLayer').hide();
            $('#leistungen').hide();
          });
        }
    );

}


    }

if($(".prettyPhoto")) {
  $(".prettyPhoto").bind('click', function() {
      alert("HIT");
      return;
  })
  $(".prettyPhoto").prettyPhoto({animationSpeed:'fast'});
}

})(jQuery);


