// movie for the mitral and granule synapse weights associated with
// the mitral or granule cell gid
create w_movie_section
w_movie_section {delete_section()}
objref keepsyn, movie_ncl, w_grph_, w_grph_handle_, w_box_
{load_file("pattern.hoc")}
w_clear_ignore = 0

proc clear_weight_movie() {
	if (w_clear_ignore) { return }
	objref w_box_, w_grph_handle_, w_grph_, movie_ncl, keepsyn
	if (section_exists("w_movie_section")) {
		w_movie_section { delete_section() }
	}	
}

proc synonly() {local i  localobj mg, syn, nc, nil
	clear_weight_movie()
	create w_movie_section
	w_movie_section { insert pas g_pas = 1e9 e_pas = -65 }
	keepsyn = new List()
	movie_ncl = new List()
    if (argtype(1) == 0) {
	for i=0, mgrs_list.count-1 {
		mg = mgrs_list.object(i)
		if ($1 == -1 || mg.mitral_gid == $1 || mg.granule_gid == $1) {
			w_movie_section mg.fi.loc(.5)
			keepsyn.append(mg.fi)
			w_movie_section mg.ampanmda.loc(.5)
			keepsyn.append(mg.ampanmda)
		}
	}
    }else{ // synsel list
	for i=0, $o1.count-1 {
		mg = $o1.object(i)
		w_movie_section mg.fi.loc(.5)
		keepsyn.append(mg.fi)
		w_movie_section mg.ampanmda.loc(.5)
		keepsyn.append(mg.ampanmda)
	}
	$o1.remove_all()
    }
	mg = nil
	w_clear_ignore = 1
	clear()
	w_clear_ignore = 0
	for i=0, keepsyn.count-1 {
		syn = keepsyn.object(i)
		nc = pc.gid_connect(syn.srcgid, syn)
		nc.weight[0] = 1
		nc.delay = 1
		movie_ncl.append(nc)
	}
}

proc weight_movie() {localobj s
	synonly($1)
	w_box_ = new VBox()
	w_box_.intercept(1)
	w_grph_ = new Graph()
	w_grph_handle_ = new FInitializeHandler("cvode.event(0, \"show_weight()\")")
	s = new String()
	if ($1 < num_mitral) {
		w_use_x = 1
		sprint(s.s, "Synapses associated with Mitral gid %d\n", $1)
	}else{
		w_use_x = 0
		sprint(s.s, "Synapses associated with Granule gid %d\n", $1)
	}
	w_grph_.size(0, w_use_x*net_spatial_len + (1 - w_use_x)*(num_mitral-1), 0, 1)
	w_box_.intercept(0)
	w_box_.map(s.s, 400, 250, 700, 250)
	stdinit()
}

proc show_weight() {local i, x, w  localobj g
	g = w_grph_
	g.erase()
	for i=0, movie_ncl.count-1 {
		if (w_use_x) {
			x = keepsyn.object(i).x
		}else{
			x = keepsyn.object(i).mgid
		}
		w = movie_ncl.object(i).weight[2]
		if (i%2) {
			g.mark(x, w, "S", 8, 2, 1)
		}else{
			g.mark(x, w, "s", 10, 3, 2)
		}
	}
	cvode.event(t+100, "show_weight()")
}

{load_file("allsynhinton.hoc")}
proc allsyn() {
	synonly(-1)
	w_box_ = new AllSynHinton(movie_ncl)
	stdinit()
}

{load_file("somesyn.hoc")}
proc somesyn() {
	synonly($o1)
	w_box_ = new SomeSyn(movie_ncl)
	stdinit()
}