
function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt){
	var idx = carousel.index(i, mycarousel_itemList.length);
	carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[idx - 1]));
};

function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt){carousel.remove(i);};

function mycarousel_getItemHTML(item){
	tempSpan='';
	if(item.title.length > 0){tempSpan = '<span>' + item.title + '</span>'};
	return '<img src="' + item.url + '" width="320" height="320" alt="' + item.title + '" />' + tempSpan;
};
function mycarousel_initCallback(carousel)
{
	// Pause autoscrolling if the user moves with the cursor over the clip.
	carousel.clip.hover(function() {
		carousel.stopAuto();
	}, function() {
		carousel.startAuto();
	});
}; 
$(document).ready(function() {

	if(typeof(mycarousel_itemList) != 'undefined') {
	
		if(mycarousel_itemList.length > 1){
			jQuery('#mycarousel').jcarousel({
				scroll: 1,
				auto: 2,
				initCallback: mycarousel_initCallback,
				itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback},
				itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback}
			});
		}else{
			$('#mycarousel').addClass('jcarousel-list');
			$('#mycarousel').append('<li>'+mycarousel_getItemHTML(mycarousel_itemList[0])+'</li>');
		};
	
	}
	
	$(".resume table tr:odd td").css("background-color", "#d1d0c9");
	$(".resume table tr:even td").css("background-color", "#b3b1a5");
	
	// Helper 
	
	$('.helper').each(function() {
		$(this).data('init', $(this).val()) ;
	});

	$('.helper').bind({
		
		focusin: function() {
			if($(this).val() == $(this).data('init')) {
				$(this).val('') ;
			}
		},
		
		focusout: function() {
			if($(this).val().length == 0) {
				$(this).val($(this).data('init')) ;
			}
		}
		
	});

});


function activeElementWithValue(target, classe, reset) {

	// reset des selects inferieurs
	if(reset) {
		resetField(reset) ;
	}

	$('#'+target+' option:enabled').attr('disabled' , 'disabled') ;
	$('#'+target+' .'+classe).attr('disabled' , '') ;
	
}

function activeElementWithClass(target, obj, reset) {

	// reset des selects inferieurs
	if(reset) {
		resetField(reset) ;
	}
	
	var tmp =  target.split(',') ;
	
	for(i in tmp) {
		$('#'+tmp[i]+' option:enabled').attr('disabled' , 'disabled') ;
	}
	
	
	var array =  $(obj).attr('class').split(' ') ;
	
	for(i in tmp) {
		for(id in array) {
			$('#'+tmp[i]+' .'+array[id]).attr('disabled' , '') ;
		}
	}
	
}

function checkout() {

	$("#form-devis").append('<input type="hidden" name="checkout" value="true">') ;
	$("#form-devis").submit() ;
		
}

function resetField(reset) {
	
	var tmp =  reset.split(',') ;
	
	for(i in tmp) {
		$('#'+tmp[i]+' option:enabled').attr('disabled' , 'disabled') ;
		$('#'+tmp[i]+' option:first').attr('selected' , 'selected') ;

	}

}

function validStep1() {
	
	if($('#gamme').val().length > 0 && $('#pdt').val().length > 0) {
		return true ;
	} else {
	
		alert('Merci de renseigner la gamme et le produit') ;
		return false; 
	}

}

function validStep2() {

	if($('#uv').val() == '0') {
		
		if($('#support').val().length > 0 && $('#frmt').val().length > 0 && $('#imp').val().length > 0 && $('#qte').val().length > 0) {
			return true ;
		} else {
			alert('Merci de renseigner le support, l\'impression le format et la quantité') ;
			return false; 
		}
		
	} else {
	
		if($('#support').val().length > 0 && $('#l').val().length > 0 && $('#h').val().length > 0 && $('#imp').val().length > 0 && $('#qte').val().length > 0) {
			return true ;
		} else {
			alert('Merci de renseigner l\'impression le format et la quantité') ;
			return false; 
		}
	}

}

function validStep3() {
	return true ;
}



