//<![CDATA[

$(document).ready(function () {

	$(function($) {
	
		var basicprice = 0, price = 0;

		// DATA
		$('#stof').data('stof_1', [{ e1:400, e2:265, e3:135, e4:135, e5:135, e6:125, e7:115, e8:265 }]);
		$('#stof').data('stof_2', [{ e1:500, e2:335, e3:165, e4:165, e5:165, e6:150, e7:135, e8:335 }]);
		$('#stof').data('stof_3', [{ e1:600, e2:400, e3:200, e4:200, e5:200, e6:180, e7:160, e8:400 }]);
		$('#stof').data('stof_4', [{ e1:700, e2:465, e3:235, e4:235, e5:235, e6:210, e7:180, e8:465 }]);
		$('#stof').data('stof_5', [{ e1:800, e2:535, e3:265, e4:265, e5:265, e6:250, e7:220, e8:535 }]);
		$('#stof').data('stof_6', [{ e1:900, e2:600, e3:300, e4:300, e5:300, e6:270, e7:240, e8:600 }]);
		

		// Standaard data 
		var currentFabric = 'stof_1';
		$('#stof').find(":first").addClass('selected');
				

		// Update Current prices
	    function updatePrices() {

			$('#m_1 .price').text($('#stof').data(currentFabric)[0].e1);
			$('#m_2 .price').text($('#stof').data(currentFabric)[0].e2);
			$('#m_3 .price').text($('#stof').data(currentFabric)[0].e3);
			$('#m_4 .price').text($('#stof').data(currentFabric)[0].e4);
			
			$('#e_1 .price').text($('#stof').data(currentFabric)[0].e1);
			$('#e_2 .price').text($('#stof').data(currentFabric)[0].e2);
			$('#e_3 .price').text($('#stof').data(currentFabric)[0].e3);
			$('#e_4 .price').text($('#stof').data(currentFabric)[0].e4);
			$('#e_5 .price').text($('#stof').data(currentFabric)[0].e5);
			$('#e_6 .price').text($('#stof').data(currentFabric)[0].e6);
			$('#e_7 .price').text($('#stof').data(currentFabric)[0].e7);
			$('#e_8 .price').text($('#stof').data(currentFabric)[0].e8);
	    };

		// Run on load
		updatePrices();

		// SELECTING THE FABRICS
		$('#stof').children().click(function() {
		
			$(this).parent('#stof').children().removeClass('selected');
			$(this).addClass('selected');
			// Select currentFabric
			currentFabric = $(this).attr('id');
			// Call functions
			updatePrices();
			updateTotal();
		});

		$('.stof_desc').hide();
		

/*
		$('#stof').children().hover(function() {
		
			$(this).children().hide();
		//	$('.stof_desc').show();
		});
*/

		$('#stof').children().hover (
		     function() { // over
		        $(this).find('span:first').hide();
		        $(this).find('span:last').show();
		     },
		     function() { // out
		        $(this).find('span:first').show();
		        $(this).find('span:last').hide();
		     }
		);




		function updateTotal() {
		
			var all = $('#prijzen_container .prijzen_producten .selected');
			var temp = 0;
			var obj = jQuery.each(all, function() {
			
				var that = $(this);
				var value = parseFloat(/[0-9.]+/.exec(that.find('.price').text()));
				temp = temp + parseFloat(value);

			});
			temp = (temp == 0) ? '0' : temp;
			
			$('#price').html(temp);
		}

		// Clear prices after gender change
		function clearPrices() {
			$('#prijzen_container .selected').removeClass('selected');
			updateTotal();
		}


		// Selecting products
		$('.prijs_product').click(function() {
		
			$(this).toggleClass('selected');
			updateTotal();
		
		});
		
		// Hiding elements
		$('.prijzen_slide').first().hide();

		// Selecting gender
		$('#gender_select').children().click(function() {
			
			selected_gender = $(this).attr('id');		
			selected_gender += '_prijzen';
			
            $(this).parent().fadeTo(300, 0, function() {
		      $('.prijzen_slide').first().fadeTo(300,1);
		      $(this).parent().hide();
 			});
			
			$('#prijzen_container').children().hide();
			$('#prijzen_container').children("#"+selected_gender).show();

			clearPrices();
	
		});
		
	
	
	});				

})
		
//]]>
