data {
	Omega[1, 1] <- 1
	Omega[1, 2] <- 0
	Omega[2, 1] <- 0
	Omega[2, 2] <- 1

	for(k in 1:N){
		first.loc[k, 1] <- y[Yidx[k], 1]
		first.loc[k, 2] <- y[Yidx[k], 2]
		}
	}
model
{
# priors on process uncertainty
iSigma[1:2, 1:2] ~ dwish(Omega[, ], 2)
Sigma[1:2, 1:2] <- inverse(iSigma[, ])

gamma ~ dbeta(1,1)

for(k in 1:N){
	logpsi[k] ~ dunif(-10, 10)  #prior on scaling parameter for t-dist. scale params
	psi[k] <- exp(logpsi[k])

  ## Priors for first locations
	for(i in 1:2){
		x[Xidx[k], i] ~ dt(first.loc[k, i], itau2[Yidx[k], i] * psi[k], nu[Yidx[k], i])
		}

	## Process equation
	x[(Xidx[k]+1), 1:2] ~ dmnorm(x[Xidx[k], ], iSigma[, ])

	for(t in (Xidx[k]+1):(Xidx[k+1]-2)){
	  x.mn[t, 1:2] <- x[t, 1:2] + (x[t, 1:2] - x[t-1, 1:2]) * gamma
	  x[t+1,1:2] ~ dmnorm(x.mn[t, ], iSigma[, ])
	  }

	## Measurement equation
	for(i in (Yidx[k]+1):(Yidx[k+1]-2)){  
	    for(j in 1:2){
	      yhat[i, j] <- w[i] * x[idx[i], j] + (1 - w[i]) * x[idx[i+1], j]
		       y[i, j] ~ dt(yhat[i, j], itau2[i, j] * psi[k], nu[i, j])
		  }
	}
}
}
