// jQuery library in use

/* IE PNG fix multiple filters */
(function ($) {
    if (!$) return;
    $.fn.extend({
        fixPNG: function(sizingMethod, forceBG) {
                if (!($.browser.msie)) return this;
                var emptyimg = "empty.gif"; //Path to empty 1x1px GIF goes here
                sizingMethod = sizingMethod || "scale"; //sizingMethod, defaults to scale (matches image dimensions)
                this.each(function() {
                        var isImg = (forceBG) ? false : jQuery.nodeName(this, "img"),
                                imgname = (isImg) ? this.src : this.currentStyle.backgroundImage,
                                src = (isImg) ? imgname : imgname.substring(5,imgname.length-2);
                        this.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='" + sizingMethod + "')";
                        if (isImg) this.src = emptyimg;
                        else this.style.backgroundImage = "url(" + emptyimg + ")";
                });
                return this;
        }
    });
})(jQuery);


$(document).ready(function() {
	var mbm = new Object();

	$('.noJs').removeClass('noJs');

// wyszukiwarka
	mbm.searchValue = 'szukaj';
	$('#searchQuery').focus(function() {
		if($(this).attr('value') == mbm.searchValue) $(this).attr('value','');
	}).blur(function() {
		if($(this).attr('value') == '')	$(this).attr('value',mbm.searchValue);
	});
	
	$('#szukaj').click(function() {
		v = $('#searchQuery').attr('value');
		if(v != mbm.searchValue && v != '') {
			$('#szukaj').attr('disabled','disabled');
			$('#searchForm').submit();
		} else return false;
	});
	
// slideshow na głównej
	$('#baner').cycle({
		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		slideExpr: 'div.banerItem',
		startingSlide:0,
		allowPagerClickBubble: true,
		pagerEvent: 'mouseover', 
    	pauseOnPagerHover: true,
    	cleartypeNoBg: true,
    	cleartype: true,
    	timeout: 4000
	});

	$('a.blank').attr('target','_blank');
	
//newsletter
	$("#newsletterForm").validate({
		rules: {
			imie: {required: true},
			email: {required: true, email: true}
 		},
		submitHandler: function(form) {
			$(form).submit(function() { return false; });
			$.post('/ntbase.php', $(form).serialize(), function(resp) {
				$('#newsletter .formContent').html('<div class="msg">' + resp + '</div>');
   		});

		}
	});

	$(".toTop").click(function() {
		$('html, body').animate({scrollTop:0}, 'slow');
		return false;
	});
	
	$("#formularzKontaktowy").validate({
		 rules: {
			contactEmail: {required: true, email: true},
			contactName: {required: true},
			contactSurName: {required: true},
			contactCompany: {required: true},
			contactAdres: {required: true},
			contactContent: {required: true},
			contactPhoneNo: {required: true, telefon: true}
		},
		submitHandler: function(form) {
			$(form).submit(function() { return true; });
/*			$(form).submit(function() { return false; });
			$.post('/include/formularz.php', $(form).serialize(), function(resp) {
				if(resp) msg = 'Dziękujemy za przesłanie zapytania.<br />Wkrótce udzielimy wyczerpującej odpowiedzi.';
				else msg = 'Wystąpił błąd - zapytanie nie zostało wysłane.';
				var height = $('#form').height();
				$('#form').html('<div class="msg" style="height: ' + height + 'px;">' + msg + '</div>');
  		}); */

		}
	});
	
	$('.newsItem').click(function() {
		var link = $(this).children('.newsTxt').children('a.newsMore').attr('href');
		location.href = link;
		return false;
	});
});	

function number_format(number, decimals, dec_point, t_sep) {
	var intstr;
	var output = '';
       
	if(typeof(decimals) == 'undefined')
		decimals = 2;
          
	if(typeof(dec_point) == 'undefined')
		dec_point = ',';
          
	if(typeof(t_sep) == 'undefined')
		t_sep = ' ';
       
	// czesc calkowita   
	int = parseInt(number);
       
	// czesc ulamkowa
	float = parseInt((parseFloat(number)-int)*Math.pow(10, decimals));

	intstr = int+'';
       
	j = intstr.length;
       
	if((i = j%3) != 0)
	output += intstr.substring(0, i);
       
	while(i < j) {
		output += t_sep+''+intstr.substring(i, i+3);
		i += 3;
	}
       
	if(float > 0) output += dec_point + float;
	if(float == 0) output += dec_point + '00';
	
	return(output);
}
