var product_changeable = true;

function reset_choose_product_fade() {
	$('.step_bag').fadeOut(400);
	$('.step_thermos').fadeOut(400);
}

function reset_choose_product() {
	product = '';
	
	$('.product').css('opacity', 1.0);
	
	$('#choose_product_next').css('opacity', 0.3);
	
	setTimeout('reset_choose_product_fade()', 500);
}

$('document').ready(
	function() {
		$('#bag').tooltip(
			{
				delay: 0,
				showURL: false,
				fade: 250,
				bodyHandler: function() {
					return $('#bag_tooltip').html();
				},
				fixPNG: true,
				track: true,
				left: -100
			}
		);
		
		$('#thermos').tooltip(
			{
				delay: 0,
				showURL: false,
				fade: 250,
				bodyHandler: function() {
					return $('#thermos_tooltip').html();
				},
				fixPNG: true,
				track: true,
				left: -100
			}
		);
		
		$('.product').hover(
			function() {
				$(this).css('border', '3px solid #EE1D23');
			}, function() {
				$(this).css('border', '3px solid black');
			}
		);
		
		$('.product').click(
			function() {
				if(product_changeable && product != $(this).attr('id')){
					product_changeable = false;
					
					var no_fadeout = false;
					
					if(product == ''){
						no_fadeout = true;
					}
					
					product = $(this).attr('id');
					
					$(this).css('border', '3px solid #EE1D23');
					
					$('.product').stop().not(this).animate({'opacity': 0.3}, 400);
					$(this).stop().animate({'opacity': 1.0}, 400);
					
					if(product == 'bag'){
						$('.step_bag').css('height', 40);
						
						setTimeout('recount_bags()', 400);
						
						if(no_fadeout){
							$('.step_bag').fadeIn(400);
						}else{
							$('.step_thermos').fadeOut(400, function() {
									$('.step_bag').fadeIn(400);
							});
						}
					}else if(product == 'thermos'){
						$('.step_thermos').css('height', 40);
						
						setTimeout('recount_thermoses()', 400);
						
						if(no_fadeout){
							$('.step_thermos').fadeIn(400);
						}else{
							$('.step_bag').fadeOut(400, function() {
									$('.step_thermos').fadeIn(400);
							});
						}
					}
					
					$('#choose_product_next').animate({'opacity': 1.0}, 400);
					
					if(no_fadeout){
						setTimeout('product_changeable = true', 400);
					}else{
						setTimeout('product_changeable = true', 800);
					}
				}
			}
		);
		
		$('#choose_product_next').click(
			function() {
				if($(this).css('opacity') == 1){
					show_next();
				}
			}
		);
		
		$('.step_header_back', $('#step_choose_product')).click(
			function() {
				reset_steps('step_choose_product');
			}
		);
	}
);

