$('#prod-choises img').css({ 'position' : 'relative', 'bottom' : '20px' }).animate({ 'bottom': '0px' }, { duration: 800, easing: 'easeOutBounce' });

$('#printAndPdf a:first-child').click(function() {
	window.print();
return false;
});

$.fn.extend({
	showImage: function() {
		$(this).click(function() {
					
			$('#product-matrix-modal-img').html('<img src="' + $(this).attr('href') + '" alt="Lol" />');
			
			$('#product-matrix-modal').css({
				'top' : $(document).scrollTop() + (($(window).height() / 2) - (600 / 2)) + 'px',
				'left' : ($(window).width() / 2) - (620 / 2) + 'px'
			});
			
			$('#product-matrix-modal').fadeIn('slow');
			
			$('#product-matrix-modal-close').click(function() {
				$('#product-matrix-modal').fadeOut('fast');
			return false;
			});
					
		return false;
		});
	},
	
	showInfo: function() {
		$(this).click(function() {
		
			$('#product-matrix-modal-info').css({
				'top' : $(document).scrollTop() + (($(window).height() / 2) - (245 / 2)) + 'px',
				'left' : ($(window).width() / 2) - (270 / 2) + 'px'
			});
		
			$('#product-matrix-modal-info').fadeIn();
			
			$('#product-matrix-modal-infotext').html($(this).next('div.infotext').html());
					
			$('#product-matrix-modal-info-close').click(function() {
			
				$('#product-matrix-modal-info').fadeOut('fast');
				$('#product-matrix-modal-infotext').html(' ');
				
			return false;
			});
					
		return false;
		});
	}
});

$(window).ready(function() {

	$('#product-matrix td input[type="checkbox"]').before('<a href="#" class="chbx">Yes</a>');
	$('#product-matrix th a').each(function() {
		$(this).before('<div class="plus"><a href="' + $(this).attr('href') + '" class="modal">Show image</a></div>');
	});
	
	$('a.modal').showImage();
	$('a.info').showInfo();
	
	$('#product-matrix a.chbx').click(function() {
		var $products = ['rollUpClassic', 'rollUpPro', 'rollUpPromo', 'screen', 'poleSystem'];
		var $root = $(this).parent();
		
		$(this).next().trigger('click');
			
		if($(this).next().is(':checked')) {
				
			$(this).addClass('chbx-checked');
				
			$root.nextAll(':has(img)').children('img').attr('src', '/img/banner-system-guide/check-green.gif');
			$root.nextAll().contents().not('img').parent().html('<img src="/img/banner-system-guide/check-red.gif" alt="False" />');
				
			$('#product-matrix tfoot tr td span[id]:odd').html($('#product-matrix input[type="checkbox"]:checked').length);
			
		} else {
				
			$(this).removeClass('chbx-checked');
				
			$root.nextAll(':has(img[alt="Check"])').children('img').attr('src', '/img/banner-system-guide/check-gray.gif');
			$root.nextAll(':has(img[alt="False"])').html(' ');
				
			$('#product-matrix tfoot tr td span[id]:odd').html(($('#product-matrix td input[type="checkbox"]:checked').length > 0 ) ? $('#product-matrix td input[type="checkbox"]:checked').length : '0');
			
		}
			
		$($products).each(function(n, prod) {
				
			$('#rating-' + prod +'-sum').html('' + $('#product-matrix td input[type="checkbox"]').parent().nextAll(':has(img[src*="green"]):nth-child(' + (3+n) +')').length);
				
			var $sum = $('#rating-' + prod +'-sum').html();
			var $tot = $('#rating-' + prod +'-tot').html();
				
			if($sum !== $tot) {
				$('#product-matrix td input[type="checkbox"]').parent().nextAll(':nth-child(' + (3+n) +')').css('background', '#fff').animate({
					'opacity' : 0.4
				}, 500);
					
				$('#product-matrix th:nth-child(' + (3+n) + ') a img').animate({
					'opacity' : 0.6,
					'height' : '100px'
				}, 300);
			} else {
				$('#product-matrix td input[type="checkbox"]').parent().nextAll(':nth-child(' + (3+n) +')').css('background', 'transparent').animate({
					'opacity' : 1
				}, 500);
					
				$('#product-matrix th:nth-child(' + (3+n) + ') a img').animate({
					'opacity' : 1,
					'height' : '140px'
				}, 300);
			}
		});
		
		return false;
	});


/*
	$('#product-matrix thead, #product-matrix tfoot').css({
		zIndex: 900
	});

	$(window).bind('scroll', function() {
		if($(document).scrollTop() > 171) {
			$('#product-matrix thead').css({
				position: 'fixed',
				top: 0
			});
			
			$('#product-matrix tbody tr:first-child td').css({
				paddingTop: '170px'
			});
			

		} else {
			$('#product-matrix thead').css({
				position: 'static'
			});
			
			$('#product-matrix tbody tr:first-child td').css({
				paddingTop: 0
			});
		}
	});
*/
});
