var $j = jQuery.noConflict(); 
$j(document).ready(function() {






/* Cycle-Plugin-Slideshow für die Startseite */

$j('.slideshow').cycle({ // Großes Bild auf der Startseite
		fx: 'fade' 
	});
	

$j('.slideshowright-1').cycle({ // Rechtes Menü Bildertausch #1
fx: 'none',
		prevNextEvent: 'mouseenter mouseleave',
		next:   '.slideshowright-1', 
    timeout: 0
	});
	
	
	
$j('.slideshowright-2').cycle({ // Rechtes Menü Bildertausch #2
fx: 'none',
		prevNextEvent: 'mouseenter mouseleave',
		next:   '.slideshowright-2', 
    timeout: 0
	});


$j('.slideshowright-3').cycle({ // Rechtes Menü Bildertausch #3
fx: 'none',
		prevNextEvent: 'mouseenter mouseleave',
		next:   '.slideshowright-3', 
    timeout: 0
	});

	
	






/// Funktion von stackoverflow, um URL-Parameter entfernen
function removeParameter(url, parameter)
{
  var urlparts= url.split('?');

  if (urlparts.length>=2)
  {
      var urlBase=urlparts.shift(); //get first part, and remove from array
      var queryString=urlparts.join("?"); //join it back up

      var prefix = encodeURIComponent(parameter)+'=';
      var pars = queryString.split(/[&;]/g);
      for (var i= pars.length; i-->0;)               //reverse iteration as may be destructive
          if (pars[i].lastIndexOf(prefix, 0)!==-1)   //idiom for string.startsWith
              pars.splice(i, 1);
      url = urlBase+'?'+pars.join('&');
  }
  return url;
}




/* Prüft, ob String in URL enthalten ist - Quelle: http://staticfloat.com/2011/06/04/javascript-auf-get-parameter-in-der-url-zugreifen/ */
function getParam(variable){  
     var query = window.location.search.substring(1);  
     var vars = query.split("&");  
      for (var i=0;i<vars.length;i++) {  
            var pair = vars[i].split("=");  
            if(pair[0] == variable){return pair[1];}  
       }       return(false);  
}  








if ($j('hr').length != 0){ // Ersetzen aller HR durch P mit Border :-)

$j("hr").before('<p class="hrLine"></p>');


}


if ($j('div.std').length != 0){  }













/**** Rendert "Druckansicht", also entfernt Header+Footer und blendet Druck-Menü ein ***/

if (getParam("atdprint") != false){

 window.print(); 

}

if (getParam("atdpopup") != false){

  $j("div.header-container").detach();
  $j("div.breadcrumbs").detach();
  $j("p.atd-gototop").detach();
  $j("div.footer-container").detach();
  
  
  
  $j("body").prepend('<p class="printtools"><button class="popupprint">Drucken</button></p>');
  
  if (  getParam("atdpopup") != false){ 
      $j("p.printtools").append(' <button class="popupshow" onclick=" location.href=\'http://'+window.location.hostname+'/media/atd_cms/pdf/'+getParam("atdcms")+'.pdf\'">PDF ansehen</button>');
      $j("p.printtools").append(' <button class="popupsave" onclick=" location.href=\'http://'+window.location.hostname+'/media/atd_cms/pdf/download.php?file='+getParam("atdcms")+'.pdf\'">PDF speichern</button>');
      
      
      }  


  $j("p.printtools button.popupprint").click( function () {  window.print();   });
  

}












// Header: Logo-Hover
$j("a.logo img, #shortcuts a.my-account, #shortcuts a.logout, #shortcuts a.login").fadeTo(0, 0.7);
$j("a.logo img, #shortcuts a.my-account, #shortcuts a.logout, #shortcuts a.login").hover(function(){$j(this).fadeTo(150, 1.0)},function(){$j(this).fadeTo(150, 0.7)});

// Header: Logo-Hover -> Sofortkauf
$j("div.form-search button.button, #newsletter-validate-detail div.block-content div.input-box button.button").fadeTo(0, 0.85);
$j("div.form-search button.button, #newsletter-validate-detail div.block-content div.input-box button.button").hover(function(){$j(this).fadeTo(0, 1.0)},function(){$j(this).fadeTo(0, 0.85)});



// #z57: Startseite: Hover für die Rollover-Boxen, da in CSS nicht möglich ^^ (Kombination Inline_CSS und so)
$j("a.Home3ColRollover").hover( function(){$j(this).css("backgroundPosition","0px -136px"); },
                                function(){$j(this).css("backgroundPosition","0px 0px");});




 
// Header: Cart-Hover
$j("#shortcuts #cart").fadeTo(0, 0.7);
$j("#shortcuts #cart").hover(function(){$j(this).fadeTo(250, 1.0)},function(){$j(this).fadeTo(250, 0.7)});


// Prüft, ob Startseite oder nicht und setzt dann den Wert für die zweite Menü-Reihe (Verschiebung nach Links)
if ($j("#mNav div.nav-container #nav .active").hasClass("active")){ // Menüpunkt ausgewählt
var position = $j("#mNav div.nav-container #nav li.active").position();
$j("#mNav div.nav-container #nav li.active").children("ul.level0").addClass("activeLevel1Menu");
if (position.left != 0){$j("#mNav div.nav-container #nav li.active ul.activeLevel1Menu").css('margin-left', (position.left*(-1))   );}}
else {$j("#mNav li.level0.nav-1 ul.level0").addClass("activeLevel1Menu");}




if ($j('#atd-desc-navi').length != 0){ // BEFINDET SICH IN DER PRODUKT-Ansicht

$j("div.breadcrumbs p.totalAmount").hide();
$j("div.product-Color a.notSelected").fadeTo(0, 0.6);
$j("div.product-Color a.notSelected").hover(function (){$j(this).fadeTo(0, 1.0);},function () {$j(this).fadeTo(0, 0.6);});


$j("#close2").click(function() {$j("#atd-Zoom").hide(); });


$j("div.product-Availability a").hover(
  function () {
  
  var atdUSSize = $j(this).children("span.priceUS").html();
  var atdEUSize = $j(this).children("span.priceEU").html();

  
$j(this).prepend('<div class="atd-sizeMapping"><p class="top6"></p><p class="main6">Gr&ouml;&szlig;e:<br>US: '+atdUSSize+'<br>EU: '+atdEUSize+'</p></div>');  }, 
function () {    $j("div.atd-sizeMapping").detach();  });


$j("#atd-desc-navi ul li").click(function() {
$j("#atd-desc-view div").hide();
$j("#atd-desc-view div div").show();
$j("#atd-desc-navi ul li").removeClass("atd-active");
$j(this).addClass("atd-active");

if($j(this).hasClass("openTab-atdDetails")){$j("#atd-desc-view div.atdDetails").fadeIn("fast");}
else if ($j(this).hasClass("openTab-atdTechnology")){$j("#atd-desc-view div.atdTechnology").fadeIn("fast");}
else if ($j(this).hasClass("openTab-atdBewertung")){$j("#atd-desc-view div.atdBewertung").fadeIn("fast");}});




/// Bilderwechsel Bildertausch //



$j('.more-views li a').bind('click mouseover', function () {
     $j(".atdProductImageView img").attr('src', $j(this).children("span.SmallimgURL").html());
  $j(".atdProductImageView.defaultImage").addClass("realImage").removeClass("defaultImage");
  $j(".atd-Zoom img").attr('src', $j(this).children("span.BigimgURL").html());
});



}














// Erste Ebene: Menüpunkt ausgewählt (global)
if ($j('#mNav div.nav-container li.level0.active').length != 0){

$j("#atdLeftMenu li.level0").hide();
$j("#atdLeftMenu li.level0.active").css("display","block !important"); 


if(($j("#atdLeftMenu li.level1.active").length != 0) && ($j("#atdLeftMenu li.level1.active ul.level1").length != 0)){

$j("#atdLeftMenu li.level1.active li.level2 a span").show();
$j("#atdLeftMenu li.level1.active ul.level1").show();
$j("#atdLeftMenu li.level1.active ul.level2 li span").show();
$j("#atdLeftMenu li.level0.active ul.level1").prev().css({'font-weight':'bold', 'color':'#000'});

$j("#atdLeftMenu ul.level2 li.level3 a").addClass("atd-indented").css({'font-weight' : 'normal !important'});
$j("#atdLeftMenu ul.level2 li.level3 a span:first-child").before('<span style="display: inline">- </span>');



$j("#atdLeftMenu li.level0.active li.level2").css("margin-top","10px");
$j("#atdLeftMenu ul.level0 li.level1").hide();
$j("#atdLeftMenu ul.level0 li.level1.active").show();
$j("#atdLeftMenu li.level0.active a.level-top").hide();




}

$j("li.level0.active").show();
$j("div.nav-container").fadeIn("slow");}



// Startseite -> LeftMenu sichtbar schalten
if (!$j("#mNav div.nav-container #nav .active").hasClass("active")){
  if($j("#atdLeftMenu").length != 0){
  $j("div.nav-container").fadeIn("slow");}
}






/// Erstellt Farbfilter-Feld
if ($j('#narrow-by-list #filter-Farben').length != 0){ // Kategoriebaum "Farbe" gefunden

var status = false;
$j.each($j("#narrow-by-list #filter-Farben a"), function(index, value) {
if (!status){$j("#filter-Farben").append('<div class="colorfield"></div>');status = true;}
var farbe = $j("span",this).html();
var link = $j(this).attr("href");

$j("#filter-Farben div.colorfield").append('<a href="'+link+'" style="background-color:'+farbe+';"  title="'+farbe+'"></a>');
$j("#filter-Farben div.colorfield a").fadeTo(0,0.70);    });

if (status){$j("#filter-Farben dd").detach();$j("#filter-Farben div.colorfield").append('<p class="clear"></p>');}
$j("#filter-Farben").append('<p class="clear"></p>'); /* IE-8 Bugfix, versteht Clear nicht. */


$j("div.colorfield a").live({
        mouseenter: function() {$j(this).fadeTo(0,1.0);},
        mouseleave: function() {$j(this).fadeTo(0,0.7);}
       });


} 


/// Checkout: Input-Feld-Link
if ($j('th.atd-CO-Art').length != 0){
$j('td.atd-qty input').each(function(index) {$j(this).before('<a class="setNumberOfItems"></a>');});}
    
    
// Entferne Kategorie-Filter

$j("#narrow-by-list #filter-Kategorie").detach();
    
    
    
    
// Checkout: Eingabfeld anzeigen
$j("a.setNumberOfItems").click(function() {



if ($j(this).prev("div").length == 0){

selectValues = new Array(0,1,2,3,4,5,6,7,8,9,10);var selectArea = "";
currentValue = $j(this).next("input").val();
$j.each(selectValues, function(i, val){
if (currentValue == val){selectArea = selectArea+'<li class="atd-active">'+val+"</li>";}
else {selectArea = selectArea+"<li>"+val+"</li>";}});
$j(this).before('<div><ul class="selectList">'+selectArea+"</ul></div>");

} else {

$j(this).prev("div").fadeOut("fast").detach();

}});






$j("ul.selectList li").live("click", function() {

$j(this).parents("ul").parent("div").next().next().val($j(this).html());
$j(this).parents("ul").parent("div").fadeOut("fast").detach();
$j("#checkoutForm").submit();
});



// Checkout: Bei Verlassen des Textfelds -> Refresh

$j(".atd-qty input").focusout(function() {$j("#checkoutForm").submit();} );






/// Produkt-ZOOM
if ($j('.atd-Zoom').length != 0){ // Produktbild-Zoom-Funktionalität gefunden

$j("div.atdProductImageView img").mousemove(function(e) {

if($j('div.atdProductImageView.realImage').length != 0){


/* IE-Fix */
  if ( $j.browser.msie ) { 
if ($j('#zoom-helper').length != 0){$j(".atd-Zoom").show();$j("div.atdProductImageView").before('<div id="zoom-helper"></div>');$j("#zoom-helper").hide(); }}


  var msg = "Handler for .mousemove() called at ";
  var pageCoords = "( " + e.pageX + ", " + e.pageY + " )";
  var clientCoords = "( " + e.offsetX + ", " + e.offsetY + " )";
  var ffPos = $j("div.atdProductImageView img").position();

  // Da Chrome und dieser Workaround das gleiche ausliefern, global auf die FF-Lösung gewechselt
  var ffoffsetX = e.pageX - Math.round(ffPos.left);
  var ffoffsetY = e.pageY - Math.round(ffPos.top);
  
 $j("#log").html("");
 $j("#log").html("<p>" +pageCoords + "|"+clientCoords+"|FF: "+ffoffsetX+","+ffoffsetY+"</p>"); 
  
  var padding = 20;
  
  $j("div.atd-Zoom img").css({'margin-top' : ((ffoffsetY*2)*(-1))+padding, 'margin-left' : ((ffoffsetX*2)*(-1))+padding });
  
  if ( $j.browser.msie ) {  $j("#zoom-helper").css({'margin-top' : (ffoffsetY)+5, 'margin-left' : (ffoffsetX)+5 }).fadeTo(0, 0.8);  }
  else {  $j("#zoom-helper").css({'margin-top' : (ffoffsetY)+5, 'margin-left' : (ffoffsetX)+5 }).fadeTo(0, 0.8);  }
  

  
  
  
  } // Ende: div.atdProductImageView.realImage
  
});

  /* IE-Fix: Wenn über das Lupen-Div drübergefahren wird */
  if ( $j.browser.msie ) {  $j("#zoom-helper").mouseenter( function () {  $j(".atd-Zoom").show();$j("div.atdProductImageView").before('<div id="zoom-helper"></div>');$j("#zoom-helper").hide(); alert("i"); }); }




$j('div.atdProductImageView').mouseenter( function () {
if($j('div.atdProductImageView.realImage').length != 0){
  $j(".atd-Zoom").show();$j(this).before('<div id="zoom-helper"></div>');$j("#zoom-helper").hide(); 
  }
});
  
  
  
$j('div.atdProductImageView').mouseleave( function () {
if($j('div.atdProductImageView.realImage').length != 0){
  $j(".atd-Zoom").hide();$j("#zoom-helper").detach();
    }
});







}







if ($j('.product-Availability').length != 0){// Produktgrößenauswahl

$j("#atdProductViewActions a.atd-addToCart").attr('onclick', '');
$j("#atdProductViewActions a.atd-addToCart").addClass("plsSelectSize");


$j.each($j("div.product-Availability a.stock"), function(index, value) {
// padding-left: 6px + padding-right: 6px = 12px offset. -2px wegen Grafik
  $j(this).addClass('strike'+(14+($j(this).width())));      });



$j("div.product-Availability a.stock1",this).click( function () {
$j("#atdProductViewActions a.atd-addToCart").removeClass("plsSelectSize");
$j("#atdProductViewActions a.atd-addToCart").attr('onclick', "window.location.href = '"+$j(this).children("span.addtoCartURL").html()+"'");
$j("div.product-Availability a").removeClass("selectedSize");
$j(this).addClass("selectedSize");});

// Same Code, nur touchend

$j("div.product-Availability a.stock1",this).live('touchend', function() {
$j("#atdProductViewActions a.atd-addToCart").removeClass("plsSelectSize");
$j("#atdProductViewActions a.atd-addToCart").attr('onclick', "window.location.href = '"+$j(this).children("span.addtoCartURL").html()+"'");
$j("div.product-Availability a").removeClass("selectedSize");
$j(this).addClass("selectedSize");});





// Das Gleiche für die Größen anfragen:

$j("#atdProductViewActions a.atd-addToCart").click( function () {
if ($j("#atdProductViewActions a.atd-addToCart").hasClass("plsSelectSize")){
$j(this).before('<div class="errorSize">Bitte wählen Sie eine Größe aus!</div>');
$j("div.errorSize").fadeTo('fast', 0.95);
$j("div.errorSize").fadeTo(2000, 0.94);
$j("div.errorSize").fadeOut('fast',function(){$j("div.errorSize").detach();} );
}});



// Mit Größenauswahl / Größe anfragen: Resettet Status der Links
$j("#atdProductViewActions a.atd-askSize").attr('title', $j("#atdProductViewActions a.atd-askSize").attr('href'));
$j("#atdProductViewActions a.atd-askSize").removeAttr("href");
$j("#atdProductViewActions a.atd-askSize").addClass("plsSelectSizeforAsk");

// Mit Größenauswahl / Weiterempfehlen: Resettet Status der Links
$j("#atdProductViewActions a.atd-wishlist").removeAttr("href");
$j("#atdProductViewActions a.atd-wishlist").addClass("plsSelectSizeforAsk");





/**** START: GRÖSSE ANFRAGEN *******/
$j("#atdProductViewActions a.atd-askSize").click( function () {  
  if ($j("#atdProductViewActions a.atd-askSize").hasClass("plsSelectSizeforAsk")){
  $j(".product-Availability p").before('<div class="errorSize" style="margin-top: 18px;">Bitte wählen Sie eine Größe aus!</div>');
  
  if ($j(".product-Availability a.allSizesHelper").length == 0){
  $j(".product-Availability").addClass("selectNotAvailableMode");
  $j(".product-Availability").append('<a class="allSizesHelper">Alle Größen anzeigen</a>');}
  
  
  
  $j(".product-Availability a.stock").click( function () { 
    if ($j(".product-Availability").hasClass("selectNotAvailableMode")){
 
  $j(".product-Availability a.stock").removeClass("selectedNotAvailable");
  $j(this).addClass("selectedNotAvailable");
  
  var currentURL = $j("#atdProductViewActions a.atd-askSize").attr("title");
  var selectedSize = $j("span.priceUS",this).html();
  
  var currentURL = currentURL.substr(0, currentURL.length-1);
  
  
  $j("#atdProductViewActions a.atd-askSize").attr('onclick', "window.location.href='"+currentURL+"&size="+selectedSize+"'");
  $j("#atdProductViewActions a.atd-askSize").removeClass("plsSelectSizeforAsk");
  
  $j("#atdProductViewActions a.atd-askSize").before('<div class="successSize" style="margin-top: -11px;">Jetzt Anfrage <br>starten!</div>');
  $j("div.successSize").fadeTo('fast', 0.95);
  $j("div.successSize").fadeTo(2000, 0.94);
  $j("div.successSize").fadeOut('fast',function(){$j("div.successSize").detach();}); 
  }});
  
  $j(".product-Availability a.allSizesHelper").live("click", function() {
      $j(".product-Availability a.allSizesHelper").detach();
      $j(".product-Availability a.stock1").show();
      $j(".product-Availability").removeClass("selectNotAvailableMode");
      $j("div.errorSize").detach();
      $j(".product-Availability a.stock").removeClass("selectedNotAvailable");
      $j("#atdProductViewActions a.atd-askSize").removeAttr("onclick");
      $j("#atdProductViewActions a.atd-askSize").addClass("plsSelectSizeforAsk");   });
  
  $j("div.errorSize").fadeTo('fast', 0.95);
  $j("div.errorSize").fadeTo(2000, 0.94);
  $j("div.errorSize").fadeOut('fast',function(){$j("div.errorSize").detach();}); 
  $j(".product-Availability a.stock1").hide();
  
}});
/**** ENDE: GRÖSSE ANFRAGEN *******/




/**** START: Weiterempfehlen mit Größe ** Redundant :) *******/
$j("div.atdInnerBoxRight a.atd-wishlist").click( function () {
  if ($j("#atdProductViewActions a.atd-wishlist").hasClass("plsSelectSizeforAsk")){
  $j(".product-Availability p").before('<div class="errorSize" style="margin-top: 18px;">Bitte wählen Sie eine Größe aus!</div>');
  
  if ($j(".product-Availability a.allSizesHelper").length == 0){
  $j(".product-Availability").addClass("selectNotAvailableMode");
  $j(".product-Availability").append('<a class="allSizesHelper">Alle Größen anzeigen</a>');}
 
 

 
  $j(".product-Availability a.stock1,.product-Availability a.stock").click( function () { 
    if ($j(".product-Availability").hasClass("selectNotAvailableMode")){
 
  $j(".product-Availability a.stock").removeClass("selectedNotAvailable").removeClass("selectedSize");  
  $j(".product-Availability a.stock1").removeClass("selectedSize").removeClass("selectedNotAvailable");

  $j(this).addClass("selectedNotAvailable").addClass("selectedSize");
  
  
  var addtoWishlistURL = $j("span.addtoWishlist",this).html();
  
    
  
  $j("#atdProductViewActions a.atd-wishlist").attr('onclick', "window.location.href='"+addtoWishlistURL+"'");
  $j("#atdProductViewActions a.atd-wishlist").removeClass("plsSelectSizeforAsk");
  
  $j("#atdProductViewActions a.atd-wishlist").before('<div class="successSize" style="margin-top: -11px;">Jetzt Anfrage <br>starten!</div>');
  $j("div.successSize").fadeTo('fast', 0.95);
  $j("div.successSize").fadeTo(2000, 0.94);
  $j("div.successSize").fadeOut('fast',function(){$j("div.successSize").detach();}); 
  }});
  
  $j(".product-Availability a.allSizesHelper").live("click", function() {
      $j(".product-Availability a.allSizesHelper").detach();
      $j(".product-Availability a.stock1").show();
      $j(".product-Availability").removeClass("selectNotAvailableMode");
      $j("div.errorSize").detach();
      $j(".product-Availability a.stock").removeClass("selectedNotAvailable").removeClass("selectedSize");
      $j("#atdProductViewActions a.atd-wishlist").removeAttr("onclick");
      $j("#atdProductViewActions a.atd-wishlist").addClass("plsSelectSizeforAsk");   });
  
  $j("div.errorSize").fadeTo('fast', 0.95);
  $j("div.errorSize").fadeTo(2000, 0.94);
  $j("div.errorSize").fadeOut('fast',function(){$j("div.errorSize").detach();}); 
  //Zeige alle Produkte an: $j(".product-Availability a.stock1").hide();
}});
/**** ENDE: Weiterempfehlen mit Größe *******/











}


















/// Katalog  || Vorsicht: Schrottfunktion !!!! Lädt die gesamte Webseite nochmals, nur ohne die Farbauswahl. 
/// Und dieses DOM wird dann geladen und zerpflückt, um die restlichen Farben rauszufinden. 

if ($j('.atd-left-col ol.currently .atd-active-filterbox-Farben').length != 0){

  var pathname = window.location.href;
  
  pathname = pathname.replace('color=', 'novalue='); 
  pathname = removeParameter(pathname,"novalue");
  
  
  
  // colorValueID ist ein DIV mit dem aktuellen Farbwert (== $_GET["color"] )
  var colorFieldID = $j("#colorValueID").html(); // FarbID, z.b. 191
  var colorLabelID = $j("#colorLabelID").html(); // Farbbezeichnung, z.b. "grey"
  
// Prüfen ob überhaupt ein Filter vorhanden. Wenn nein, dann blende "alle Filter entfernen" aus  
var removeAllLinkVisiblility = true;
$j.each($j("div.block-content ol.currently li"), function(index4, value4) {
  if($j(this).is(":visible")){
    if(!$j(this).hasClass("atd-active-filterbox-Farben")){
      removeAllLinkVisiblility = false;
    }
   }
});


if(removeAllLinkVisiblility){$j("div.block.block-layered-nav div.actions").hide();}


  
  // Vorarbeit: Damit es keine ewige Wartezeit gibt, da ja auf das DOM gewartet werden muss,
  // wird schon ein Farbfeld mit der aktiven Farbe erzeugt + ein AJAX-Lade-Icon
  $j("#narrow-by-list").prepend('<div id="filter-Farben" class="filterbox"></div>');
  $j("#filter-Farben").append('<dt>Farben</dt><div class="colorfield"></div>');
  $j("#filter-Farben div.colorfield").append('<a style="background-color:'+colorLabelID+';"></a> <a class="loading-color"></a>');
  $j("#filter-Farben div.colorfield a").fadeTo(0,0.75);  
  $j("#filter-Farben div.colorfield").append('<p class="clear"></p>');
  $j("#filter-Farben").append('<p class="clear"></p>');  /* IE8 */
  $j(".atd-active-filterbox-Farben").hide(); 
  

$j.ajax({type: "POST",url: pathname,   data: "",success: function(msg){

  // Splitet das erhaltene DOM. Zuerst Absätze entfernen (replace), dann den richtigen DIV wählen (split)
  // Dann das erste Array-Element wählen, da ja nach "</div>" gesplitet wurde
  
  msg = msg.replace(/[\r\n]+/g, "");msg = msg.split("filter-Farben\">");
  msg = msg[1];msg = msg.split("</div>");
  $j("#filter-Farben").detach();
  $j("#narrow-by-list").prepend('<div id="filter-Farben" class="filterbox">'+msg[0]+'</div>');
  
  // Gibt das erste Array-Element aus. D.h. die ganze FarbfilterBox ohne Farbselektion
  // alert(msg[0]);


var status = false;
$j.each($j("#narrow-by-list #filter-Farben a"), function(index, value) {

//X//   Wenn Status noch "false" ist (Standardwert), dann wird ein DIV angehängt. Einmalige Aktion (= erster Durchlauf)
 if (!status){$j("#filter-Farben").append('<div class="colorfield"></div>');status = true;}
  
// Es wird die Farbe des each-Vorgangs ausgelesen. Und den Link. 
  var farbe = $j("span",this).html();
  var link = $j(this).attr("href");
  
  // Nun wird eine Farbfläche erzeugt (inkl. Hintergrundgrafik) und in das eben erzeugte, 
  // neue DIV eingefügt. Und transparenter gesetzt.
  $j("#filter-Farben div.colorfield").append('<a href="'+link+'" style="background-color:'+farbe+';" title="'+farbe+'"></a>');
  $j("#filter-Farben div.colorfield a").fadeTo(0,0.75);    
});




// Wenn Status = True, d.h. es wurde mind. eine ausgewählte Farbe gefunden, dann wird die originale Darstellung entfernt. 
// Und ge-"clear"-ed, damit es keine Darstellungsprobleme mit den floatenden Farbfeld-Boxen gibt.
if (status){$j("#filter-Farben dd").detach();$j("#filter-Farben div.colorfield").append('<p class="clear"></p>');}

 /* IE-8 Bugfix, versteht Clear nicht. */
$j("#filter-Farben").append('<p class="clear"></p>'); 





// Geht nun alle aktiven Farbfeld-Boxen durch. Sucht sich die aktuell ausgewählte Farbe
// raus und bearbeitet den Link + roter Rahmen :-)
$j.each($j("div.colorfield a"), function(index, value) {

  urlvalue = $j(this).attr("href");
  urlvalue2 = urlvalue.replace('color='+colorFieldID, ''); 
  
  if(urlvalue != urlvalue2){
    $j(this).css("border","1px solid #111").attr("href",pathname).attr("title","Jetzt Farbfilter verwerfen.").fadeTo(0,1.00).addClass("selectedColorField52");  
  } 
  else {$j(this).addClass("nonselectedColorField52"); }
  
  
  
});





}});

$j("div.colorfield a.nonselectedColorField52").live({
        mouseenter: function() {$j(this).fadeTo(0,1.0);},
        mouseleave: function() {$j(this).fadeTo(0,0.7);}
});

}












/// Katalog wenn DropDown da: iPad-DOM Verschieben für Select-Feld /////
if ($j('.atd-wrapper-catalog').length != 0){  // Login-Form

$j.each($j(".atd-wrapper-catalog .iPadDropDown"), function(index, value) { // Geht alle Flyout-Menüs durch


$j(this).parent().after('<select class="iPadDropDown">'+$j(this).html()+'</select>');
$j(this).detach();
});

if ($j('.iPadDropDown').length != 0){
$j(".filterbox dd").detach();
}

$j("select.iPadDropDown").live({
        change: function() {window.location.href = $j("option:selected",this).attr("href");}
});


}








// Login-Form
if ($j('div.account-login').length != 0){  // Login-Form

$j("div.registered-users button").click( function() { // Validate AGB-Checkbox
  if(!$j("#is_accepted").is(':checked')){ $j('div.sbcheckbox label[for="is_accepted"]').css("color","red");}
  else { $j('div.sbcheckbox label[for="is_accepted"]').css("color","#666");}
});

}



/* Befindet sich in Customer-Backend */
if ($j('div.atd-main-container-userbackend').length != 0){


  // Befindet sich beim "Mein Bestellung-Tab". 
  if ($j('div.atd-box-sales-history').length != 0){

$j("p.back-link a").addClass("atd-back-link-sales-history");
$j("div.atd-col-main-userbackend  .buttons-set").addClass("atd-noBorder").addClass("atd-noPadding");


  }
}






/* Befindet sich in New-One-Page-Checkout */
if ($j('.atd-new-onepage-checkout-wrapper').length != 0){

$j("#secondrow").detach();
$j("div.quick-access").detach();

//$j("div.atd-new-onepage-checkout-wrapper #cart").html("");
$j("div.atd-new-onepage-checkout-wrapper #cart").html($j("#backtoshoplink").html()).addClass("noBackgroundImage");

/* Wandelt alle Sonderzeichen wie "&quot;" z.B. in doppelte Anführungszeichen um */
/* Fehler: Martin &quot;Mäx&quot; Meier => Richtig: Martin "Max" Meier */
   $j.each( $j("#co-billing-form ul.form-list select#billing-address-select option, #checkout-step-shipping ul.form-list select#shipping-address-select option"), function(index, value) {
      $j(this).html($j(this).text());
   });



}







/**** Wishlist: View *****/
if ($j('div.atd-wishlist').length != 0){
$j("#atd-wishlist-view-texarea").click( function() {
  if (!$j(this).hasClass("empty")){
    $j(this).html("").addClass("empty");
  }
});
}
/*************************/




/* ATD Giftcode: accessoires/geschenkgutschein.html */
if ($j('.atd-giftcode-wrapper').length != 0){




  $j(".atd-addToCart").submit( function() { "submit";
    if ($j("#recipient_type_myself:checked").val() == "0"){
      if (!$j("#atd-add-email").is(":checked") &&  !$j("#atd-add-postal").is(":checked")  ){
      alert("Bitte wählen Sie die Versandart aus: Per Post oder Per Brief");}
    }
  });






$j("div.product-collateral").detach();
$j("div.product-Facebook").detach();

/// Ändert in der Preisbox die Menge, wenn Menge in der Dropdown geändert wurde (Gutscheinwert)
$j("#amount").change(function () {$j("label.atd-priceValue").html($j("option:selected",this).html());});



$j('[name=recipient_type]').change( function() {
    if ($j("#recipient_type_myself:checked").val() == "0") {$j("p.atd-giftcode-new-forms").hide();}
    if ($j("#recipient_type_someone:checked").val() == "1") {$j("p.atd-giftcode-new-forms").show();}
});


$j('p.atd-add-postal input[type=checkbox]').change( function() {
  /*B62*/$j("#recipient_address").val("abweichenden Lieferanschrift a.d. Kasse angeben");
  if ($j(this).is(':checked')){ $j(".atd-recipient_address").show();}
  else {$j(".atd-recipient_address").hide();}
});

$j('p.atd-add-email input[type=checkbox]').change( function() {
  /*B62*/$j("#recipient_address").val("abweichenden Lieferanschrift a.d. Kasse angeben");
  if ($j(this).is(':checked')){ $j(".atd-recipient_email").show();}
  else {$j(".atd-recipient_email").hide();}
});



$j('#recipient_message, #recipient_name').keyup( function() {

var giftpreview = "";

if ($j('#recipient_name').val().length > 0){ // Eingabe von EmpfängerName
  giftpreview = "<b>An: </b>"+$j('#recipient_name').val()+"<br>";}

if ($j('#recipient_message').val().length > 0){ // Eingabe von Nachricht
  giftpreview = giftpreview + $j('#recipient_message').val().replace(/\n/g,'<br>');}


$j("#atd-textpreview").html( giftpreview );



});






}
/******************************************/










// TopMenu: Fix für Spalten: Nach jeder dritten Spalte wird nun ein Clear eingefügt
if ($j('#mNav div.nav-container li.level0 ul.level1').length != 0){
$j.each($j("#mNav div.nav-container li.level0 ul.level1"), function(index, value) { // Geht alle Flyout-Menüs durch

    $j("#mNav div.nav-container ul.level1 li.level2").addClass("thirdColBreak");
    var counter = 0;
    var globalcounter = 0;

      $j.each($j(this).children("li.level2"), function(index2, value2) {
      
        if(counter==3){$j(this).before('<p class="clear atd-spacer"></p>');counter = 0;}
        
      counter = counter+1;  globalcounter = globalcounter+1;});

  
      if (globalcounter == 1){$j(this).css("width","200px"); }
      else if (globalcounter == 2){$j(this).css("width","400px"); }
      else if (globalcounter >= 3){$j(this).css("width","600px"); }

});


}











/* Newsletter entfernen des aktuellen Werts */
if($j(".atd-newsletter-subscribe").length != 0){
  $j(".atd-newsletter-subscribe").focus( function() {
    if(!$j(this).hasClass("cleared")){
      $j(this).addClass("cleared").val("");
    }
  });
}
















// Schaltet den GoToTop-Link komplett aus anhand der ID "#noGoToTopLink"

if ($j('#noGoToTopLink').length != 0){$j("p.atd-gototop").detach();}




//// IE8-Bugfixes, z.b. weil der Steinzeitbrowser noch kein last-child kann ...

$j("#wideBanner3Col table td:last-child").addClass("last1").css('textAlign', 'right'); // Startseite: 3er Spalte: Letzte Box rechtsbündig









});


