$(document).ready(function(){
	// Add rounded corners to boxes
	$('div.ef_box').each(function(){
		ef_original_box_content = $(this).html();
		$(this).html('<div class="ef_top_left"><div class="ef_top_right"><div class="ef_bottom_left"><div class="ef_bottom_right">'+ef_original_box_content+'</div></div></div></div>');
	});
	// Address controls
	$('ul.ef_addresses div.ef_controls').hide();
	$('ul.ef_addresses li').hover(function(){
		$(this).children('div.ef_controls').show();
	},
	function(){
		$(this).children('div.ef_controls').hide();
	});
	$('div.ef_box_billing_addresses div.ef_controls img.ef_use').click(function(){
		$(this).parents('ul.ef_addresses').children('li').removeClass('ef_selected');
		$(this).parents('ul.ef_addresses li').addClass('ef_selected');
		$('input#ef_selected_billing_address').val($(this).parents('ul.ef_addresses li').attr('id'));
		return false;
	});
	$('div.ef_box_delivery_addresses div.ef_controls img.ef_use').click(function(){
		$(this).parents('ul.ef_addresses').children('li').removeClass('ef_selected');
		$(this).parents('ul.ef_addresses li').addClass('ef_selected');
		$('input#ef_selected_delivery_address').val($(this).parents('ul.ef_addresses li').attr('id'));
		return false;
	});
	// Change quantity dynamically
	$('div.ef_quantity_container input').css({
		'float': 'left',
		'margin': '0'
	});
	$('img.ef_decrease_quantity').show();
	$('img.ef_increase_quantity').show();
	$('img.ef_decrease_quantity').click(function(){
		ef_quantity_val = $(this).parents('div.ef_quantity_container').children('input').val();
		if ( $(this).parents('div.ef_quantity_container').children('input').val() > 1 ) {
			ef_quantity_val--;
		}
		$(this).parents('div.ef_quantity_container').children('input').val(ef_quantity_val);
		return false;
	});
	$('img.ef_increase_quantity').click(function(){
		ef_quantity_val = $(this).parents('div.ef_quantity_container').children('input').val();
		ef_quantity_val++;
		$(this).parents('div.ef_quantity_container').children('input').val(ef_quantity_val);
		return false;
	});
	$('div.ef_quantity_container input').blur(function(){
		if ( $(this).val() < 1 ) {
			$(this).val(1)
		}
		if ( $(this).val() == '' ) {
			$(this).val(1)
		}
		if ( isNaN($(this).val()) ) {
			$(this).val(1)
		}
		else {
		}
	});
	$('div.ef_quantity_container input').mouseout(function(){
		if ( isNaN($(this).val()) ) {
			$(this).val(1)
		}
		else {
		}			 
	});
	$("div.ef_quantity_container input").keypress(function(e){
		if ( e.which != 8 && e.which != 0 && ( e.which < 48 || e.which > 57 ) ) {
			return false;
		}
	});
	$("div.ef_quantity_container input").bind('paste', function(e){
		return false;
	})
	// Minimum height for IE6
	if ( $.browser.msie && $.browser.version == '6.0' ) {
		if ( $('div.ef_box').height() < '145' ) {
			$('div.ef_box').css({
				'height': '145px'			
			});
		}
	}
	// Rollovers (instant)
	$('.ef_rollover img, .ef_rollover input, img.ef_rollover, input.ef_rollover').hover(function(){
		$(this).attr('src', $(this).attr('src').replace(/\_off\./gi, '_on\.'));
	},
	function(){
		$(this).attr('src', $(this).attr('src').replace(/\_on\./gi, '_off\.'));
	});
	// Rollovers (preload)
	$('.ef_rollover img, .ef_rollover input, img.ef_rollover, input.ef_rollover').each(function(){
		var source_image = $(this).attr('src');
		var rollover_image = source_image.replace(/\_off\./gi, '_on\.');
		$('<img>').attr('src', rollover_image);
	});
});