<?php if ($accessories_product) { ?>
<h2><?php echo $heading_title; ?></h2><br />
<div class="accessories-product-list">
   	<?php foreach ($accessories_product as $accessory_product) { ?>
      <div>
		<div class="product-accessories-hover">
		  <div class="image-accessories-product"><a href="<?php echo $accessory_product['href']; ?>"><img src="<?php echo $accessory_product['image']; ?>" title="<?php echo $accessory_product['name']; ?>" alt="<?php echo $accessory_product['name']; ?>" /></a></div>
		  <div class="accessories-product-info"><img src="<?php echo $accessory_product['popup']; ?>" alt="<?php echo $accessory_product['name']; ?>" /></div>
        </div>
		<div class="name-accessories" style="margin-left: <?php echo $mrg; ?>px;"><a href="<?php echo $accessory_product['href']; ?>"><?php echo $accessory_product['name']; ?></a></div>
		<div class="accessories-description" style="margin-left: <?php echo $mrg; ?>px;"><?php echo $accessory_product['description']; ?></div>
		<div class="cart-accessories">
		  <?php if ($accessory_product['price']) { ?>
		    <div class="price-accessories"> 
		      <?php if (!$accessory_product['special']) { ?>
      		    <?php echo $accessory_product['price']; ?>
      	      <?php } else { ?>
      		    <span class="price-accessories-old"><?php echo $accessory_product['price']; ?></span> <span class="price-accessories-new"><?php echo $accessory_product['special']; ?></span>
      	      <?php } ?>
		      <?php if ($accessory_product['discounts'] && !$accessory_product['special']) { ?>
			    <br />
			    <?php foreach ($accessory_product['discounts'] as $discount) { ?>
			      <span class="price-accessories-discount"><?php echo sprintf($text_discount, $discount['quantity'], $discount['price']); ?></span>
			    <?php } ?>
			  <?php } ?>
		    </div>
		  <?php } ?>
      	  <?php echo $text_qty; ?>
      	  <input type="text" name="access_<?php echo $accessory_product['product_id'];?>]" id="access_<?php echo $accessory_product['product_id'];?>" onclick="this.select();" onkeyup="set_qty(<?php echo $accessory_product['product_id'];?>);" size="2" style="width:20px;" value="<?php echo $accessory_product['minimum'];?>" />
      	  <input type="hidden" name="access_values[<?php echo $accessory_product['product_id'];?>]" id="access_values_<?php echo $accessory_product['product_id'];?>" value="<?php echo ($accessory_product['special_accessory']) ? $accessory_product['special_accessory'] : $accessory_product['price_accessory'];?>" />
		  <input type="hidden" name="access_minimum[<?php echo $accessory_product['product_id'];?>]" id="access_minimum_<?php echo $accessory_product['product_id'];?>" value="<?php echo $accessory_product['minimum'];?>" />
 		  <?php if (!$accessory_product['options']) { ?>
      		<a onclick="addProductToCart('<?php echo $accessory_product['product_id']; ?>');" class="button" id="button_cart_<?php echo $accessory_product['product_id'];?>"><?php echo $button_cart; ?></a>
      	  <?php } else { ?>
      		<a href="<?php echo $accessory_product['href']; ?>" class="button" id="button_cart_<?php echo $accessory_product['product_id'];?>"><?php echo $button_cart; ?></a>
		  <?php } ?>
		  <?php if ($accessory_product['minimum'] > 1) { ?>
			<br /><div class="accessories-minimum"><?php echo sprintf($this->language->get('text_minimum'), $accessory_product['minimum']); ?></div>
		  <?php } ?>
		  <?php if ($accessory_product['options']) { ?>
			<br /><div class="accessories-minimum"><?php echo $text_accessories_product_options; ?></div>
		  <?php } ?>
		</div>
      </div>
    <?php } ?>
</div>
<?php } ?>
<script type="text/javascript">
function get_qty(product_id){
	var qty = document.getElementById("access_"+product_id).value;
	if(isNaN(qty)) {
		return 1;
	}
	if(qty < 1){
		qty = 1;
	}
	return qty;
}
function set_qty(product_id){
	var qty = get_qty(product_id);
	var minimum = document.getElementById("access_minimum_"+product_id).value;
				
	if(qty < minimum){
		document.getElementById("access_"+product_id).value = minimum;
	}
	else{
		document.getElementById("access_"+product_id).value = qty;
	}
}			
function addProductToCart(product_id) {
			
	$.ajax({
		url: 'index.php?route=checkout/cart/add',
		type: 'post',
		data: 'product_id=' + product_id + '&quantity=' + get_qty(product_id),
		dataType: 'json',
		success: function(json) {
		$('.success, .warning, .attention, information, .error').remove();
							
		if (json['error']) {
			if (json['error']['option']) {
				for (i in json['error']['option']) {
					$('#option-' + i).after('<span class="error">' + json['error']['option'][i] + '</span>');
				}
			}
		} 
							
		if (json['success']) {
			$('#notification').html('<div class="success" style="display: none;">' + json['success'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>');
								
			$('.success').fadeIn('slow');
								
			$('#cart-total').html(json['total']);
								
			$('#cart').addClass('active');
						
			$('#cart').load('index.php?route=module/cart #cart > *');
			
			setTimeout(function() {$('#cart').removeClass('active');}, 5000);
								
			$('html, body').animate({ scrollTop: 0 }, 'slow'); 
		}	
}
});				
}
</script>
<script type="text/javascript">
$('.product-accessories-hover').each(function() {        
	var tip = $(this).find('.accessories-product-info');

	$(this).hover(
		function() { tip.appendTo('body'); },
		function() { tip.appendTo(this); }
	).mousemove(function(e) {
		var x = e.pageX + 60,
		y = e.pageY - 40,
		w = tip.width(),
		h = tip.height(),
		dx = $(window).width() - (x + w),
		dy = $(window).height() - (y + h);
		if ( dx < 50 ) x = e.pageX - w - 60;
		if ( dy < 50 ) y = e.pageY - h + 50;
		tip.css({ left: x, top: y });
	});         
});
</script>
