$(document).ready(function(){
  //setupZoom();
	
	// Carsten Bleicker - Hover Listen
	$("a[class^=thumbnail thumbnail]*").each(function(item) {
		
		var className = $(this).attr('class');
		var zoomClassName = className.split("_");
		var lastPos = zoomClassName.length;
		
		$("a[class^=zoom zoom_"+zoomClassName[lastPos-1]+"]*").hide();
		
	});
	
	// Carsten Bleicker - Hover Listen
	$("a[class^=thumbnail thumbnail]*").hover(function(item) {
		
		$("a[class^=zoom]*").hide();
		
		var className = $(this).attr('class');
		var zoomClassName = className.split("_");
		var lastPos = zoomClassName.length;
		
		$("a[class^=zoom zoom_"+zoomClassName[lastPos-1]+"]*").show();
		
	});
	
  
  $('#detailsubmit').click(function(event){
  	var $amount = $('#amount');
	if($amount.val()=="") {
		$('#amount').val('1');	
	}	
  });
  
  
  $('div.tx-cenafloorpass-pi1 div.autosubmit input.btn').hide();
  
  $('div.autosubmit #tx_cenafloorpass_pi1_gendersize').change(function(event){
  	this.form.submit();
  });
  
  $('div.autosubmit #tx_cenafloorpass_pi1_currency').change(function(event){
  	this.form.submit();
  });
  
  
  var browserwidth = $(window).width();
  var imagewidth = $('a.zoomout img').width();
  var imageheight = $('a.zoomout img').height();
  var imageprop = (browserwidth-5)/imagewidth;
  var imagevsize = imageheight*imageprop;
  var imagewidth = browserwidth-5;
  var imageheight = Math.ceil(imagevsize);
  $('a.zoomout img').attr('width',imagewidth).attr('height',imageheight);
  
  //setupZoom();
  
  $('.zoomin').click(function(event){
  	$('div.page').fadeOut('slow');
	$('div#logolayer').fadeOut('slow');	
  });
  
  $('#ZoomImage').click(function(event){
  	$('div.page').fadeIn('slow');
	$('div#logolayer').fadeIn('slow');		
  });
  
  $("h1#area_delivery_address_klick").css({'cursor' : 'pointer'});
  $("dl#area_delivery_address").css({'display' : 'none'});
  $("h1#area_delivery_address_klick").click(function(){
	  $("dl#area_delivery_address").slideToggle("slow");
	  $(this).toggleClass("active");
	});
  
  // Zoomtext einblenden
  $('a.zoomin img').each(function(index){
    var $picture = $(this);
	$picture.parent().append("<div class='enlarge'>Click to zoom</div>");
	var $enlarge = $picture.parent().find('.enlarge');
	$enlarge.hide();
	$picture.mouseover(function(){
	  $enlarge.fadeIn('fast');
	}).mouseout(function(){
	  $enlarge.fadeOut('fast');
	});
  });
  
  // Zoomtext einblenden
  $('a.zoomout img').each(function(index){
    var $picture = $(this);
	$picture.parent().append("<div class='enlarge'>Click to close Zoom</div>");
	var $enlarge = $picture.parent().find('.enlarge');
	$enlarge.hide();
	$picture.mouseover(function(){
	  $enlarge.fadeIn('fast');
	}).mouseout(function(){
	  $enlarge.fadeOut('fast');
	});
  });
  
  // Modalbox
  $('#detailsubmit').click(function(){
	$.modal("<div id='simplemodal'><h1>Please be patient.<br />The basket is being updated.</h1></div>");
  });
  
  // Delete Product
  $('dt.amount span.btn').each(function(index){
    var $delbutton = $(this);
	var $productinput = $(this).prev();
	$delbutton.click(function(){
	  $productinput.val('0');
	 
	  $.modal("<div id='simplemodal'><h1>Please be patient.<br />The basket is being updated.</h1></div>");
	   $('form.detailshoping').submit();
	});
  });
  
  //Saferpay
  $('h2#saferpaylink').insertAfter("div.tx-cenashop-pi5");
  $('h2#saferpaylink a').attr('target', '_blank');
  
}); 