$.noConflict();

Cufon.replace('#nav a, h2, h3', {
	hover: true
});

jQuery(document).ready(function($){
	$('.pressitem a, #collection-itemthumbs a').hover(function() {
		$(this).stop().animate({'opacity':0.3},150);
	},function(){
		$(this).stop().animate({'opacity':1},750);
	});
	$('#collection-itemthumbs').galerio();
	if (jQuery.support.opacity) {
		$('body').addClass('advanced');
	}

	$('.pressitem a, #collection-itemdisplay a, .product-img-zoomable').fancybox({
		imageScale: false,
		centerOnScroll: false,
		overlayOpacity: 0.8
	});

	$("a[href^='http://'],a[href$='.pdf']").attr("target","_blank");
});


/*
 * Galerio (beta)
 * by Freddy Leitner @ Digital Dreamer [www.dreamer.de]
 * 
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html

	TODO towards a general release:
	- sanitize target div retrieval
	- shows first target per default (detection/parametrization)
	- only hides and shows the first image within target div
	- respect more than one image (or less)
	- animation options (in/out) and callbacks (onSelectThumb,onDeselectThumb,onImagesLoad,onImagesLoaded)
 */
(function($) { $.fn.galerio = function(options) {
	$.fn.galerio.defaults = {
		imageOnClass:			'active',
		imageOffClass:			'inactive',
		thumbOnClass:			'active',
		thumbOffClass:			'inactive',
		onSelectThumb:			function() {},
		onDeselectThumb:		function() {},
		onImageLoad:			function() {},
		onImageLoaded:			function() {},
		onImageShow:			function() {}
	};
	var opts = $.extend({}, $.fn.galerio.defaults, options);
	return this.each(function() {
		var container = this;
		var initialThumb = "";
		$(container).find('ul li a').each(function() {
			var targetDiv = $($(this).attr("href"));
			targetDiv.hide();
			if (targetDiv.find("img").length > 0) {
				var targetImg = targetDiv.find("img").eq(0);
				targetImg.data("osrc", targetImg.attr("src"));
				targetImg.data("bindstate", false);
				targetImg.removeAttr("src");
				if (initialThumb == "") {
					initialThumb = $(this).attr("href");
				}
			}
			$(this).click(function(e){
				e.stopPropagation();
				e.preventDefault();
				$(this).blur();
				switchTarget($(this).attr("href"),container);
			});
		});
		switchTarget(initialThumb,container);
	});
	function switchTarget(targetHref,container) {
		if ($(container).data("currentThumb") != targetHref) {
			loadTarget(targetHref,container);
		}
	}
	function loadTarget(targetHref,container) {
		var targetDiv = $(targetHref);
		if (targetDiv.find("img").length > 0) {
			var targetImg = targetDiv.find("img").eq(0);
			targetImg.removeAttr("src");
			if (!targetImg.data("bindstate")) {
				targetImg.bind("load",function() {
					activateTarget(targetHref,container);
				});
				targetImg.data("bindstate", true);
			}
			targetImg.attr("src",targetImg.data("osrc"));
		} else {
			activateTarget(targetHref,container);
		}
	}
	function activateTarget(targetHref,container) {
		if ($(container).data("currentThumb") != targetHref) {
			if ($(container).data("currentThumb")) {
				var oldTargetDiv = $($(container).data("currentThumb"));
				oldTargetDiv.fadeOut().hide();
			}
			$(container).data("currentThumb", targetHref);
			var targetDiv = $(targetHref);
			targetDiv.fadeIn();
			opts.onImageShow.call(targetDiv);
		}
	}
} })(jQuery);