var bbloginUse=false;
$(document).ready(function(){
  // ### PNG-FIX ###
  $(document).pngFix();
  //
});
// Elemente Einblenden
$(document).ready(function(){
  $("#showBBLogin").mouseover(function(){
    $("#bigboxlogin").addClass("hovered");
  }).mouseout(function(){
    $("#bigboxlogin").removeClass("hovered");
  });
  $("#boxlogin").mouseover(function(){
    $("#bigboxlogin").removeClass("noUse");
  }).mouseout(function(){
    $("#bigboxlogin").addClass("noUse");
  });
  $("#bigboxlogin input").focusin(function(){
    $("#bigboxlogin").addClass("focused");
  }).focusout(function(){
    $("#bigboxlogin").addClass("progress").removeClass("focused").fadeTo(100, 1,  function(){
      $("#bigboxlogin").removeClass("progress");
	});
  });
  
  $("#boxcart").mouseover(function(){
    $("#cartSumDetail").addClass("hovered");
  }).mouseout(function(){
    $("#cartSumDetail").removeClass("hovered");
  });
});
// Suchlabel


$(document).ready(function(){
  $(".jLabel").css({position : 'absolute', color : '#999999'});
  $(".jLabel label").click(function(){
    var nextField = $(this).attr("for");
	$("input[name='" + nextField + "']").focus();
	$(this).parent("span").hide();
  });
 
  var defaults=$(".jField input");
  var defaultsVal=$(".jField input").val();

  for(i=0;i<defaults.length;i++){
    if(defaults[i].value){
	  var dID=defaults[i].name;
	  //$("#social").append(dID + "<br />");
	  $("label[for='"+dID+"']").parent("span").hide();
    }
  }
  
  $(".jField input").focusin(function(){
    var jActID = $(this).attr("name");
	var jActLabel = $("label[for='"+jActID+"']");
	jActLabel.parent("span").hide();
  }).focusout(function(){
    var jLeftID = $(this).attr("name");
	var jLeftLabel = $("label[for='"+jLeftID+"']");
	var jLeftIn=$(this).val();
	if(jLeftIn==''){
	  jLeftLabel.parent("span").show();
    } else {
	  jLeftLabel.parent("span").hide();
    }
  });
});

// PRODUKT Toggle
$(document).ready(function(){
  if($(".toggleBox")){
    $(".toggleBox").hide();
  }
  $(".toggleBox:first").show();
  $("h6").click(function(){
    $(this).next(".toggleBox").toggle();
  });
});

// Teaser
$(document).ready(function(){
  var aniActive=1;
  var t = 4700;
  var tNext = 1000;
  var z = 1;
  var stopZ = 0;
  var teaserC=$(".teaserMainElement").length;
  //alert(teaserC);
  $(".teaserMainElement").hide();
  $(".El0").css({zIndex : z}).show();
  
  if(teaserC>1){
    animateTeaser();
  }
  
  function animateTeaser(){
    z=1;
    for(j=0;j<teaserC;j++){
	  if(aniActive==1){
        $(".El" + j).css({zIndex : (z+j)}).delay(t*j).fadeIn(tNext, function(){
          //$("#social").append(j + '<br />');
		  j++;
		  if(j==(teaserC*2) && aniActive==1){
		    $(".El0").show();
			for(c=1;c<(teaserC-1);c++){
			  $(".El" + c).hide();  
			}
		    //$(".El1").hide();
		    //$(".El2").hide();
		    $(".El" + (teaserC-1)).css({zIndex : (z+teaserC-1)}).delay(t).fadeOut(tNext, animateTeaser);
		  }
	    });
	  }
    }
  };
  // NAVI
  if(teaserC>1){
    $("#teaseNav").show();
    $("#teaseNav a").click(function(){
      aniActive=0;
	  var layer=($(this).html())-1;
	  $(".El" + layer).stop().css({zIndex : (stopZ+100), opacity : '1', display : 'none'}).fadeIn(tNext);
	  stopZ++;
     return false;
    });
  }
  
});

// CHECKOUT
$(document).ready(function(){
  $(".detailShip").hide();
  
// ---------->> A/B-Testing Hermes-Zahlen 20100806 <<----------//
if(1){  
  // A
  $(".openShip:checked").parents().next(".detailShip").show();
  // B
} else {  
    var shippingDetails = $(".detailShip");
	if(shippingDetails.length!=0) {shippingDetails[2].style.display = 'table-row';}
}	
// ---------->> A/B-Testing Hermes-Zahlen ENDE 20100806 <<----------//
  
  $(".openShip").click(function(){
    $(".detailShip").hide();
    $(this).parents().next(".detailShip").show();
  });
  
  
  $(".detailPay").hide();
  $(".openPay:checked").parents().next(".detailPay").show();
  $(".openPay").click(function(){
    $(".detailPay").hide();
    $(this).parents().next(".detailPay").show();
  });
  $(".closePay").click(function(){
    $(".detailPay").hide();
  });  
});

