
jQuery.fn.reverse = function() { return this.pushStack(this.get().reverse(), arguments); };

$(function(){ try {

	//swfobject.embedSWF('/page/flash/top.swf','topflash','981','451','10.0.0','',oTopFlashVars,{menu:'false',allowfullscreen:'true',allowscriptaccess:'sameDomain'});
	$('a[rel~=external],a[href^=http://]').attr('target','_blank');
	$('a[rel~=lightbox]').lightBox({ imageBlank: '/page/images/lightbox-blank.gif', imageLoading: '/page/images/lightbox-ico-loading.gif', imageBtnClose: '/page/images/lightbox-btn-close.gif', imageBtnPrev: '/page/images/lightbox-btn-prev.gif', imageBtnNext: '/page/images/lightbox-btn-next.gif', txtImage: 'Zdjęcie', txtOf: 'z' }); 

	$('select[name=ilosc]').change(function(){
		var url = new pb_url(window.location.href);
		url.query('ilosc',$(this).val());
		window.location.href = ""+url;
	});

	if($('.accordion .accordion-title').length>1) { $('.accordion .accordion-content').hide(); $('.accordion .accordion-title').click(function(){ if($(this).hasClass('visible')) $(this).next('.accordion-content').slideUp(); else $(this).next('.accordion-content').slideDown(); $(this).toggleClass('visible') }); }; 

	var iHeight = $(window).height()-$('body').height();
	if(iHeight>0) $('#bottom-content').height($('#bottom-content').height()+iHeight);
	//$('.ico-cert').height($('#index-small-y,#index-y').height()-65);

	if(document.getElementById('projects-gallery') && document.getElementById('projects-gallery').getElementsByTagName('img').length>6)
		setInterval('randomProjectGallery();',2000);

	/* wyszukiwarka */
	$('#search-q').each(function(){
		if($(this).val()=='')
			$(this).val($(this).attr('title'));
		$(this).focus(function(){ if($(this).attr('title')===$(this).val()) $(this).val(''); })
			.blur(function(){ if(''===$(this).val()) $(this).val($(this).attr('title')); });
	});

	/* rozwijane zdjecia w menu */
	$('.a0-img img').each(function(){
		this.assignAnimation = function(){
			$(this).parent()
				.data('height1',$(this).parent().height())
				.data('height2',$(this).height())
				.css({ backgroundImage: 'url(\''+$(this).attr('src')+'\')' })
				.click(function(){ $(this).animate({ height:$(this).data('height2') }); return false; })
				.mouseout(function(){ $(this).animate({ height:$(this).data('height1') }); });
			$(this).remove();
		};
		if($(this).height()>0)
			this.assignAnimation();
		else
			$(this).load(function(){ this.assignAnimation(); });
	});

	var iWidth = 0;
	$('#top-menu .li0').each(function(){ iWidth += $(this).width(); });
	if(iWidth<533)
	{
		iWidth = parseInt((533-iWidth)/$('#top-menu .li0').length/2);

		if(iWidth>8)
		$('#top-menu .li0').each(function(){
			$(this).css({ paddingLeft: iWidth, paddingRight: iWidth-8, backgroundPosition: (iWidth>19?19-(iWidth):iWidth-9)+'px 6px' });
		});
	}

	if(ie6)
	$('#top-menu li').hover(
		function(){ $(this).addClass('hover'); },
		function(){ $(this).removeClass('hover'); }
	);

} catch(err) { alert(["ERROR",err]); }; });

function randomProjectGallery()
{
	var aRandKeys = $('#projects-gallery').data('aRandKeys');
	if(null===aRandKeys || aRandKeys.length===0)
		aRandKeys = [0,1,2,3,4,5].sort(function(){ return (Math.round(Math.random())-0.5); });

	$('#projects-gallery img:eq('+aRandKeys.shift()+')').parent().fadeOut('fast',function(){
		$(this).parent().replaceWith($('#projects-gallery img:eq(6)').parent().parent()).appendTo('#projects-gallery');
		$('#projects-gallery .clear').appendTo('#projects-gallery');
		$(this).show();
	});

	$('#projects-gallery').data('aRandKeys',aRandKeys);
}
