(function($) {
  $.fn.fullBg = function(){
    var bgImg = $(this);
    
    bgImg.addClass('fullBg');
    
    function resizeImg() {
      var imgwidth = bgImg.width();
      var imgheight = bgImg.height();
      
      var winwidth = $(window).width();
      var winheight = $(window).height();
      
      var widthratio = winwidth / imgwidth;
      var heightratio = winheight / imgheight;
      
      var widthdiff = heightratio * imgwidth;
      var heightdiff = widthratio * imgheight;
    
      if(heightdiff>winheight) {
        bgImg.css({
          width: winwidth+'px',
          height: heightdiff+'px'
        });
      } else {
        bgImg.css({
          width: widthdiff+'px',
          height: winheight+'px'
        });    
      }
    } 
    resizeImg();
    $(window).resize(function() {
      resizeImg();
    }); 
  };
})(jQuery)


jQuery.easing['BounceEaseOut'] = function(p, t, b, c, d) {
  if ((t/=d) < (1/2.75)) {
    return c*(7.5625*t*t) + b;
  } else if (t < (2/2.75)) {
    return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
  } else if (t < (2.5/2.75)) {
    return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
  } else {
    return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
  }
};    
  
jQuery.noConflict();
jQuery(document).ready(function()
{ 
  /*
   * Animierte Figur
   */
  /*jQuery("#background").fullBg();*/
  
  
  var randomnumber=Math.floor(Math.random()*4);
  
  //alert (randomnumber);
  
  jQuery(".figur").hide();
  if (randomnumber==0)
  {
    jQuery(".figur.rechts.oben").show();
    jQuery(".figur.rechts.oben").animate({ 
        right: "-132"
    }, 3000 );
  }
  else if(randomnumber==1)
  {
    jQuery(".figur.links.oben").show();
    jQuery(".figur.links.oben").animate({ 
        left: "-132"
    }, 3000 );
  }
  else if(randomnumber==2)
  {
    jQuery(".figur.links.unten").show();
    jQuery(".figur.links.unten").animate({ 
        left: "-132"
    }, 3000 );
  }
  else if (randomnumber==3)
  {
    jQuery(".figur.rechts.unten").show();
    jQuery(".figur.rechts.unten").animate({ 
        right: "-132"
    }, 3000 );
  }
  
  /*
   * Sprachauswahl anpassen
   */
  
  if (jQuery(".tx-srlanguagemenu-pi1 div:eq(0)").hasClass("NO"))
  {
    jQuery(".tx-srlanguagemenu-pi1 div:eq(0) .tx-srlanguagemenu-pi1-flag").attr("src","fileadmin/images/de_inactiv.png");
  }
  else
  {
    jQuery(".tx-srlanguagemenu-pi1 div:eq(0) .tx-srlanguagemenu-pi1-flag").attr("src","fileadmin/images/de.png");
  }
  
  if (jQuery(".tx-srlanguagemenu-pi1 div:eq(1)").hasClass("NO"))
  {
    jQuery(".tx-srlanguagemenu-pi1 div:eq(1) .tx-srlanguagemenu-pi1-flag").attr("src","fileadmin/images/en_inactiv.png");
  }
  else
  {
    jQuery(".tx-srlanguagemenu-pi1 div:eq(1) .tx-srlanguagemenu-pi1-flag").attr("src","fileadmin/images/en.png");
  }
  
  jQuery('.navi_level_1 li').each(function(index) {
    jQuery(this).addClass("item_"+index);
  });
  
  jQuery('.start .produkte li').each(function(index) {
    jQuery(this).addClass("item_"+index);
  });
  
  jQuery('.tx-bildboxen-pi1 div.infobox:last').css("margin-right","0px");
  
  
  
  /*
   * SEO Text unten
   
  jQuery('.seo_text h1').click(function() {
        jQuery('.seo_text .text').slideToggle('slow', function() {
          if ( jQuery('.seo_text .text').is(':visible')){
                var pos=jQuery("body").height();
                jQuery('html,body').animate({scrollTop: pos}, 500);
            }
        });
    });*/

  //Slider Startseite
   jQuery(".start .tx-bildboxen-pi1 div.infobox").each(function() {
     
     jQuery(this).replaceWith("<li class='infobox'>"+jQuery(this).html()+"</li>");
   });

   jQuery(".start .tx-bildboxen-pi1").each(function() {
     
     jQuery(this).replaceWith("<ul class='slider'>"+jQuery(this).html()+"</ul>");
   });
  
  jQuery('.slider').jcarousel(
  {
    scroll: 1,
    easing:"BounceEaseOut",
    animation:2500,
    auto: 3,
    wrap: 'circular'

  });
  
  
  
});


jQuery(document).ready(function(){
       var ankerC = document.URL.split('#')[1];
       if(!ankerC){
        } else {
      var container = '#' + ankerC.split('-')[0];
     var elementId = parseInt(ankerC.split('-')[1])-1;
     jQuery(container).accordion({
         autoHeight:false, active:elementId, animated:'slide'
     });
        }
});

/*

jQuery("[id^='jfmulticontent']").ready(function(){
    jQuery("[id^='jfmulticontent']").anythingSlider(document.URL.split('#')[1].split('c')[1]);
    //alert('Now on page ' + document.URL.split('#')[1].split('c')[1]);  
});

*/


