function initFilm(){
   $('#headwrapper .flv-film').fancybox({
         'transitionIn' :  'fade',
         'transitionOut'   :  'fade',
         'speedIn'      :  300, 
         'speedOut'     :  100, 
         'opacity':false,
         'overlayColor':   '#666',
         'overlayOpacity':   '0.9',
         
         'type':'iframe',
         'width': 480,
         'height':420,
         'titleShow': false,
         'autoDimensions':false
   
   });
   
}

/*
 * ######################################################
 * SHOP
 * ######################################################
 */
function initShop(){
   
   var location = document.location.href;
   if(location.indexOf("#")!=-1){
      var selectedId = location.split("#")[1];
      
      var startswithtab = selectedId.substring(3,0);
      if(startswithtab!='tab'){
         selectedId = $("#content div.detailContent div.tabs ul.tabheads li a[href='#"+selectedId+"']");
      } else {
         selectedId = $("#"+selectedId);
      } 
      
      changeTab(selectedId);
   }
   
   
   $("#content .shop_detail_box .tabheads a.clickme").click(function() {
      changeTab($(this));
      return false;
   });
   
   $("#varianten #varianten_tabelle tr.tooltip").tooltip({
      bodyHandler: function() {
         var tooltipContainer = $(this).find("div.tooltip");
         return tooltipContainer.html();
      },
      showURL: false
   });
   
   // Verstecke die Antworten - nur per JS (Somit ohne JS auch nutzbar)
   $('.faq_ansicht_js dd.answer').hide();

   // Beim Klicken soll nichts passieren
   $(".faq_ansicht_js dt.question a").click(function(){
      // Hole die Antwort
      var dt = $($(this).attr("href"));
      // Ermittle die zuletzt geöffnete Antwort
      var selectedFAQ = $(".faq_ansicht_js .selectedFAQ");
      // Nur wenn die beiden nicht in der ID übereinstimmen, wird es aufgeklappt
      if(dt.attr("id")!=selectedFAQ.attr("id")){
         // 'Alte' FAQ verstecken
         selectedFAQ.slideUp(300);
         selectedFAQ.removeClass("selectedFAQ");
         // 'Neue' FAQ öffnen
         dt.slideDown(300);
         dt.addClass("selectedFAQ");
      }
      return false;
   });
   
   // Wenn man sich auf dem Reiter Varianten befindet und dort einen Artikel in den Warenkorb legt soll danach wieder der Reiter Varianten zu sehen sein
   // Dazu muss der href angepasst werden, eine "#varianten" muss dem Link angefügt werden.
   var divs = $('#varianten_tabelle').find('.warenkorb_klein');
   divs.each(function(){
	// jeweils den Link auslesen und verändern
      var link = $(this).find('a');
      var href = link.attr("href");
      href = href + '#varianten';
      link .attr({'href':href});
   })
   
}

function changeTab(newSelected) {
   var lastSelected = $("#content .shop_detail_box .tabheads a.selected");
   var lastSelectedBox = $(lastSelected.attr("href"));
   var newSelectedBox = $(newSelected.attr("href"));

   if(newSelected.hasClass("selected")){
      return false;
   }

   /* HIDE OLD DATA */
   lastSelected.removeClass("selected");
   lastSelectedBox.slideUp(250);
   
   /* SHOW NEW DATA */
   newSelected.addClass("selected");
   newSelectedBox.slideDown(250);
}
/*
 * ######################################################
 * FAQ-ACCORDION
 * ######################################################
 */
function initFAQAccordion(){
   $('#questions-container').accordion();
}
/*
 * ######################################################
 * FAQ-SUCHE
 * ######################################################
 */
