mam.contact = new function() {

	
	var buffer = '';
	var selected = null;
	
	jQuery.extend(
		this,  { 
			version: "1.0",
			initialize: function() {		
				$("div[@class='contact_list'] > div> p > a[@class='contact']").click( 
					function() { 				
						if(buffer != '') {
							$('#left-content-column').html(buffer);
							$("li[@class='contact']").each (
								function() {	
									var id = $(this).attr('id');
									if($('#display_photos').size() > 0) {
										var photo_id = id.replace(/_item_/g,"_photo_");
										$('#'+photo_id).hide();
									}
									$('#' + id).css("background","");
                  var photo_id = id.replace(/_item_/g,"_photo_");
                  if ($('#' + photo_id).size() > 0 )
                  {
                  	var imageSrc = $('#' + photo_id + ' img').attr("src");
                  	if (imageSrc.match("_selected")) {
                  	    imageSrc = imageSrc.substring(0,imageSrc.length-13)+".jpg";
                  	    $('#' + photo_id + ' img').attr("src",imageSrc);
                  	}
                  }
									$('#' + id + ' > a:first').removeClass('underline');
									$('#' + id + ' > a:first').addClass('name');
								}
							);
							selected = '';
							$('#contact_back_link').hide();
						}
					} 
				);
								
				$("li[@class='contact']").each (		
							function() {
							$(this).click( 
								function() { 
									var id = $(this).attr('id');
									var text_id = id.replace(/_item_/g,"_text_");
									var photo_id = id.replace(/_item_/g,"_photo_");
									if(buffer == '') {
										buffer = $('#left-content-column').html();
									}
									selected = id;
									$("li[@class='contact']").each (
										function() {	
											var id = $(this).attr('id');
											if(id != selected) {
												if($('#display_photos').size() > 0) {
													var photo_id = id.replace(/_item_/g,"_photo_");
													$('#'+photo_id).hide();
												}
                        $('#' + id).css("background","");
                        var photo_id = id.replace(/_item_/g,"_photo_");
                        if ($('#' + photo_id).size() > 0 )
                  	{
                        	var imageSrc = $('#' + photo_id + ' img').attr("src");
                        	if (imageSrc.match("_selected")) {
                        	    imageSrc = imageSrc.substring(0,imageSrc.length-13)+".jpg";
                        	    $('#' + photo_id + ' img').attr("src",imageSrc);
                        	}
			}										$('#' + id + ' > a:first').removeClass('underline');
												$('#' + id + ' > a:first').addClass('name');
											} else {
                        $('#' + id).css("background","url(/core/library/images/contact_heads/bottom.gif) repeat-x 100% 100%");
                        var photo_id = id.replace(/_item_/g,"_photo_");
                        if ($('#' + photo_id).size() > 0 )
                  	{
                        	var imageSrc = $('#' + photo_id + ' img').attr("src");
                       		imageSrc = imageSrc.substring(0,imageSrc.length-4)+"_selected.jpg";
                       		$('#' + photo_id + ' img').attr("src",imageSrc);
                      	}
                      }
										}
									);
									
									var t = $('#'+text_id).html();
									$('#left-content-column').html('<div>'+t+'</div>');
									$('#contact_back_link').show();
								} 
							);
						
						
							$(this).hover(
								function() { 
									var id = $(this).attr('id');
									var text_id = id.replace(/_item_/g,"_text_");
									var photo_id = id.replace(/_item_/g,"_photo_");
									$('#' + id + ' > a:first').removeClass('name');
									$('#' + id + ' > a:first').addClass('underline');
									
									if($('#display_photos').size() > 0) {
									$("li[@class='contact']").each (
									function() {																		
											var id = $(this).attr('id');
											var photo_id = id.replace(/_item_/g,"_photo_");
											$('#'+photo_id).hide();
										}
									);
									if($('#'+photo_id).size() > 0) {
										
										var b = $(this).height();
										var a = $(this).offset()['top'];										
										var c = $('#'+photo_id).height();
										var y = (a + b) - (c - 5) - 206;
										var x = 200;
										$('#'+photo_id).css('top', y );
										$('#'+photo_id).css('left', x );
										$('#'+photo_id).show();
									}
									}
								}
								,
								function() {
						   		var id = $(this).attr('id');
									if(id != selected) {
                    $('#' + id).css("background","");
                        var photo_id = id.replace(/_item_/g,"_photo_");
                        if ($('#' + photo_id).size() > 0 )
                  	{
                        	var imageSrc = $('#' + photo_id + ' img').attr("src");
                        	if (imageSrc.match("_selected")) {
                        	    imageSrc = imageSrc.substring(0,imageSrc.length-13)+".jpg";
                        	    $('#' + photo_id + ' img').attr("src",imageSrc);
                        	}
                        }
										$('#' + id + ' > a:first').removeClass('underline');
										$('#' + id + ' > a:first').addClass('name');
									}
									if($('#display_photos').size() > 0) {
                    var photo_id = id.replace(/_item_/g,"_photo_");
                    $('#'+photo_id).hide();
                    if(selected != null) {
							   			var photo_selected = selected.replace(/_item_/g,"_photo_");
                      $('#'+photo_selected).show();
                    }
                  }
							   }
							   );
							
							}
						);

			}		
		
		}
	);
	
		
}