$().ready(

	function() {
		
		// $(".productsList li:even").css('float', 'left');
		// $(".productsList li:odd").css('float', 'right');
		// $(".productsList li:last").css({ 'padding-bottom' : '45px', 'background' : 'none' }).prev().css({ 'padding-bottom' : '45px', 'background' : 'none' });
		
		// rowne boksy
		/*
		$(".productsList li:odd").each(function(){
			$heightA = $(this).prev().height();
			$heightB = $(this).height();

			if ($heightA >= $heightB) {
				$height = $heightA;
			} else {
				$height = $heightB;
			}

			$(this).prev().height($height);
			$(this).height($height);
		});
		*/
		
		$(window).load(function(){
			$(".productsList li").each(function(i){
				if (i % 3 == 0){
					var maxHeight = Math.max($(this).height(), $(this).next().height(), $(this).next().next().height());
					$(this).height(maxHeight).next().height(maxHeight).next().height(maxHeight);
					// $(this).height(300).next().height(300).next().height(300);
					// alert(maxHeight);
				} 
			});
		});


		if ($(".review:first dd").height() >= $(".review:last dd").height())
		{
			$(".review:last dd").height($(".review:first dd").height());
		} else {
			$(".review:first dd").height($(".review:last dd").height());
		}
		
		// $(".productsList li").append('<div class="clearFix"></div>');
		/*
		$('#top_newsy').cycle({ 
		    fx:     'fade', 
		    speed:  2000, 
		    timeout: 8000
		});
		*/
		
		$("#search").submit(function(){
			window.location = $(this).attr('action')+','+$("#search input:text").val();
			return false;
		});
		
		
		// $('.telebim_more_btn,.telebim_slide_btn').fadeTo(0, 0.9);
		
		
		$('#telebim_pics').cycle({
		    fx:      'cover',
		    next:   '#telebim_pics',
		    timeout:  10000,
		    speed: 300,
		    pager:  '.telebim_slide_btn',
		    before: function(currElement, nextElement, opts, isForward) {
				$('.telebim_more_btn').attr('href', nextElement);
			}
		});
		

		$('a.cart_add').each(function(){
			$(this).qtip({
				content: { 
					text: 'Ile sztuk? <br /> <input type="text" value="1" style="border: 1px solid #f0de7d; width: 100px; text-align: center; margin: 6px 0 6px 0;" /> <a href="'+$(this).attr('href')+'" class="cart_add_q">Dodaj</a>'
				},
				show: {
					when: false,
					solo: true
				},
				hide: {
					when: false,
				},
				style: {
					name: 'cream',
					tip: { 
						corner: 'bottomRight',
						size: {
							x: 20,
							y : 20
						}
					},
					border: {
						width: 3,
						radius: 5,
					},
					padding: 5
				},
				position: {
					corner: {
						target: 'topMiddle',
						tooltip: 'bottomRight'
					}
				}
			});
			
			$(this).toggle(
				function(){
					$(this).qtip('show');	
					return false;
				}, function() {
					$(this).qtip('hide');	
					return false;
				}
			);
		});
		
		$('a.cart_add_q').click(
			function(){
				$(this).attr('href', $(this).attr('href')+','+$(this).prev().val());
			}
		);
		
	}
	
);
