var steps;
var prices;

function setStep(id)
{
	if( id > 1 && steps[1] == 0)
	{
		alert( 'Сначала выберите основу');
		return;
	}
	if( id == 10) $('#constarr').attr('value', steps.join(','));
	
	$('.cblock').hide();
	$('#cnav span').removeClass('sel');
	$('#cnav span#cn'+id).addClass('sel');
	$('#constr'+id).show();
	
	page.updatescroll();
}

function setSelection(e)
{
	var d = $(this).attr('rel').split(/,/);
	var l = d[0];
	var id = d[1]
	var pic = d[2];
	var price = d[3];
	
	prices[l] = price;
	steps[l] = id; 
	
	if( pic != '0')
	{
		$('#aldr2').show();
		$('#la'+l).attr('src', '/img/const/'+pic);
	}
	
	$('#constr'+l+' img.cim1').removeClass('csel');
	$(this).addClass('csel');
	
	updateSum();
}

function aldr2h()
{
	$('#aldr2').hide();
}

function updateSum()
{
	var s = 0;
	for(var a = 1; a <= 8; a ++ )
	{
		var b = prices[a] + ' ';
		if( b.indexOf('%') >= 0) s += Math.round(s*parseInt(b)/100);
		else s += parseInt(b);
	}
	if( $("#cc1").attr('checked')) s += shviPrice;
	if( $("#cc2").attr('checked')) s += Math.round(s*30/100); 

//	if( $("input[@name='cc1']:checked").val()) s += parseInt('1000');
//	if( $("input[@name='cc2']:checked").val()) s += Math.round(s*30/100); 
	
	$('#ctotal').html(s);
}

function cinit()
{
	steps = new Array(0,0,0,0,0,0,0,0,0);
	prices = new Array(0,0,0,0,0,0,0,0,0);
	
	for(var a = 1; a <= 8; a ++) $('#constr'+a+' img.cz').lightBox( { fixedNavigation:true});
	$('.cblock img.cim1').click(setSelection);
	$('#cnav span').click( function() { setStep($(this).attr('rel')) } );
	setStep(1);
	updateSum();
}
