
jQuery(document).ready(function() {
	jQuery.fn.exists = function(){return jQuery(this).length>0;}
	
	if($('body#product').exists()) {
		$('.att_price').each(function(k){
			att_id = $(this).attr('id').replace('price_','');
			var p = getPriceByChoice( new Array(att_id));
			$(this).text(p);
		});
		$('#our_minimum_price').text(getMinimumPrice());

		var waiting_for_update = false;

		originalAjaxCartUpdateCartMethod = ajaxCart.updateCart;
		ajaxCart.updateCart = function(jsonData) {
			originalAjaxCartUpdateCartMethod.apply( this, arguments );
			if(waiting_for_update==true) {
				waiting_for_update = false;
				if($('div#added_to_cart:hidden').exists()) {
					// $('div#added_to_cart:hidden').slideDown(80).delay(80);
				}
				$('div#added_to_cart').fadeOut(120).fadeIn(200);
			}
		}

		var originalAjaxCartAddMethod = ajaxCart.add;
		ajaxCart.add =function(idProduct, idCombination, addedFromProductPage, callerElement, quantity, whishlist) {
			waiting_for_update = true;
			originalAjaxCartAddMethod.apply( this, arguments );
		};
		
		$(document).keydown(function(e){
		    if (e.keyCode == 37) { 
				if($('a#prev_link').exists()) {
					document.location = $('a#prev_link').attr('href');
				}
		    }
		    if (e.keyCode == 39) { 
				if($('a#next_link').exists()) {
					document.location = $('a#next_link').attr('href');
				}
		    }
		});
		
				
	}
	
	
	if($('li.ajax_block_product').exists()) {
		$('li.ajax_block_product:nth-child(4n)').css('marginRight', 0);
	}
	else if($('ul#subcategories_list').exists()) {
		$('ul#subcategories_list li:nth-child(4n)').css('marginRight', 0);
		
	}
	

});
