function urlencode(str) {
	//return escape(str).replace(/\+/g,'%2B').replace(/%20/g, '+').replace(/\*/g, '%2A').replace(/\//g, '%2F').replace(/@/g, '%40');
	return encodeURI(str).replace(/\+/g,'%2B').replace(/%20/g, '+').replace(/\*/g, '%2A').replace(/\//g, '%2F').replace(/@/g, '%40').replace(/#/g, '').replace(/&/g, '');
}
$(function() {
	
	$('#top h1').css('top',Math.floor(($('#top').height()-$('#top h1').height())/2));
	
	$(".swfFile").each(function() {
		var params = $(this).attr('rel').split(':');
		$(this).css({width: params[1]+'px',height: params[2]+'px'}).flash({
			swf: params[0],
			width: params[1],
			height: params[2],
			wmode: 'transparent'
		});
	});
	$('#buttonSearch').click(function() {
		if($('#inputSearch').val() == 'szukana fraza' || $('#inputSearch').val() == '') return false;
	});

	$("#newsletter").validate();
	$('#newsletter a').click(function() {
		$('#newsWypisz').val('1');
		$('#newsletter').submit();
		return false;
	});
	$('#buttonEmail').click(function() {
		$('#newsWypisz').val('0');
	});

	if ($("#contactForm").length)	$("#contactForm").validate();

	Shadowbox.init();

	var search_a = $('#content #center p img').parent('a');
	if(search_a.length) search_a.each(function() {
		$(this).attr('target', '_blank');
	});

	search_a = $('#content #center .shadowboxLinks p img').parent('a');
	if(search_a.length) search_a.each(function() {
		$(this).attr('target', '');
		Shadowbox.setup(this);
	});

	if($('#kontaktform').length) {
		$('#kontaktform').validate();
		$('#kontaktsubmit').click(function() {
			$('#kontaktform').submit();
			return false;
		});
	}
	if ($('#slideshow').length)
	{
		$('#slideshow').before('<div id="sliderNav">').cycle({ 
		    fx:     'fade', 
		    speed:  1200, 
		    timeout: 5000, 
		    pager:  '#sliderNav',
		    before: function() { if (window.console) console.log(this.src); }
		});
	}
	
	Cufon.replace('#top ul li a', {	hover: true });
	Cufon.replace('h1:not(.noCufon)')('h2:not(.noCufon)')('.cufonik');
	Cufon.replace('.leftBox h2, .rightBox h2, button.yellow, a.buttonYellow, a.buttonGrey', { textShadow: '#fff 1px 1px' });
	
	$('ul.categoryGraphicList').each(function(){
		$('ul.categoryGraphicList li:nth-child(4n)').addClass('last');
	});
    
	$('ul.productList').each(function(){
		$('ul.productList > li:nth-child(3n)').addClass('last');
	});
	
	$('.showFiles').each(function() {
		var parent = $(this).parent();
		$(this).hide().css({width: parent.css('width'), height: parent.css('height')});
		$(this).find('.back').click(function() {
			$(this).parent().parent().parent().fadeOut('fast');
			return false;
		});
	});
	$('.do_pobrania').each(function() {
		$(this).find('li a').click(function() {
			var showFiles = $(this).parent().parent().next('.showFiles');
			$(showFiles).find('div ul').html($(this).next('ul').html());
			$(showFiles).find('div h3').html($(this).attr('rel'));
			$(showFiles).fadeIn('fast');
			Cufon.replace('.showFiles div h3');
			return false;
		});
	});
	$(function(){
		$(".tip").tipTip({defaultPosition: 'bottom', edgeOffset: 3, delay: 100});
	});
	
	if($('ul.productList .zapytaj').length) {
		$('ul.productList .zapytaj span.bg').fadeTo(0, 0.6);
	}
});
