$(document).ready(function(){
	Infinitize.addIEHover();
	Infinitize.makeProductRowsClickable();
	Infinitize.makePackageBoxClickable();
	//Infinitize.animatePromotion();

	jQuery(".fancybox.iframe").fancybox({
			'autoscaling'		: false,
			'padding'			: 25,
			'width'			: 660,
			'height'			: 550,
			'speedIn'			: 300,
			'speedOut'		: 300,
			'overlayOpacity'	: 0.3,
			'overlayColor'		 : '#000'
	});



});

Infinitize = {

	/**
	 * Moet eventueel uitgebreid worden naar meer zaken
	 */
	addIEHover: function() {
		$("table.colored tr, div.rounded.promo").hover(
			function() { $(this).addClass('hover') },
			function() { $(this).removeClass('hover') }
		);
	},

	makeProductRowsClickable: function() {
		$("table.productlist tr").css("cursor","pointer");
		$("a.product-detail").each(function() {
			var link = $(this);
			var tr = link.parent().parent();

			tr.bind("click",function() { window.location = link.attr("href") });
			link.replaceWith(link.html());
		});
	},

	makePackageBoxClickable: function() {
		// Even though this function is neirly exacly the same as makeProductRowsClickable we can't generalise
		// these two as the HTML structure for both cases could very easely be different.
		$("div.rounded.promo").css("cursor","pointer");
		$("a.package-detail").each(function() {
			var link = $(this);
			var box = link.parent().parent();

			box.bind("click",function() { window.location = link.attr("href") });
			link.replaceWith(link.html());
		});
	},

	animatePromotion: function() {
		var sticker = $("#promo-sticker");
		sticker.css({opacity:0});

		var image = new Image();
		image.src = sticker.css("background-image");
		image.onload = sticker.animate({
			opacity: 1.0}, 2000, "swing", function() { Infinitize.glowElement("#promo-sticker",750,0.8) });
	},

	glowElement: function(cssSelector,duration,minimum) {
		var el = $(cssSelector);
		var o = el.css("opacity") < Math.abs((1.0 + minimum)/2)?1.0:minimum;
		el.animate({opacity: o}, duration, "swing",function() { Infinitize.glowElement(cssSelector,duration,minimum) });
	}
}

