$(document).ready(
	
		function() {
			var timerIdK = 0;
			var timerIdO = 0;

			$('#m4').mouseover(function() {
				if ($('#kursy').css('display') == 'none') {
					$('#kursy').stop(true, true).slideDown(300);
					$('#ulKursy').stop(true, true).fadeIn(600);
				} else {
					clearTimeout(timerIdK);
				}
			});
			$('#m4').mouseout(function() {
				timerIdK = setTimeout(function() {
					$('#ulKursy').hide();
					$('#kursy').stop(true, true).slideUp(200);
				}, 300);
			});
			$('#m1').mouseover(function() {
				if ($('#onas').css('display') == 'none') {
					$('#onas').stop(true, true).slideDown(300);
					$('#ulOnas').stop(true, true).fadeIn(600);
				} else {
					clearTimeout(timerIdO);
				}
			});
			$('#m1').mouseout(function() {
				timerIdO = setTimeout(function() {
					$('#ulOnas').hide();
					$('#onas').stop(true, true).slideUp(200);
				}, 300);
			});
			preloadImages = function() {
				for ( var i = 0; i < arguments.length; i++) {
					jQuery("<img>").attr("src", arguments[i]);
				}
			}
			$("#news img").wrap("<div class='fakeImage'></div>").animate( {
				opacity : 0
			}, 1);
			$("#news img").mouseover(
					function() {
						var adresFoty = $(this).attr("src");
						$(".tooltip img").replaceWith(
								"<img src='" + adresFoty + "' alt='' />"
						);
			});
			
			$('#facebook').mouseover(function() {
				$(this).stop(true, false).animate({
					right:0
				}, 800)
			})
			
			$('#facebook').mouseout(function() {
				$(this).stop(true,false).animate({
					right:-190
				}, 600)
			})
		
			$("#news img").tooltip( {
				position : 'bottom right',
				tip : '.tooltip',
				effect : 'slide',
				slideOffset : 50,
				offset : [ 0, 20 ],
				relative : 'true'
			});
			
			var tablicaWysokosci = new Array();
			
			$('#news p').each(function(){
				var klasa = $(this).attr('class');
				var wysokosc = $(this).height();
				tablicaWysokosci[klasa] = wysokosc;
				$(this).css('height', '56px');	
				});
			
			
			$('#news p').click(function() {
				var klasa = $(this).attr("class");
				var oldHeight = tablicaWysokosci[klasa];
				
				if ($(this).css('height') == '56px') {
					$(this).animate( {
						height : oldHeight
					}, {
						duration : oldHeight*2+300
					});
					$("div." + klasa).css("background-position", "0 -10px");
				} else {
					$(this).animate( {
						height : '56px'
					}, {
						duration : 500
					});
					setTimeout(function() {
						$("div." + klasa).css("background-position", "0 0");
					}, 500);
				}
			});
			$('#news div').click(function() {
				var klasa = $(this).attr("class");
				var oldHeight = tablicaWysokosci[klasa];
				if ($("p." + klasa).css('height') == '56px') {
					$("p." + klasa).animate( {
						height : oldHeight
					}, {
						duration : oldHeight*2+300
					});
					$(this).css("background-position", "0 -10px");
				} else {
					$("p." + klasa).animate( {
						height : '56px'
					}, {
						duration : oldHeight*2+300
					});
					setTimeout(function() {
						$("div." + klasa).css("background-position", "0 0");
					}, oldHeight*2+300);
				}
			});

			$("input[name='url']").hide();
			var wartosc;
			$('#zapisy input').focus(function() {
				wartosc = $(this).attr('value');
				$(this).attr( {
					value : ""
				});
			});
			$('#zapisy input').blur(function() {
				if ($(this).attr('value') != '') {
					$(this).unbind('focus');
				} else {
					$(this).attr( {
						value : wartosc
					});
				}
			});
			$('form.blad > input').unbind('focus');
			
			preloadImages("/img/menu1.png", "/img/kursy.png",
					"/img/kursy1.png", "/img/onas.png", "/img/onas1.png",
					"/img/kursy2.png", "/img/onas2.png");
			
});
