
jQuery( function( $ ) {
	$('.foto_regalo').each( function() {
		var id = $(this).attr('id');
		var info = id.split('_');
		var w_orig = info[1];
		var h_orig = info[2];	
		if (w_orig>0 && h_orig>0) {	
			var ratio = ((w_orig/h_orig)*100);
			if (ratio != 150) {
				if (ratio == 100) {
					w = this.height;
					h = this.height;
				}
				else if (ratio > 100) {
					w = Math.min(this.width,w_orig);
					h = Math.round((h_orig*w)/w_orig);
					$(this).css('margin-top',(80-h));
				}
				else if (ratio < 100) {
					h = Math.min(this.height,h_orig);
					w = Math.round((h*w_orig)/h_orig);
				}				
				$(this).css( {width: w, height: h} );
			}	
		}
	});
} );

jQuery( function( $ ) {
	$('.foto_regalo_grande').each( function() {
		var id = $(this).attr('id');
		var info = id.split('_');
		var w_orig = info[1];
		var h_orig = info[2];
		if (w_orig>0 && h_orig>0) {	
			var ratio = ((w_orig/h_orig)*100); 
			if (ratio != 150) {
				if (ratio == 100) {
					w = this.height;
					h = this.height;
				}
				else if (ratio > 100) {
					w = Math.min(this.width,w_orig);
					h = Math.round((h_orig*w)/w_orig);
				}
				else if (ratio < 100) {
					h = Math.min(this.height,h_orig);
					w = Math.round((h*w_orig)/h_orig);
				}				
				$(this).css( {width: w, height: h} );
			}
			else {
				$(this).css( {width: 240, height: 160} );
			}
		}
	});
} );

jQuery( function( $ ) {
	$('.foto_regalo_color').each( function() {
		var id = $(this).attr('id');
		var info = id.split('_');
		var w_orig = info[1];
		var h_orig = info[2];	
		if (w_orig>0 && h_orig>0) {	
			var ratio = ((w_orig/h_orig)*100);
			if (ratio != 150) {
				if (ratio == 100) {
					w = this.height;
					h = this.height;
				}
				else if (ratio > 100) {
					w = Math.min(this.width,w_orig);
					h = Math.round((h_orig*w)/w_orig);
				}
				else if (ratio < 100) {
					h = Math.min(this.height,h_orig);
					w = Math.round((h*w_orig)/h_orig);
				}				
				$(this).css( {width: w, height: h} );
			}
		}
	});
} );


$.swapImage(".swapImage");
