$(document).ready(function() {
	$('.open-box, .close-box').click(function(){

		var box = $('.inner', $(this).parent().parent().parent());
		
		if(box.css('display')=="none"){
			box.show('slow');
			$(this).css('background-image', "url('/sites/agel/_static_media/public/boxes/close.jpg')");
		}
		else{
			box.hide('slow');
			$(this).css('background-image', "url('/sites/agel/_static_media/public/boxes/open.jpg')");
		}
	});
	
	$('.search-friends-open').click(function(){
		if($('.search-friends-advanced').css('display')=="none"){
			$('.search-friends-advanced').show('slow');
			$(this).html('[Close]');
		}
		else{
			$('.search-friends-advanced').hide('slow');
			$(this).html('[Advance]');
		}
	});
	
	$('.add-friend-details-open').click(function(){
		if($('.add-friend-details').css('display')=="none"){
			$('.add-friend-details').show('slow');
			$(this).html('[Close]');
		}
		else{
			$('.add-friend-details').hide('slow');
			$(this).html('[Edit relationship]');
		}
	});

	var dijkstra;
	$('.src-mem-open').click(function(){
		if($('.src-mem-extra', $(this).parent()).css('display')=="none"){
			$('.src-mem-extra', $(this).parent()).show('slow');
			$('.src-mem-details', $(this).parent()).css('width', '420px');
			$('.src-mem-img', $(this).parent()).css('width', '230px');
			$('img', $('.src-mem-img', $(this).parent())).css('width', '220px');
			$(this).css('background-image', "url('/sites/agel/_static_media/public/boxes/close-friends.gif')");
			
			
			dijkstra = $('.dijkstra_div', $(this).parent());
			if(dijkstra.attr('id_look')!=0){
				ajaxpack.postAjaxRequest("/scripts/one_dijkstra/", "id_look="+dijkstra.attr('id_look')+"&mem_id="+dijkstra.attr('mem_id')+"",  update_dijksra_result, "txt");
				dijkstra.attr('id_look', 0);
			}
		}
		else{
			$('.src-mem-extra', $(this).parent()).hide('slow');
			$('.src-mem-details', $(this).parent()).css('width', '560px');
			$('.src-mem-img', $(this).parent()).css('width', '70px');
			$('img', $('.src-mem-img', $(this).parent())).css('width', '59px');
			$(this).css('background-image', "url('/sites/agel/_static_media/public/boxes/open-friends.gif')");
		}
	});
	
	function update_dijksra_result(){
		var myajax=ajaxpack.ajaxobj
	    var myfiletype=ajaxpack.filetype
	    if (myajax.readyState == 4){
	        if (myajax.status==200 || window.location.href.indexOf("http")==-1){
	        	var result = myajax.responseText;
	        	dijkstra.html(result);
	        }
	    }
	}
});