function initFAQSuche(){
   $('#listeMasterTable .faq_suchergebnis dd').hide();
   $('#listeMasterTable .faq_suchergebnis dt').css("cursor", "pointer");
   
   $("#listeMasterTable .faq_suchergebnis dt").click(function(){
      $(this).next().slideToggle(300);
   });
   
   $("#listeMasterTable .faq_suchergebnis dt").hover(
         function () {
           $(this).addClass("hover");
         }, 
         function () {
           $(this).removeClass("hover");
         }
       );

}

/*
 * ######################################################
 * Tabellen-Hover
 * ######################################################
 */
function initTableHover(){
   $("#varianten #varianten_tabelle tr").hover(
     function () {
      $(this).toggleClass("highlite");
     },
     function () {
      $(this).toggleClass("highlite");
     }
   ); 
}




/*
 * ######################################################
 * SLIDESHOW
 * ######################################################
 */
function initSlideshow(){
   $('#header').cycle({
      fx: 'fade',
      before: onBefore,
      speed:    1000, 
      timeout:  5000,
      next: $("#nextSLS"),
      prev: $("#prevSLS")
   });
   
   $("body").append(
         $("<div/>").attr("id", "info-container")
   );
   
   $("#header .infopunkt").hover(function() {
      var info = $(this);
      info.attr("title", "");
      var infoContainer = info.find(".info");
      var tooltip = $("#info-container");
      tooltip.html(infoContainer.html());
      
      var distanceToTop = info.offset().top+25;
      var distanceToLeft = info.offset().left-100;
      
      tooltip.css("top", distanceToTop);
      tooltip.css("left", distanceToLeft);
      
      
      tooltip.show();
      
   } , function() {
      var tooltip = $("#info-container");
      tooltip.hide();
       
   });
   
   
   $("#info-container").hover(function() {
      var tooltip = $("#info-container");
      tooltip.show();
      
   } , function() {
      var tooltip = $("#info-container");
      tooltip.hide();
       
   });
   

   
   $('#pausePlaySLS').click(function() {
      var elm = $(this);
      if(elm.hasClass("pause-SLS")){
         $('#header').cycle('pause');
         elm.removeClass("pause-SLS");
         elm.addClass("play-SLS");
      } else {
         $('#header').cycle('resume');
         elm.removeClass("play-SLS");
         elm.addClass("pause-SLS");
         
      }
      
       return false;
      
      return false;
   });

}

/*
 * ######################################################
 * LIGHTBOX FUER E-MAIL-LOGIN
 * ######################################################
 */
function initEMailLightbox(){
   
   $('#login a').fancybox({
      'transitionIn' :  'fade',
      'transitionOut'   :  'fade',
      'speedIn'      :  300, 
      'speedOut'     :  100, 
      'opacity':false,
      'overlayColor':   '#666',
      'overlayOpacity':   '0.7',
      
      'type':'inline',
      'width': '98%',
      'height':'98%',
      'titleShow': false
   });
   
}
/*
 * ######################################################
 * News-Slider
 * ######################################################
 */

function initNewsSlider(){
   var newsticker = $(".newsticker-jcarousellite");
   newsticker.jCarouselLite({
      hoverPause:true,
      visible: 3,
      auto:3500,
      speed:1500,
      btnNext: "#nextSlider",
      btnPrev: "#prevSlider"
   });
   
   var news = $(".newsticker-jcarousellite ul li");
   news.each(function (i) {
      var link = $(this).find(".info h3 a").attr("href");
      
      $(this).attr("href", link);
      
   });
   
   news.click(function(){
      window.location=$(this).attr("href"); return false;
    });
}
/*
 * ######################################################
 * TEASER
 * ######################################################
 */
