/*
 * WIENFLUSS: slides initialization method
 */
function initSlides(headers, headeralts) 
{
  
  // start the innerfade plugin when imagesLoaded is being triggered
  $('#slides').bind("imagesLoaded", function(){
    $(this).innerfade({ 
      speed: 'slow',
      timeout: 5000, 
      runningclass: 'innerfade',
      children: 'p'
    });
  });
  
  // keep track of preloaded images
  var preloaded = 0;
  var img = new Image();
  

  $(img).bind('loadComplete', function(){
    preloaded ++;
    if (preloaded >= headers.length)
    {
      // move alt attribute to span after the image
      $('#slides p img')
        // create span
        .after('<span></span>')
        .next('span')
        // for each span copy the alt text of the corresponding image
        .each(function(){
          $(this)
            .hide()
            .text($(this).prev('img').attr('alt'));
        })
        // back to the images
        .end()
        // clear the alt attribute
        .attr('alt', '')
        // the parent paragraphs
        .parents('p')
        .hover(function(){
                 $(this).find('span').show();
               }, 
               function(){
                 $(this).find('span').hide();
               }
              );
      
      // when focusing (or hovering) the pause-button, show the image caption
      $('#slides #stopper').bind('focus mouseover', function(){
        $(this).nextAll('p').find('span').show();
      })
      $('#slides #stopper').bind('blur mouseout', function(){
        $(this).nextAll('p').find('span').hide();
      });
                
      $('#slides').trigger("imagesLoaded");
    }
  });
  

  // insert the stopper control (not necessary without javascript...)
  $('<a id="stopper" href="#" title="Animation anhalten"><img src="/images/ui/control_pause.png" alt="Animation anhalten" /></a>')
    .insertBefore('#slides p:first')
    .click(function(){
      
      if ($(this).hasClass('stopped'))
      {
        pauseSlides(false);
        $(this).attr('title', 'Animation anhalten')
               .removeClass('stopped')
               .find('img')
               .attr('src', '/images/ui/control_pause.png')
               .attr('alt', 'Animation anhalten');
      }
      else
      {
        pauseSlides(true);
        $(this).attr('title', 'Animation fortsetzen')
               .addClass('stopped')
               .find('img')
               .attr('src', '/images/ui/control_play.png')
               .attr('alt', 'Animation fortsetzen');
      }
      
      return false;
    })
  
  for (var i = 0; i < headers.length; i++)
  {
    img.src = headers[i];
    
    $(img).ready(function(){
      $("#slides p:first")
        .clone(true)
        .children(img)
        .attr("src", headers[i])
        .attr("alt", headeralts[i])
        .end()
        .css("display", "none")
        .insertAfter("#slides p:last");
    }).trigger("loadComplete");
  };
}

var paused = false;

function pauseSlides(isPaused)
{
  paused = isPaused;
} 
 
/* jquery.innerfade.js
 * Datum: 2008-02-14
 * Firma: Medienfreunde Hofmann & Baldes GbR
 * Author: Torsten Baldes
 * Mail: t.baldes@medienfreunde.com
 * Web: http://medienfreunde.com
 */
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('(7($){$.S.a=7(j){R q.17(7(){$.a(q,j)})};$.a=7(p,j){e 2={\'n\':\'u\',\'g\':\'O\',\'d\':\'f\',\'k\':Z,\'H\':\'U\',\'G\':\'a\',\'l\':F};5(j)$.P(2,j);5(2.l===F)e 3=$(p).l();9 e 3=$(p).l(2.l);5(3.8>1){$(p).B(\'16\',2.H).13(2.G);11(e i=0;i<3.8;i++){$(3[i]).B(\'z-Y\',X(3.8-i)).B(\'W\',\'V\').T()};5(2.d=="f"){o(7(){$.a.h(3,2,1,0)},2.k);$(3[0]).x()}9 5(2.d=="b"){e 6=c.m(c.b()*(3.8));o(7(){Q{4=c.m(c.b()*(3.8))}E(6==4);$.a.h(3,2,4,6)},2.k);$(3[6]).x()}9 5(2.d==\'w\'){2.d=\'f\';e 4=c.m(c.b()*(3.8));o(7(){$.a.h(3,2,(4+1)%3.8,4)},2.k);$(3[4]).x()}9{t(\'v-D s r A \\\'f\\\', \\\'b\\\' y \\\'w\\\'\')}}};$.a.h=7(3,2,4,6){5(!N){5(2.n==\'I\'){$(3[6]).M(2.g);$(3[4]).15(2.g)}9 5(2.n==\'u\'){$(3[6]).14(2.g);$(3[4]).12(2.g,7(){K($(q)[0])})}9 t(\'v-n s r A \\\'I\\\' y \\\'u\\\'\');5(2.d=="f"){5((4+1)<3.8){4=4+1;6=4-1}9{4=0;6=3.8-1}}9 5(2.d=="b"){6=4;E(4==6)4=c.m(c.b()*3.8)}9 t(\'v-D s r A \\\'f\\\', \\\'b\\\' y \\\'w\\\'\')}o((7(){$.a.h(3,2,4,6)}),2.k)}})(10);7 K(C){5(C.J.L){C.J.L(\'18\')}}',62,71,'||settings|elements|current|if|last|function|length|else|innerfade|random|Math|type|var|sequence|speed|next||options|timeout|children|floor|animationtype|setTimeout|container|this|either|must|alert|fade|Innerfade|random_start|show|or||be|css|element|Type|while|null|runningclass|containerheight|slide|style|removeFilter|removeAttribute|slideUp|paused|normal|extend|do|return|fn|hide|auto|absolute|position|String|index|2000|jQuery|for|fadeIn|addClass|fadeOut|slideDown|height|each|filter'.split('|'),0,{}))