
$.fn.scaleImage = function(options) {

	var defaults = {
	};
	var options = $.extend(defaults, options);

	return this.each(function() {
		obj = $(this);
		var width = obj.width();
		var height = obj.height();
		if (width > options.maxwidth || height > options.maxheight) {
			//Set variables for manipulation
			if ((width / options.maxwidth) > (height / options.maxheight)) {
				var ratio = (height / width );
				var new_width = options.maxwidth;
				var new_height = (new_width * ratio);
			} else {
				var ratio = (height / width );
				var new_height = options.maxheight;
				var new_width = (new_height / ratio);
			}

			//Shrink the image and add link to full-sized image
			$(this).height(new_height).width(new_width);
			$(this).css({'visibility': 'visible'});

		}
	});
};


$(document).ready(function(){

	// show fist submenu if need
	if (! $('#bandeauHautBis ul:visible').length ) {
		$('#bandeauHautBis td:first').toggleClass("selected");
		$('#bandeauHautBis ul:first').show();
	}

	// roll over menu
	$('#bandeauHautBis td').hover(
		function(){
			$('#bandeauHautBis ul:visible').hide();
			id = $(this).attr('id');
			$('#bandeauHautBis #sub'+id).show();
		},
		function(){}
	);
});
	
$(window).load(function(){
	// scale image produit
    $('#photo_produit img').scaleImage({'maxwidth': 200, 'maxheight': 220});
    small_imgs = $('#photo_small img');
    small_imgs.scaleImage({'maxwidth': 200/small_imgs.length, 'maxheight': 60});
    // scale image index
    $('#1col img').scaleImage({'maxwidth': 600, 'maxheight': 800});
    $('#3col img').scaleImage({'maxwidth': 180, 'maxheight': 500});
    
});