function initTeaser(){
    //Volle Ausblendung des Textes
   var teaser = $("#content .teaser-container .teaser");
   teaser.each(function (i) {
      var teaserLink = $(this).find(".inner a").attr("href");
      $(this).attr("href", teaserLink);
      
      var teaserText = $(this).find(".inner .teaser-text");
      var height = 184 -(teaserText.find(".inner-teaser-text h3").height()+10);
      teaserText.css("top", height+"px");
   });
   
   teaser.css("cursor", "pointer");
   
   teaser.click(function(){
      window.location=$(this).attr("href"); return false;
    });
   
   teaser.hover(function(){
      var teaserText = $(".teaser-text", this);
      var height = 188-teaserText.height();
      teaserText.stop();
      teaserText.animate(
         {top:height+'px'},
         {queue:false,duration:160}
      );
    }, function() {
       var teaserText = $(".teaser-text", this);
       var height = 184 -(teaserText.find(".inner-teaser-text h3").height()+10);
       teaserText.stop();
       teaserText.animate(
          {top:height+'px'},
          {queue:false,duration:160}
       );
    });  
}
/*
 * ######################################################
 * PRODUKT-MENUE 
 * ######################################################
 */
function requestData(service, method) {
   var moxMessage = new MoxMessage(service,method);
   return MoxServer.executeData(moxMessage);
}

function getArtikel(artikelID, menuEntry) {
   var artikelPreview = $("#artikel-preview");
   artikelPreview.hide();
   $("#artikel-name").text("");
   $("#artikel-bild img").attr("src", "/images/system/allgemein/clear.gif");
   $("#artikel-bild img").css("max-height", "1px");
   $("#artikel-text").html("");
   
   var artikel = requestData("org.auctores.schaller.hp2", "getArtikelByID(\""+artikelID+"\")");
   var parentUL = menuEntry.parent().parent();
   var sName = $("<div>"+artikel.getData("srlhp_name")+"</div>").html();
   var sText = $("<div>"+artikel.getData("srlhp_text")+"</div>").html();
   $("#artikel-name").text(sName);
   $("#artikel-bild img").attr("src", artikel.getData("srlhp_bild"));
   $("#artikel-text").html(sText);
   
   artikelPreview.attr("href", menuEntry.attr("href"));
   
   // Set the Link for Tabs
   var link = artikelPreview.attr("href");
   
   $("#artikel-text .artikel-links a").each(function (i) {
      var tabID = $(this).attr("href");
      /* Workaround IE8 - stellt momentane URL vor die Raute */
      tabID = tabID.substring(tabID.indexOf("#"));
      $(this).attr("href", link+tabID);
   });
   
   parentUL.append(artikelPreview);
   artikelPreview.show();
   
   
   var distanceToTop = $("#artikel-preview").offset().top;
   
   if(distanceToTop>0)
      $("#artikel-bild img").css("max-height", (distanceToTop-15)+"px");
      
   return true;
}

function changeProduktBilder(){
   var menuLink = $("#MenuProdukte li a.firstEbene");
   
   var linkIMG = menuLink.find("img");
   
   var src = linkIMG.attr("src");
   var length = src.length;
   src = src.substring(length-5, length-4);
   var number = parseInt(src);
   if(number==8)
      number=1;
   else
      number++;
   
   
   linkIMG.css({opacity: "1"});
   linkIMG.fadeOut(800, function () {
      
      linkIMG.each(function (i) {
         var linkID = $(this).parent().attr("id");
         if(linkID=="PRD_GITARREN_ZUEBHOER" || linkID=="PRD_PICKUPS"){
            $(this).attr("src", "/org.auctores.schaller.hp2/org/auctores/schaller/hp2/view/jsp/images/start/produkte/bilder/"+$(this).parent().attr("id")+"/1.png");
         } else {
            $(this).attr("src", "/org.auctores.schaller.hp2/org/auctores/schaller/hp2/view/jsp/images/start/produkte/bilder/"+$(this).parent().attr("id")+"/"+number+".png");
         }
      });
      
      linkIMG.fadeIn(800, function () {
         linkIMG.css({opacity: "1"}); 
      });
   });
   

   
}



