var opicd, opfirstind=true, opcount, opval=1, opvartime, opfunfrom, optim, op1picd, op1firstind=true, op1count, op1val=1, op1vartime, 
op1funfrom, op1tim;

function initwed()
{
  preloadwedshow();
  preloadwed2show();
  preloadImagescat();
}

function preloadwedshow()
{
  for (var i = n; i < imgs.length; i++)
  {
    preloadimgs[i] = new Image();
    preloadimgs[i].src = imgs[i];
  }
  for (var i = 0; i < n; i++)
  {
    preloadimgs[i] = new Image();
    preloadimgs[i].src = imgs[i];
  }
showed();
}

function showed()
{
   if (wedstart)
   {
     wedtime = setTimeout ("showed()", 3000);
     wedstart = false;
   }
   else
   if (document.all)
   {
      wedshowd.style.filter="blendTrans(duration=0.5)";
      wedshowd.filters.blendTrans.Apply();
      wedshowd.src= preloadimgs[n].src;
      wedshowd.filters.blendTrans.Play();
      (n == (imgs.length - 1)) ? n = 0: n++;
      wedtime = setTimeout ("showed()", 5000);
   }
   else
   {
      if (opfirstind)
      {
         clearTimeout(optim);
         opvars("showed()", wedshowd, 1);
      }
      else
      {
         wedshowd.src= preloadimgs[n].src;
         opvars("showed()", wedshowd, 2);
         (n == (imgs.length - 1)) ? n = 0: n++;
      }
   }
}
function preloadwed2show()
{
  for (var i = n2; i < imgs2.length; i++)
  {
    preloadimgs2[i] = new Image();
    preloadimgs2[i].src = imgs2[i];
  }
  for (var i = 0; i < n2; i++)
  {
    preloadimgs2[i] = new Image();
    preloadimgs2[i].src = imgs2[i];
  }
showed2();
}
function showed2()
{
   if (wed2start)
   {
     wed2time = setTimeout ("showed2()", 5500);
     wed2start = false;
   }
   else
   if (document.all)
   {
      wed2showd.style.filter="blendTrans(duration=0.5)";
      wed2showd.filters.blendTrans.Apply();
      wed2showd.src= preloadimgs2[n2].src;
      wed2showd.filters.blendTrans.Play();
      (n2 == (imgs2.length - 1)) ? n2 = 0: n2++;
      wed2time = setTimeout ("showed2()", 5000);
   }
   else
   {
      if (op1firstind)
      {
         clearTimeout(op1tim);
         op1vars("showed2()", wed2showd, 1);
      }
      else
      {
         wed2showd.src= preloadimgs2[n2].src;
         op1vars("showed2()", wed2showd, 2);
         (n2 == (imgs2.length - 1)) ? n2 = 0: n2++;
      }
   }
}

function wedstop(wedpic, wedind)
{
   if (wedpic == 1)
   {
      if (wedind == 1)
      {
         clearTimeout(wedtime);
         clearTimeout(optim);
         stopd.style.color = "#ff0000";
         wedstopind = true;
      }
      else
      {
         if (wedstopind)
         {
            showed();
            stopd.style.color = "#0000ff";
            wedstopind = false;
         }
         else
         {
            clearTimeout(wedtime);
            clearTimeout(optim);
            wedtime = setTimeout ("showed()", 0);
         }
      }
   }
   if (wedpic == 2)
   {
      if (wedind == 1)
      {
         clearTimeout(wed2time);
         clearTimeout(op1tim);
         stop2d.style.color = "#ff0000";
         wed2stopind = true;
      }
      else
      {
         if (wed2stopind)
         {
            showed2();
            stop2d.style.color = "#0000ff";
            wed2stopind = false;
         }
         else
         {
            clearTimeout(wed2time);
            clearTimeout(op1tim);
            wed2time = setTimeout ("showed2()", 0);
         }
      }
   }
}

function opvars(funfrom, picd, ind)
{
     opicd = picd;
     opfunfrom = funfrom;
     opcount = 1;
     (ind == 1) ?  opvar() : opvar2();
}

function opvar()
{
    if (opcount < 21)
    {
       opval = opval - .045;
       opicd.style.opacity= opval;
       opcount =  opcount +1;
       opvartime = setTimeout ("opvar()", 0);
    }
    else
    {
       opfirstind = false;
       clearTimeout(opvartime);
       optim = setTimeout (opfunfrom, 0);
    }
}

function opvar2()
{
    if (opcount < 21)
    {
       opval = opval + .045;
       opicd.style.opacity= opval;
       opcount =  opcount +1;
       opvartime = setTimeout ("opvar2()", 0);
    }
    else
    {
       opfirstind = true;
       opval = 1;
       opicd.style.opacity= 1;
       clearTimeout(opvartime);
       optim = setTimeout (opfunfrom, 5000);
    }
}

function op1vars(funfrom1, pic1d, ind1)
{
     op1picd = pic1d;
     op1funfrom = funfrom1;
     op1count = 1;
     (ind1 == 1) ?  op1var() : op1var2();
}

function op1var()
{
    if (op1count < 21)
    {
       op1val = op1val - .045;
       op1picd.style.opacity= op1val;
       op1count =  op1count +1;
       op1vartime = setTimeout ("op1var()", 0);
    }
    else
    {
       op1firstind = false;
       clearTimeout(op1vartime);
       op1tim = setTimeout (op1funfrom, 0);
    }
}
function op1var2()
{
    if (op1count < 21)
    {
       op1val = op1val + .045;
       op1picd.style.opacity= op1val;
       op1count =  op1count +1;
       op1vartime = setTimeout ("op1var2()", 0);
    }
    else
    {
       op1firstind = true;
       op1val = 1;
       op1picd.style.opacity= 1;
       clearTimeout(op1vartime);
       op1tim = setTimeout (op1funfrom, 5000);
    }
}