/* toggle functionality for fabric listings (used on Homepage, Free Samples and Buy pages	*/	

$(document).ready(function(){
	
	toggleFabrics();
	
	//imagePreview();
	
});

function toggleFabrics () {
	//hide all fabric_tiny_swatch
	
	//add click behaviour to fabric family title
	$('.toggle').click(
		function () {

			if($(this).attr('rev') == "open"){
				$('#fabricFamilyTitle' + $(this).attr('rel') + ' .fabric_tiny_swatch').animate({ 
				width:"40px",
				marginRight: "12px"
				}, 200 );
	
				$('#fabricVariationListing' + $(this).attr('rel') + ' .fabric_variation').fadeOut('fast');
				$('#fabricVariationListing' + $(this).attr('rel') + ' .fabric_variation_right').fadeOut('fast');
				$('#fabricVariationListing' + $(this).attr('rel')).slideUp('medium');	
				
				$(this).attr('rev','closed');
				$(this).attr('title','Show this fabric family');
				$(this).addClass('closed');
				
			} else {
				$('#fabricFamilyTitle' + $(this).attr('rel') + ' .fabric_tiny_swatch').animate({ 
				width:"0px",
				marginRight: "0px"
				}, 200 );
				
				
				$('#fabricVariationListing' + $(this).attr('rel') + ' .fabric_variation').fadeIn('normal');
				$('#fabricVariationListing' + $(this).attr('rel') + ' .fabric_variation_right').fadeIn('normal');
				$('#fabricVariationListing' + $(this).attr('rel')).slideDown('slow');	
				
				$(this).attr('rev','open');
				$(this).attr('title','Hide this fabric family');
				$(this).removeClass('closed');
				
			}

		}		
	);
}

/*

function imagePreview(){	
	
	//set up positioning of preview
		
		xOffset = 4;
		yOffset = 4;
		

	$('a.swatch_link').hover(function(e){
		
		this.t = this.title;
		this.title = '';

		//create src for rollover image based on a rel attribute
		this.rolloverImageSrc = '/productimages/fabrics/rollover/' + $(this).attr('id') + '.jpg';
		this.fabricAlt = $(this).attr('title');

		var fabricDescriptionContent = '<p>' + (this.t != '') ? '<p>' + this.t : ' </p>';
		
		$('body').append('<div id="preview"><img src="'+ this.rolloverImageSrc +'" alt="' + this.fabricAlt + '" />'+ fabricDescriptionContent +'</div>');								 
		
		$('#preview')
			.css('top',(e.pageY - xOffset) + 'px')
			.css('left',(e.pageX + yOffset) + 'px')
			.fadeIn("fast");
			
	},
	function(){
		
		this.title = this.t;	
		
		$("#preview").remove();
		
	});	
	$('a.swatch_link').mousemove(function(e){
									  
		$('#preview')
		
			.css('top',(e.pageY - xOffset) + 'px')
			
			.css('left',(e.pageX + yOffset) + 'px');
			
	});			
};

*/