function initProduktMenu(){
   setInterval( "changeProduktBilder()", 6000 );
   
   $("body").append(
      $("<div/>").attr("id", "product-overlay")
   );
   
   $(window).resize(function() {
      var list = $("#MenuProdukte");
      var leftholder = $("#products");
      list.css({
         left: leftholder.offset().left
      });
    });


    var list = $("#MenuProdukte");
    var leftholder = $("#products");
    var offsetLeft = leftholder.offset().left;
    // Anpassung für Mozilla
    if ( $.browser.mozilla && $.browser.version.slice(0,3) >= "1.9" ) {
       offsetLeft+=7;
    }
    // Anpassung für IEs größer 7.0
    if($.browser.msie && $.browser.version.slice(0,1) > "7") {
    	offsetLeft+=7;
    }
     list.css({
        position: "absolute",
        top: list.offset().top,
        left: offsetLeft
     });
     list.remove().appendTo("body");
     
    $("#MenuProdukte").superfish({ 
        delay:       500,                            // one second delay on mouseout 
        animation:   {opacity:"show"},  // fade-in and slide-down animation 
        speed:       "fast",                          // faster animation speed 
        onShow:  function(){
           var main = $("#MenuProdukte");
           var mainTopGesamt = main.offset().top + main.height(); 
           
           var ul2open = this;
           var ul2openTopGesamt = ul2open.offset().top + ul2open.height();
           
           if(ul2openTopGesamt>mainTopGesamt){
              var openedMainLink = ul2open.parent();
              var distanceLinkTopEndMain = mainTopGesamt-(openedMainLink.height()+openedMainLink.offset().top) ;
              ul2open.css("bottom", "-"+distanceLinkTopEndMain+"px");
              ul2open.css("top", "auto");
           }
        },
        autoArrows:  false,                           // disable generation of arrow mark-up 
        dropShadows: false                            // disable drop shadows 
    }); 

      
   $("#MenuProdukte").hover(function() {
         $(this).css("z-index", "10000");
         $("#product-overlay").css("opacity", 0.7);
         $("#product-overlay").height($(document).height());
         $("#product-overlay").width($(document).width());
         $("#product-overlay").show();
      } , function() {
         $("#product-overlay").hide();
         $(this).css("z-index", "10");
          
   });

   
   $("ul.MenuCon li.getArtikel a.getArtikel").hover(function() {
         var id = $(this).attr("id");
         getArtikel(id, $(this));
      } , function() {
   });
   
   $("ul.MenuCon li.liFirstEbene").hover(function() {
      $(this).css({"z-index" : "10"}); /*Add a higher z-index value so this image stays on top*/ 
      $(this).find("a.firstEbene img").addClass("hover").stop() /* Add class of "hover", then stop animation queue buildup*/
         .animate({
            bottom: "-15px",
            width: "50px", /* Set new width */
            height: "50px", /* Set new height */
            opacity: 1.0
         }, 150); /* this value of "200" is the speed of how fast/slow this hover animates */
   
      } , function() {
      $(this).css({"z-index" : "0"}); /* Set z-index back to 0 */
      $(this).find("a.firstEbene img").removeClass("hover").stop()  /* Remove the "hover" class , then stop animation queue buildup*/
         .animate({
            bottom: "0",
            width: "30px", /* Set width back to default */
            height: "30px", /* Set height back to default */
            opacity: 1.0
         }, 300);
   });
   
   $("#artikel-bild").click(function(){
      window.location=$("#artikel-preview").attr("href"); return false;
    });
   $("#artikel-name").click(function(){
      window.location=$("#artikel-preview").attr("href"); return false;
   });
   
   
}
function initMainDropdown(){
   $("#MenuMain").superfish({ 
      delay:       500,                            // one second delay on mouseout 
      animation:   {opacity:"show"},  // fade-in and slide-down animation 
      speed:       "fast",                          // faster animation speed 
      autoArrows:  false,                           // disable generation of arrow mark-up 
      dropShadows: false                            // disable drop shadows 
   }); 
}
