//jQuery.noConflict();

(function($){
	$(document).ready(function(){
		$('#menuUslugi').hover(function(){
			$('.flyingSubmenu').stop().animate({'opacity':0}, 1, function(){
				$(this).css('display', 'block').animate({'opacity':1});
			});
		}, function(){
			$('.flyingSubmenu').stop(true).animate({'opacity':0.0}, 'normal', function(){
				$(this).css('display', 'none');
			});
		});
		
		$('.flyingSubmenu').hover(function(){
			$(this).stop(true).css('display', 'block').animate({'opacity':1});
		}, function(){
			$(this).stop().animate({'opacity':0.0}, 'normal', function(){
				$(this).css('display', 'none');
			});
		});
		$('.slider_nav_intro').each(function(){
			$(this).css('padding-top', Math.floor((90-$(this).height())/2)+'px');
		});
		
		var sliderHeight = 0;
		$('#dabnews_inner .dabnews_slide').each(function(){
			sliderHeight = ($(this).height() > sliderHeight) ? $(this).height() : sliderHeight;
			$('#dabnews_outer').css('height', sliderHeight+'px');
		});
		
		
		//cenniki
        function TSeparator(S) {
            S = String(S);
            var RgX = /^(.*\s)?([-+]?\d+)(\d{3}\b)/;
            return S == (S = S.replace(RgX, "$1$2 $3")) ? S : TSeparator(S);
        }
        
		$('.pricegrid-price').each(function(){
            var prices = $(this).text().match(/([0-9]*[ ]?)*[0-9]+(\.|,)?[0-9]*/);
            
            if (prices.length == 0) return true;
            
            $(this).html( $(this).html().replace(prices[0],'<span class="pricegrid-pricevalue">'+prices[0]+'</span>')  );
            
            $(this).find('.pricegrid-pricevalue').data('singlePrice',prices[0].replace(',','.').replace(/[ ]/g,'').toFloat());
        });

        $('.pricegrid-multiplier').html('<input value=1 type=text>');
        
        $('.pricegrid-multiplier input').change(function() {
            var value = $(this).val().toInt();
            value = (value != null && value>=1 ? value : 1) ; 
            $(this).val(value);

            $(this).parents('.pricegrid').find('.pricegrid-pricevalue').each(function(){

                $(this).text(
                     TSeparator(( $(this).data('singlePrice') * value.toFloat()  ).toFixed(2).replace('.',',')) 
                 );
            });
        })
        .keyup(function(){
            $(this).change();
         }).change();
        
        
        
        //wyszukiwarka: 
        $('#searchForm').submit(function(){
            return ($('#inputFraza').val() != '') ? true : false;
        });
        
        $.ajax({
			url: 'public/javascript/autocomplete.js',
			success: function(data){
	        	$('#inputFraza').autocomplete({source:data, delay:0});
        	},
        	error: function(){},
			dataType: 'json'
		});
        
        
        $('.qn-collapsible').each(function(){
        	var content = $(this);
        	content.hide();
        	var link = $('<a href="#">więcej</a>');
        	link.toggle(function(){
        		$('.qn-collapsible:visible').next('a').click();
        		content.slideDown();
        		$(this).html('zwiń');
        		return false;
        	}, function(){
        		content.slideUp();
        		$(this).html('więcej');
        		return false;
        	});
        	content.after(link);
        });
        
        $("#fb_widget").hover(function(){
			$("#fb_widget").animate({right:"0"},{duration: "medium", queue: false});
		},function(){
			$("#fb_widget").animate({right:"-212"},{duration: "medium", queue: false});
		},500);
        
	});

})(jQuery);


window.addEvent('load', function(){
	if(openSlider)
	new dabnews({
	outerContainer : 'dabnews_outer',
	innerContainer : 'dabnews_inner',
	elements: '.dabnews_slide',
	navigation: {
		'forward':'dabnews_right',
		'back':'dabnews_left',
		container: 'dabnews_inner_nav',
		elements:'.dabnews_navLink',
		outer: 'dabnews_nav', 
		visibleItems:4
	},
	navInfo: 'dabnews_nav_info',
	navLinks: '.dabnews_navLink',
	slideType: 1,
	orientation: 0,
	slideTime: 6000,
	duration: 600,
	tooltips:1,
	autoslide:0,
	startElem:1
	});
});
