﻿jQuery.noConflict();

switchProduct = function() {
  // Funktion noch zu überarbeiten, da Codedoppelung!
  $thumbs.each(function() {
    jQuery(this).hover(function() {
      jQuery('.current').removeClass('current');
      stopper = true;
      jQuery('.thumbs').css('background', 'transparent');
      
      jQuery(this).css('background', 'url(/tl_files/pics/layout/cover.gif) bottom left no-repeat');
      jQuery(this).addClass('current');
      jQuery('div.content').hide();
      //jQuery('img.content').hide();
      jQuery('.text').hide();
      
      //jQuery('div.' + jQuery(this).children('a').attr('class')).show();
      var content_class = '.' + jQuery(this).attr('id')
      if (jQuery(this).attr('id') == 'sonderband-spezial') {
        content_class = '.sonderband';
      }
      jQuery(content_class).show();
      
      getCurrentCoverID();
      
      window.setTimeout('repaint();', 50);
    },
    function() {
      stopper = false;
    });
  });

  jQuery('#cover_container').hover(function() {
    stopper = true;
  },
  function() {
    stopper = false;
  });

  // erstes Element anzeigen und hervorheben
  autoSwitchProduct();

  // Autowechsel initiieren
  window.setInterval('autoSwitchProduct();', 16000);
};

/**
* @fn void repaint()
* Allgemeine Repaint-Funktionalität zum manuellen Auslösen des Re-Rendering (=> IE)
* @author Alexander Rothe (c&p IIZ)
* @date 2010-07-30
*/
repaint = function() {
return;
  jQuery('.additional_links').append('&nbsp;');
  jQuery('#wrapper').addClass('repaint');
  jQuery('#wrapper').removeClass('repaint');
};

var cover_nr = 0;
  
getCurrentCoverID = function() {
  var index = 0;
  for (var i = 0; i < $thumbs.length; i++) {
    if (jQuery($thumbs[i]).hasClass('current')) {
      index = i;
      break;
    }
  }
  cover_id = index;
};

autoSwitchProduct = function() {
  if (!stopper) {
    // Ansicht allgemein zurücksetzen
    $thumbs.css('background', 'transparent');
    jQuery('div.content').hide();
    //jQuery('img.content').hide();
    jQuery('.text').hide();

    var cover = $thumbs.slice(cover_id, cover_id+1);
    
    cover.css('background', 'url(/tl_files/pics/layout/cover.gif) bottom left no-repeat');
    
    //jQuery('.' + cover.children('a').attr('class')).show();
    content_class = '.' + cover.attr('id');
    if (cover.attr('id') == 'sonderband-spezial') {
      content_class = '.sonderband';
    }

    jQuery(content_class).show();
    
    // ID für nächste Ansicht
    
    cover_id++;
    if (cover_id >= jQuery('.thumbs').length) {
      cover_id = 0;
    }
    
  }
};

// Zähler/ID Anzahl Hefte/Bände
var cover_id = 0;

// Wenn Stopper, dann lein Autowechsel
var stopper = false;

var $thumbs;


jQuery(document).ready(function() {
  
  jQuery('a.lightbox').fancybox({
    'titlePosition': 'inside',
    'enableEscapeButton': true,
    'overlayOpacity': '0.5',
    'overlayColor': '#000000',
    'type': 'iframe',
    'width': 600,
    'height': 400
  });
  
  jQuery('a.newsletter-unsubscribe').fancybox({
    'titlePosition': 'inside',
    'enableEscapeButton': true,
    'overlayOpacity': '0.5',
    'overlayColor': '#000000',
    'type': 'iframe',
    'width': 600,
    'height': 400,
    'onClosed': function() { location.search = ''; }
  });
  
  //jQuery("a.lightbox.abonnement").trigger('click');

  // Mouseover und initiale Ansicht
  $thumbs = jQuery('.landingpage .thumbs');
  switchProduct();

  window.setTimeout('repaint();', 50);
  
});  
