jQuery.noConflict();
jQuery(document).ready(function() {
	var galleryWidth = jQuery('.tx-chgallery-pi1 ul').outerWidth(true) - jQuery('.tx-chgallery-pi1 ul').innerWidth();
	jQuery('.tx-chgallery-pi1 li').each(function(element) {
		galleryWidth = galleryWidth + jQuery(this).width();
	});
	jQuery('.tx-chgallery-pi1 ul').css({ 'width':galleryWidth });
	var galleryOffset = jQuery('.tx-chgallery-pi1 ul').parent().offset();
	var galleryParentWidth = jQuery('.tx-chgallery-pi1 ul').parent().width();
	if(galleryWidth > galleryParentWidth) {
		jQuery('.tx-chgallery-pi1 ul').parent().mousemove(function(e) {
			var scrollLeft = ((e.pageX-galleryOffset.left) / galleryParentWidth) * (galleryWidth-galleryParentWidth);
			jQuery('.tx-chgallery-pi1 ul').parent().scrollLeft(scrollLeft);
		});
	}
	jQuery('.tx-chgallery-pi1 li a').click(function () {
		var link = this.href;
		jQuery('.tx-chgallery-pi1 .single').parent().append('<div class="overlay"></div>');
		jQuery('.tx-chgallery-pi1 .overlay').hide();
		jQuery('.tx-chgallery-pi1 .overlay').fadeIn('fast', function() {
			jQuery('.tx-chgallery-pi1 .single').load(link + ' #teaserbox .single img', '', function() {
				jQuery('.tx-chgallery-pi1 .single img').load(function() {
					jQuery('.tx-chgallery-pi1 .overlay').fadeOut('fast', function() {
						jQuery('.tx-chgallery-pi1 .overlay').remove();
					});
				});
			});
		});
		return false;
	});
});

