var lc, lo, tc, to;
var tCellHigh = 134;
var imgLoading = new Image();
imgLoading.src = "/imgs/loading.gif";

function init() {
  lc = document.getElementById("mListCnt");
  lo = document.getElementById("mList");
  lu = document.getElementById("listUp");
  ld = document.getElementById("listDw");
  tc = document.getElementById("iThumbsCnt");
  to = document.getElementById("iThumbs");
  tu = document.getElementById("thumbsUp");
  td = document.getElementById("thumbsDw");
  var t = parseInt(lo.style.top.indexOf("px")!=-1?lo.style.top.substr(0,lo.style.top.length-2):lo.style.top, 10);
  ld.style.visibility = (t+lo.offsetHeight>lc.offsetHeight?"visible":"hidden");
  lu.style.visibility = (t!=0?"visible":"hidden");
  t = parseInt(to.style.top.indexOf("px")!=-1?to.style.top.substr(0,to.style.top.length-2):to.style.top, 10);
  td.style.visibility = (t+to.offsetHeight>tc.offsetHeight+1?"visible":"hidden");
  tu.style.visibility = (t!=0?"visible":"hidden");
}

function listMv(d) {
  var t = parseInt(lo.style.top.indexOf("px")!=-1?lo.style.top.substr(0,lo.style.top.length-2):lo.style.top, 10);
  if((d==-1 && t!=0)||(d==1 && t+lo.offsetHeight > lc.offsetHeight)) {
    lo.style.top = (t-d*lc.offsetHeight)+"px";
    ld.style.visibility = (t-d*lc.offsetHeight+lo.offsetHeight>lc.offsetHeight?"visible":"hidden");
    lu.style.visibility = (t-d*lc.offsetHeight!=0?"visible":"hidden");
  }
}

function listLoad(c) {
  document.getElementById("mList").innerHTML = c;
  document.getElementById("mList").style.top = "0px";
  var i = 0;
  while(i < document.links.length && document.links[i].className != "listModel")
    i++;
  if(i < document.links.length)
    document.links[i].className = "listModelH";
  init();
}

function listHighlight(t) {
  for(var i=0; i < document.links.length; i++)
    if(document.links[i].className == "listModelH")
      document.links[i].className = "listModel";
  t.className = "listModelH";
}

function listWoMan(t) {
  if(t == 0) {
    document.getElementById("galMan").src = "/imgs/gallery_man_d.gif";
    document.getElementById("galWoman").src = "/imgs/gallery_woman.gif";
  } else {
    document.getElementById("galMan").src = "/imgs/gallery_man.gif";
    document.getElementById("galWoman").src = "/imgs/gallery_woman_d.gif";
  }
}

function thumbsMv(d) {
  var t = parseInt(to.style.top.indexOf("px")!=-1?to.style.top.substr(0,to.style.top.length-2):to.style.top, 10);
  if((d==-1 && t!=0)||(d==1 && t+to.offsetHeight > tc.offsetHeight)) {
    to.style.top = (t-d*tCellHigh)+"px";
    td.style.visibility = (t-d*tCellHigh+to.offsetHeight>tc.offsetHeight+1?"visible":"hidden");
    tu.style.visibility = (t-d*tCellHigh!=0?"visible":"hidden");
  }
}

function thumbsLoad(c) {
  document.getElementById("iFull").src = imgLoading.src;
  document.getElementById("iThumbs").innerHTML = c;
  document.getElementById("iThumbs").style.top = "0px";
  init();
}

function infoLoad(i) {
  document.getElementById("iInfo").innerHTML = i;
}

function fullLoad(i) {
  document.getElementById("iFull").src = imgLoading.src;
  document.getElementById("iFull").src = i;
}

function toggleBirthday(m) {
  if(m==0) {
    if(document.forma.birthday.value=="") document.forma.birthday.value="yyyy-mm-dd";
  } else {
    if(document.forma.birthday.value=="yyyy-mm-dd") document.forma.birthday.value="";
  }
}

var castingStep = 0;

function sendCasting() {
  if(castingStep == 0) {
    if (checkCasting()) {
      parent.document.getElementById("castingFormData").style.display = "none";
      parent.document.getElementById("castingFormPhotos").style.display = "inline";
      castingStep = 1;
    }
  } else if(castingStep == 1) {
    if (checkAgreement()) {
      document.getElementById("castingButton").innerHTML = "&nbsp;";
      document.forma.submit();
    }
  }
}
