var images;
var inputs;
var toggleplay = true;
var stoped = false;
function initContent() {
  $(".torggleplay","#janimation").bind("click", function(e){
    if (!toggleplay) {toggleplay = false; return false;}
    toggleplay = false;
    if (!stoped) $(this).attr("value","play").attr("title","Play the animation");
    else $(this).attr("value","stop").attr("title","Stop the animation");
    stoped = !stoped;
    if(!stoped) setTimeout (fnext_op,500);
    return false;
  });
  $("img:not(.start)","#janimation").css("opacity", 0).css("left", 0).css("display","none");
  $("img.start","#janimation").css("opacity",1).removeClass("start");
  images = $("img","#janimation");
  inputs = $("input:not(.torggleplay)","#janimation");
  setTimeout (fnext_op,4000);
}

function fnext_op() {
  num = images.index($("img:visible","#janimation"));
  next = (images.size() == num + 1) ? 0 : num + 1;
  if (stoped) {
    toggleplay = true;
    return;
  }
  toggleplay = true;
  inputs.eq(num).animate({"opacity" : .5},2500,"linear");
  images.eq(num).animate({"opacity" : 0},500,"linear",function() {
    $(this).css("display","none");
  ;});
  inputs.eq(next).animate({"opacity" : 1},2500,"linear");
  images.eq(next).css("display","block").css("left", 0);
  images.eq(next).animate({"opacity" : 1},500,"linear");
  setTimeout (fnext_op,4000);
}
