data {
	Omega[1, 1] <- 1
	Omega[1, 2] <- 0
	Omega[2, 1] <- 0
	Omega[2, 2] <- 1
	
	first.loc[1] <- y[1, 1]
	first.loc[2] <- y[1, 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)	
logpsi ~ dunif(-10, 10)		
psi <- exp(logpsi)

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

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

for(t in 2:(Nx-1)){
	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 1:(Ny-1)) {	
  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, nu[i, j])
    }
  }	
}