// SPINABLE
$(document).ready(function(){
  var isAnimating=false;
  $("#topSlider").mouseenter(function(){
    isAnimating=true;
  }).mouseleave(function(){
    isAnimating=false;
  });
						   
  $("#balken").css({
    position : 'relative',
    background : '#E0E0E0',
    height : '2px',
    margin : '10px'
  });
  $("#innerBalken").css({
    position : 'absolute',
	background : '#999',
	height : '2px',
	width : '1%'
  });
  var countChildren = $("#spinable").children().length;
  $("#spinable").append($("#spinable li:first-child").clone());
  $("#spinable").prepend($("#spinable li:nth-child(" + countChildren + ")").clone());
   var fieldWidth = $("#spinable").parent().outerWidth();
  var areaWidth = (fieldWidth*countChildren);
  var isAnimating = false;  
  $("#spinable").css({
    left: '-' + fieldWidth + 'px'
  });
  function spinFF(){
    if(!isAnimating){
      $("#spinable").animate({
        left: '-='+fieldWidth+'px'
      },'',function(){
        if( $("#spinable").css('left') == '-'+(areaWidth+fieldWidth)+'px'){
	      $("#spinable").css({
	        left: '-' + fieldWidth + 'px'
	      });
	    }
		isAnimating = false;
      });
	  isAnimating = true;
	  $("#innerBalken").stop().css({width : '0%'});
	}
  }  
  function spinRW(){
    if(!isAnimating){
      $("#spinable").animate({
        left: '+='+fieldWidth+'px'
      },'',function(){
        if($("#spinable").css('left')>=0+'px'){
	      $("#spinable").css({
	        left: '-' + (fieldWidth*countChildren) + 'px'
	      });
	    }
	    isAnimating = false;
      });
	isAnimating = true;
	}
  }  
  
  $("#saNext").click(function(){
    spinFF();
	window.clearInterval(autoSpin);
	return false;
  });
  
  $("#saPrev").click(function(){
    spinRW();
	window.clearInterval(autoSpin);
	return false;
  });
  
  function showSlideShow(){
	$("#innerBalken").animate({
	  width : '100%'
	},8000)
  }
  
  //showSlideShow();
  
  var autoSpin = window.setInterval(function(){
    spinFF();
	showSlideShow();
  }, 8000);
  
});

// DMDI 140px × 245px
/*$(document).ready(function(){
  $(".dmdi").mouseenter(function(){
    $(".dmdi img").css({ width : '140px', height : '245px', margin : '-70px 0 0 -40px'})
  }).mouseleave(function(){
    $(".dmdi img").css({ width : '60px', height : '105px', margin : '0'})
  });
});*/

// CARTANIMATE
function cartAnimate(){
  $(document).ready(function(){
    $("#cartSumDetail").addClass('hovered').delay(2000).animate({opacity : '0'},500,'',function(){
      $("#cartSumDetail").removeClass('hovered').css({opacity : '1'});
	});
  });
}

// FAQ
$(document).ready(function(){
  $(".toggleFaq").hide();
  $(".toggleFaq").css({margin : '0 5px'})
  $(".faqOpener").css({cursor : 'pointer', background: '#ebf2d0 url(templates/pharmeo/layout/h6toggle.jpg) no-repeat right 4px', padding : '5px', margin : '0 10px 1px 10px', width : '526px'});
  $(".faqOpener").click(function(){
    $(this).next(".toggleFaq").toggle();
	return false;
  });
});

// REZEPT HINWEIS
$(document).ready(function(){
  $("#idprice").parent("div").after('<div id="rezHinweis"><p>Bitte beachten Sie, dass nicht-verschreibungspflichtige Medikamente, Nahrungsergänzungsmittel, Hilfsmittel und Medizinische Geräte in vielen Fällen von der Krankenkasse nicht bzw. nicht vollständig übernommen werden. Die genaue Prüfung der Kostenübernahme durch Ihre Krankenkasse erfolgt erst nach Eingang Ihres Rezeptes bei pharmeo. Die für Sie anfallenden Rezeptgebühren können daher vom angezeigten Betrag abweichen.<p></div>');
  $("#rezHinweis").hide();
  //$("input:radio[name='id[1]']")
  var felder = $("td.main input");
  $("td.main input").click(function(){
    for (i=0;i<felder.length;i++){
	  if(i>1){
        if(felder[i].checked==true){
	      //alert('hinweis');
		  $("#rezHinweis").show();
	    }
	  } else {
	    $("#rezHinweis").hide();
	  }
    }
  });
});

// BOOKMARKS

$(document).ready(function(){
  $(".bookmarks img").hover(function(){
    if($(this).attr('title')){
      $(".bookmarksHead").html("Weitersagen bei <strong>"+$(this).attr('title')+"</strong>");
	}
  }, function(){
    $(".bookmarksHead").html("Weitersagen");
  });
});

// Email
function InsertMail(mailnam,mailsvr,maildom,text){
  if(text==""){
    document.write('<a href="mailto:'+mailnam+'@'+mailsvr+'.'+maildom+'">'+mailnam+'@'+mailsvr+'.'+maildom+'</a>');
  } else {
    document.write('<a href="mailto:'+mailnam+'@'+mailsvr+'.'+maildom+'">'+text+'</a>');
  }
}


