$(document).ready( function() {

	// change colors
	$('.color-selector a.color-sample').click( function() {
		// saves del clicked ID
		id = $(this).attr('id').substr( $(this).attr('id').lastIndexOf('-') + 1 );
			//console.log ('the id: ' + id);
		
		// if the clicked item is not the active one
		if ( !$(this).hasClass('active') ) {
			// remove the active class on color selector
			$('.color-selector a.color-sample.active').removeClass('active');
			$(this).addClass('active');
			// change images and texts
			itemData = productData['colors'][id];
			$('.color-selector .color-name').text( 'Ref. ' + itemData['name'] );
			$('.color-name-ref').text( 'Ref. ' + itemData['ref'] );
			$('.simple-sheet #main-image, .simple-sheet-mm #main-image, .products-sheet #main-image').attr('src', itemData['photo'] );
			$('.simple-sheet #main-image, .simple-sheet-mm #main-image, .products-sheet #main-image').attr('alt', itemData['name'] );
			// change print link
			if ( typeof printSheetLink != 'undefined' ) {
				$('#sheet-print').attr('href', printSheetLink  + '&ficha=' + itemData['sheet'] ) // console.log( printSheetLink );
			}

		}
		return false;
	});

	// change colors
	$('.formula-color-selector a.color-sample').click( function() {
		// saves del clicked ID
		id = $(this).attr('id').substr( $(this).attr('id').lastIndexOf('-') + 1 );
			//console.log ('the id: ' + id);
		
		// if the clicked item is not the active one
		if ( !$(this).hasClass('active') ) {
			// remove the active class on color selector
			$('.formula-color-selector a.color-sample.active').removeClass('active');
			$(this).addClass('active');
			// change images and texts
			$('.formula-color-selector li.color-name').text( 'Ref. ' + $(this).attr('rel') );
			// change active group of imaes
			$('.formula-images-group').hide();
			$('#color-group-'+id).show();
			// change print link
			if ( typeof printSheetLink != 'undefined' ) {
				$('#sheet-print').attr('href', printSheetLink + '&ficha=' + itemData['sheet'] ) // console.log( printSheetLink );
			}
		}
		return false;
	});

});