



(function($){
$(document).ready(function(){

	
	if ($.browser.msie) $('body').addClass('ie');	


	
	
	if ($('.tournamentsList')[0]) {
		var lw = 0;
	    $('.tournamentsList > ul > li').each(function(){lw+=13+$(this).width();}); 
		$('.tournamentsList').eq(0).css({width:lw+'px'});
		//.appendTo('#page');
		$('.tournamentsList li').hover(function(){
			$(this).addClass('full');

			var ext = $(this).find('.ext').eq(0);

			var lw = $(this).width();
			var ww = $(this).parent().width();
			var ew = ext.width()+14;
			
			var pos = $(this).position().left;
			if (pos+ew>ww) {
				d = ww-pos-ew;
				ext.css({'left':d+'px'})
				}
			
			//console.log(d);
			},
			function(){
			$(this).removeClass('full');
			}
			);
			
		}	

	
	if ($('.board td')[0]) {
		$('.board td').each(function(){
			var chg = 0;
			var t = $(this).html();
			if (t.match(/^[AEINORSWZ]$/)) $(this).wrapInner('<div class="tile tile1"></div>');
			else if (t.match(/^[CDKLMPTY]$/)) $(this).wrapInner('<div class="tile tile2"></div>');
			else if (t.match(/^[BGHJŁU]$/)) $(this).wrapInner('<div class="tile tile3"></div>');
			else if (t.match(/^[ĄĘFÓŚŻ]$/)) $(this).wrapInner('<div class="tile tile5"></div>');
			else if (t.match(/^[Ć]$/)) $(this).wrapInner('<div class="tile tile6"></div>');
			else if (t.match(/^[Ń]$/)) $(this).wrapInner('<div class="tile tile7"></div>');
			else if (t.match(/^[Ź]$/)) $(this).wrapInner('<div class="tile tile9"></div>');
			else if (t.match(/^\[[A-ZĄĆĘŁŃÓŚŹŻa-ząćęłńóśźż]\]$/)) {
				$(this).html(t.replace(/^\[([A-ZĄĆĘŁŃÓŚŹŻa-ząćęłńóśźż])\]$/, "$1").toUpperCase());
				$(this).wrapInner('<div class="tile tile0"></div>');
				}
			else $(this).html('');

		
			if ($(this).hasClass('Lx2') || $(this).hasClass('lLx2') ||
				$(this).hasClass('Wx2') || $(this).hasClass('lWx2') ||
				$(this).hasClass('Lx3') || $(this).hasClass('lLx3') ||
				$(this).hasClass('Wx3') || $(this).hasClass('lWx3')) {
				$(this).wrapInner('<div class="bonus"></div>');
				
				//$(this).prepend('<div class="relationPoint"><div class="bonus"></div></div>');
			}
			$(this).wrapInner('<div class="relationPoint"></div>');
		
		});
	
	}
	
	$('.portlet-menu-launch').click(
		function(){
			$(this).parents('.portlet-decoration').eq(0).toggleClass('launched');
		}
	);
	$('.portlet-menu li.show').click(
		function(){
			$(this).parents('.portlet-decoration').eq(0).toggleClass('launched').parent().toggleClass('hidden');
		}
	);
	$('.portlet-menu li.hide').click(
		function(){
			$(this).parents('.portlet-decoration').eq(0).toggleClass('launched').parent().toggleClass('hidden');
		}
	);
	$('.portlet-title').dblclick(
		function(){
			$(this).parents('.portlet').eq(0).toggleClass('hidden');
		}
	);
	$('.portlet-menu li.up').click(
		function(){
			var e = $(this).parents('.portlet').eq(0);
			if ($(this).filter('.reloadable li.up')[0]) {
				if (e.prev()[0]) e.after(e.prev());
			}
			else if (e.prev()[0]) e.prev().before(e);
			$(this).parents('.portlet-decoration').eq(0).toggleClass('launched');
		}
	);
	$('.portlet-menu li.down').click(
		function(){
			var e = $(this).parents('.portlet').eq(0);
			if ($(this).filter('.reloadable li.down')[0]) {
				if (e.next()[0]) e.before(e.next());
			}
			else if (e.next()[0]) e.next().after(e);
			$(this).parents('.portlet-decoration').eq(0).toggleClass('launched');
		}
	);
	
	$('.achievements .achvs li').addClass('all');
	
	filterAchievements = function() {
		var flt = '';
		$('.achievements .filter li.active').each(function(){ flt+='.'+$(this).attr('rel'); });
		$('.achievements .achvs li').hide();
		$('.achievements .achvs li'+flt).show();
	}
	
	$('.achievements .filter li a').click(function(){
		$(this).parent().addClass('active').siblings().removeClass('active');
		filterAchievements();
		return false;
	});


});
})(jQuery);
/*	 */
