function initViewer(){
	$(".viewer .listing a").click(function(event){
		event.preventDefault();
		target = $(this).attr('href');
		link = $(this).attr('id');
		viewer = $(this).parents("div.viewer");
		getView(viewer,target,link);
		});
				
	$(".detailSwitch").change(function(){
		if(this.value != ""){
			window.location = this.value;
		} else {
			//alert($(this).parents("form")[0].reset());
			$(this).parents("form")[0].reset();
		}
	});
}

function getView(viewer,target,id){
	$(viewer).find(".listing a").removeClass("current");
	$("a#"+id).addClass("current");
	
	$.ajax({
		type: "POST",
		url: target,
		data: "mode=viewer",
		dataType: "html",
		cache: false,
		error: function(a,b,c){
			alert(a);
			alert("AJAX Error:\n"+c);
			alert("Response Text:\n"+a.responseText);
		},
		success: function(html,status){
			$(viewer).find(".results").html(html);
		},
		complete: function(html,status){
			$(viewer).find("img.AJAXindicator").remove();
		},
		beforeSend: function(){
			$(viewer).append('<img class="AJAXindicator" src="/i/indicator_snake.gif"/>');
		}
	});
}
