			$.extend($.fn.disableTextSelect = function() {
				return this.each(function(){
					if ($.browser.mozilla){
						$(this).css('MozUserSelect','none');
					} 
					else if ($.browser.msie){
						$(this).bind('selectstart', function() {
							return false;
						});
					}
					else {
						$(this).mousedown(function() {
							return false;
						});
					}
				});
			});
			
			$( function() {
				// Unselectable thumbnails in photostream
				$('.squareGallery li').disableTextSelect();
				
				if ( $("#messages p").length == 0 ) {
					$("#messages").hide();
				}
			})
			
			// Globalny loader pozycjonowany na gorze
			$(function() {
			    var $loader = $('div#globalLoader');
			    
			    $(document).ajaxStart(function() {
			    	$("button").attr("disabled", "disabled");
			    	$("button").addClass("disabledButton");
			    	$loader.show();
			    });
			    
			    $(document).ajaxError(function() {
			    	$("button").removeAttr("disabled");
			    	$("button").removeClass("disabledButton");
			    	$loader.find('img').attr('src', $loader.find('img').attr('src').replace('global_loader.gif', 'global_loader_error.gif'));
			    	$loader.addClass('globalLoaderError').show();
			    });
			    
			    $(document).ajaxComplete(function() {
			    	$("button").removeAttr("disabled");
			    	$("button").removeClass("disabledButton");
			        $loader.hide();
			    });
			});
			/*
			// Blokowanie wszystkich submitow form w momencie wyslania formularza
			$(function() {
				$('form').submit(function() {
					$(this).find('button').attr("disabled", "disabled");
					$(this).find('button').addClass("disabledButton");
				})
			});
			*/
			function h( type ) {
				if ( !type ) type = "notice";
				
				$("#messages p."+ type).hide()
				
			}
			
			function m( msg, type ) {
				if ( !type ) type = "notice";
				
				h( type )
				
				if ( $("#messages p.wait").length > 0 ) {
					$("#messages p.wait").html( msg ).animate( {
						width: 928
					} ).attr( "class", type );
					$("#messages p a.undo").click( function() {
						undo();
						
						$(this).unbind("click");
						
						m("Zdjęcie zostało przywrócone.");
						
						return false;
					});
				} else if ( $("#messages p").length > 0 ) {
					if (type != $("#messages p").attr("class")) {
						m_cont(msg, type + " multi");
					}
					else {
						$("#messages p a.undo").unbind("click");
						
						$("#messages p").remove();
						
						$("#messages").animate({
							opacity: 1
						}, 100, function(){
							m_cont(msg, type);
						});
					}
				} else {
					m_cont( msg, type );
				}
				
				function m_cont( msg, type ) {
					if ( $("#messages:hidden").length > 0 ) $("#messages").show();
					
					$("#messages").append("<p class='"+ type +"'><strong>"+ msg +"</strong></p>");
					
					$("#messages p a.undo").click( function() {
						undo();
						
						$(this).unbind("click");
						
						m("Zdjęcie zostało przywrócone.");
						
						return false;
					});
				}
			}
			
			function w( msg ) {
				if ( $("#messages p").length > 0 ) {
					$("#messages p a.undo").unbind("click");
					
					$("#messages p").remove();
				}
				
				if ( $("#messages:hidden").length > 0 ) $("#messages").show();
				
				$("#messages").append("<p class='wait'><strong>"+ msg +"</strong></p>");
			}
			
			function undo() {
				var old = $("#undo").attr("old_display");
				
				$("#undo").attr("id", "").css("opacity", 0).css("display", old ).animate({ opacity: 1 });
			}
			
			function o() {
				if ($("#overlay:visible").length > 0) {
					$("#overlay").animate({
						opacity: 0
					}, function(){
						$(this).css({
							display: "none"
						})
					});
				}
				else {
					$("#overlay").css({
						display: "block"
					}).animate({
						opacity: 1
					});
				}
			}

			$.postJSON = function(url, data, callback) {
				$.post(url, data, callback, "json");
			};
			
			$.ajaxJSON = function(type, url, data, async){
				$.ajax({
					type: type,
					url: url,
					data: data,
					dataType: "json",
					async: async
				});
			};
			
			$( function() {
				$("input[def], textarea[def]").each( function(el) {
					if ( $(this).val() == $(this).attr("def") || $(this).val() == "" ) $(this).css("color", "#999").val( $(this).attr("def") );
					
					$(this).focus( function() {
						if ( $(this).val() == $(this).attr("def") ) $(this).val("").css("color", "#000");
					}).blur( function() {
						if ( $(this).val() == "" ) $(this).css("color", "#999").val( $(this).attr("def") );
					});
				});
				
				$("form").submit( function() {
					$("input[def], textarea[def]", this).each( function() {
						if ( $(this).val() == $(this).attr("def") ) {
							$(this).val("");
						}
					});
				});
				
				$("input#uncover").change( function(){
					if ( $("input#uncover:checked").length > 0 ) {
						$("input[type=password]").each( function() {
							$(this).replaceWith( $(this).clone().attr("type", "text").attr("oldtype", "password") );
						})
						
						$(this).parent().children("span").html("ukryj hasła")
					} else {
						$("input[oldtype=password]").each( function() {
							$(this).replaceWith( $(this).clone().attr("type", "password").attr("oldtype", "") );
						})
						
						$(this).parent().children("span").html("pokaż hasła")
					}
				})
	
				$('#suggestLink').click(function(e) {
					showSuggestWindow();
					
					return false;
				});
				
				$(document).keyup(function(e) {
					if (e == null) {
						keycode = event.keyCode;
					}
					else {
						keycode = e.keyCode;
					}
					
					if (e.keyCode == 27 && $('#overlay').is(':visible')) {
						hideOverlay();
					}
				});
				
				$('#suggestWindow .delete.window, #suggestWindow .close').click(function() {
					hideSuggestWindow();
					
					return false;
				});
				
				$('#suggestWindow form.inline').submit(function() {
					sendSuggestForm($(this).find('select option:selected').val(), $.trim($(this).find('input[name=contact]').val()), $.trim($(this).find('textarea').val()));
					
					return false;
				});
			
				
				/********* ZMIANY W LAYOUCIE KONIEC MARCA 2010 **********/
				
				if ($('form.topLogin').length) {
					if ($('form.topLogin #pass1').val() == '') {
						$('form.topLogin #pass1').hide();
						$('form.topLogin #passDecoy').show();
					}
					else {
						$('form.topLogin #pass1').show();
						$('form.topLogin #passDecoy').hide();
					}
						
					$('form.topLogin #passDecoy').focus(function() {
						$('form.topLogin #pass1').show().focus();
						$('form.topLogin #passDecoy').hide();
					});
					
					$('form.topLogin #pass1').blur(function() {
						if ($(this).val() == '') {
							$('form.topLogin #pass1').hide();
							$('form.topLogin #passDecoy').show().blur();
						}
					});
				}
				
				if ($('#reg_email').length) {
					$('#reg_email, #reg_pass1').val('');
				}
				
				if ($('.overlayWindow a.cancel').length) {
					$('.overlayWindow a.cancel').click(function() {
						hideOverlay($(this).parents('.overlayWindow'));
						
						return false;
					});
				}
			});
			
			function showSuggestWindow() {
				$('#suggestWindow div.error.email, #suggestWindow div.error.message').remove();
				
				var maskHeight = $(document).height();
				var maskWidth  = $(document).width();
				var winH = $(window).height();
			    var winW = $(window).width();

				if (navigator.appName == 'Opera') {
					winH = window.innerHeight;
				    winW = window.innerWidth;
				}
				
				$('#suggest, #suggestMask, #suggestWindow').fadeIn(function() {
					$('#suggestMask').css('opacity', '0.7');
				});
				$('#suggestMask').css({'width': maskWidth, 'height': maskHeight, 'top': 0, 'left': 0});
				$('#suggestWindow').css({top: winH/2-$("#suggestWindow").height()/2, left: winW/2-$("#suggestWindow").width()/2});
			    
				if (!$('#suggestWindow input[name=contact][type=hidden]').length) {
					$('#suggestWindow input[name=contact]').focus();
				}
				else {
					$('#suggestWindow textarea').focus();
				}
			}
			
			function sendSuggestForm(subject, contact, message) {
				if (contact != '' && message != '') {
					hideSuggestWindow();
				
					$.postJSON( ROOT +"/ajax/", {method: "slajd.user.sendSuggestion", auth: AUTH, subject: subject, contact: contact, message: message, url: document.location.href}, function(d) {
						if ( d.stat == 'err' ){
							m("Wystąpił błąd. Prosimy spróbować później.", "error");
							
							return false;
						}
						else if ( d.stat == 'ok' && d.tags == '' ){
							return false;
						}
						
						m("Twoja sugestia została przesłana");
						$('#suggestWindow textarea').val('');
						
						if (!$('#suggestWindow input[name=contact][type=hidden]').length) {
							$('#suggestWindow input[name=contact]').val('');
						}
						
						clearErrors(contact, message);
					});
				}
				else if (contact == '' || message == '') {
					if (contact == '' && !$('#suggestWindow div.error.email').length) {
						$('<div class="error email">Podaj swój adres e-mail</div>').insertBefore('#suggestWindow label[for=contact]');
					}
					
					if (message == '' && !$('#suggestWindow div.error.message').length) {
						$('<div class="error message">Wpisz treść wiadomości</div>').insertBefore('#suggestWindow label[for=message]');
					}
					
					clearErrors(contact, message);
				}
			}
			
			function hideSuggestWindow() {
				$('div#suggest, div#suggestWindow').animate({opacity: 0}, 'normal', function() {
					$(this).css({display: 'none', opacity: 1});
				});
			}
			
			function clearErrors(contact, message) {
				if (contact != '') {
					$('#suggestWindow div.error.email').remove();
				}
				
				if (message != '') {
					$('#suggestWindow div.error.message').remove();
				}
			}
			
			function escape(str) {
				return jQuery.trim(str.replace(/>/g, "&gt;").replace(/</g, "&lt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;"));
			}
			
			Array.prototype.findIndex = function( value, assoc ){
				if ( typeof(assoc) != 'undefined' ){
					var idx = 0;
					for (var key in this){
						if ( key == value ){
							return idx;
						}
						idx++;
					}
					return null;
				}
				else {
					for (var i=0; i<this.length; i++){
						if ( this[i] == value ){
							return i;
						}
					}
					return null;
				}
			}
			
			function slice(start, end){
				var sliceObj = new Object();
				var idx = 0;
				for (var key in this){
					if ( idx >= start && idx <= end ){
						sliceObj[key] = this[key]
					}
					idx++;
				}
				return sliceObj;
			}
			
			//Object.prototype.join = function(sep){
			//	return 'dupa,cipa';
			//};
			
			/*function disableLink(e){
				e.unbind('click');//.css('color','#6F6F6F').css('cursor', 'default');
			}
			
			function enableLink(e){
				e.bind('click');//.css('color','#0049A3').css('cursor', 'pointer');
			}*/
			
			function pluralizer(num, form1, form2, form3) {
				if (num == 1) {
					ret = form1;
				}
				else if (num > 1 && num < 5) {
					ret = form2;
				}
				else {
					ret = form3;
				}
				
				return ret;
			}
			
			function showLoginWindow(type) {
				showOverlay('#loginWindow');
				
				if ($('#loginWindow input[name=type]').length) {
					$('#loginWindow input[name=type]').remove();
				}
				
				$('#loginWindow fieldset').append('<input type="hidden" name="type" value="' + type + '" />');
				$('#loginWindow input#email').focus();
			}
			
			function hideLoginWindow() {
				hideOverlay('#loginWindow');
			}
			
			function showOverlay(windowId) {
				var maskHeight = $(document).height();
				var maskWidth  = $(document).width();
				var winH = $(window).height();
			    var winW = $(window).width();

				if (navigator.appName == 'Opera') {
					winH = window.innerHeight;
				    winW = window.innerWidth;
				}
				
				$(windowId).addClass('overlayWindow');
				$('#overlay').show().animate({opacity: 0.7});
				$(windowId).css({top: winH/2-$(windowId).height()/2, left: winW/2-$(windowId).width()/2}).show().animate({opacity: 1});
			}
			
			function hideOverlay() {
				$('#overlay, #overlayMask, .overlayWindow').animate({opacity: 0}, 'normal', function() {
					$('#overlay').empty().removeAttr('style');
					$('.overlayWindow').hide();
				});
			}
			
			function calculateRateScore(rate) {
				totalWidth = 110;
				scoreWidth = totalWidth / 5;
				width = scoreWidth * rate;
				
				return width;
			}
			
			function isChrome() {
			    if (navigator.appVersion.indexOf('Chrome') != -1) {
			        return true;
			    }
			    
			    return false;
			}
			
			
			
			var sendStat = function(type){
				pagetype = $('ul.sharelist').attr('id');
				isLogged = 0;
				if(USER_ID && USER_ID > 0)
					isLogged = 1;
				pageTracker._setCustomVar(1,"loggedIn", isLogged,1);
				pageTracker._setCustomVar(2,"pageType", pagetype+type,3);
				pageTracker._trackPageview();
			}

			$(document).ready(function() {
				$('#share_facebook').click(function(){sendStat('facebook')});
				$('#share_blip').click(function(){sendStat('blip')});
				$('#share_sledzik').click(function(){sendStat('sledzik')});
				$('#share_wykop').click(function(){sendStat('wykop')});
				$('#share_grono').click(function(){sendStat('grono')});
			});
