$(document).ready(function(){
	// LOAD FANCYBOX IF ZOOM IMAGES
	var za = $('a[href$=.jpg],a[href$=.jpeg],a[href$=.png],a[href$=.gif]');
	if(za.length > 0)
	{
		$.get('/fancybox/jquery.fancybox-1.3.4.css', function(css) {
			var new_css = '<style type="text/css">' + css + '</style>';
			$('head').append(new_css);
		});

		$.getScript('/fancybox/jquery.fancybox-1.3.4.pack.js', function() {
			za.each(function(){
				var img_alt = 'm';
				var a_img = $(this).children('img');
				if(a_img.length === 1)
				{
					// TRANSFER FLOAT
					$(this).css('float', $(a_img).css('float'));
					// TRANSFER MARGIN
					$(this).css('marginTop', $(a_img).css('marginTop'));
					$(this).css('marginBottom', $(a_img).css('marginBottom'));
					$(this).css('marginLeft', $(a_img).css('marginLeft'));
					$(this).css('marginRight', $(a_img).css('marginRight'));
					$(a_img).css('margin', '0');
					if($(a_img).attr('alt').length) img_alt = $(a_img).attr('alt');
				}
				var show_title = false;
				if(img_alt != '' && img_alt != 'Image')
				{
					show_title = true;
					$(this).attr('title', img_alt);
				}
				$(this).css('display', 'inline-block');
				$(this).css('textDecoration', 'none');
				$(this).prepend('<span class="image_zoom">&nbsp;</span>');
				$(this).attr('rel', 'fb_group');
				$(this).fancybox({
					'autoScale':true,
					'overlayColor': '#000',
					'overlayOpacity': 0.5,
					'titleShow':show_title,
					'titlePosition':'over',
					'transitionIn':'none',
					'transitionOut':'none'
				});
			});
		})
	}
});
