(function($) {
  $.fn.fullBg = function(){
    var bgImg = $(this).find('img'); 
    /*function resizeImg() {
      var imgwidth = bgImg.width();
      var imgheight = bgImg.height();
 
      var winwidth = $(window).width();
      var winheight = $(window).height();
 
      var widthratio = winwidth / imgwidth;
      var heightratio = winheight / imgheight;
 
      var widthdiff = heightratio * imgwidth;
      var heightdiff = widthratio * imgheight;
 
      if(heightdiff>winheight) {
        bgImg.css({
          width: winwidth+'px',
          height: heightdiff+'px'
        });
      } else {
        bgImg.css({
          width: widthdiff+'px',
          height: winheight+'px'
        });		
      }
    }*/
    function resizeImg() {
 		var imgwidth = bgImg.width();
		var imgheight = bgImg.height();
		var winwidth = $(window).width();
		var winheight = $(window).height();
		var widthratio = winwidth / imgwidth;
		var heightratio = winheight / imgheight;
		var widthdiff = heightratio * imgwidth;
		var heightdiff = widthratio * imgheight;
		var topPos = -(heightdiff-winheight) /2;
		var leftPos = -(widthdiff-winwidth) /2;
		if(heightdiff > winheight) {
 			bgImg.css({
				width: winwidth+'px',
				height: heightdiff+'px',
				left:"0px",
				top:topPos+"px"
			});
		}
		else {
			bgImg.css({
				width: widthdiff+'px',
				height: winheight+'px',
				left:leftPos+"px",
				top:"0px"
			});		
		}
	}
    resizeImg();
	$("#intro").css({width: $(window).width(), height: $(window).height()})
    $(window).resize(function() {
		resizeImg();
		$("#intro").css({width: $(window).width(), height: $(window).height()})
    }); 
  };
})(jQuery)
function introImg() {
	var kopiuj = $("#intro .images img:last").clone();
	$("#intro .images").prepend(kopiuj);
	$("#intro .images img:last").fadeOut(2500, function() {
		$(this).remove()
	});
	$("#intro .pasek .postep").css({width: 0}).animate({width: "100%"}, 9900);
}

Cufon.replace('.headline div, .headline a, h2', {
	hover: true,
});

Cufon.replace('.haslo', {
	textShadow: '1px 1px rgba(0,0,0,.60)' 
});

$(window).load(function() {
	/* obrazek w tle */
	$("#intro .images").fullBg();

	/* startowanie zmieniarki teł */
	$("#intro .pasek .postep").css({width: 0}).animate({width: "100%"}, 9900);
	var playSlideshow = setInterval("introImg()", 10000);
	//$("#intro .wybor").animate({height: 65},750);

	/* okieno wejścia */
	//$("#intro .wybor").find(".logo, .langs").fadeIn(2500);
	$("#intro .copyrights .right").click(function() {
		$("#intro .desc .wstep").slideToggle();
		if($(this).find('img').is(".rotated")) {
			$(this).find('img').animate({'rotate': 0}).removeClass('rotated');
		} else {
			$(this).find('img').animate({'rotate': 179}).addClass('rotated');
		}
	});

	/* jezyki */
	$('#intro .langs h3').hover(function() {
		var aktywny = $(this).attr("class");
		$.each($('#intro .langs h3'), function() {
			var temp_id = $(this).attr("class");
			if(temp_id != aktywny) {
				$(this).find("img").stop(true, false).animate({opacity: '0.25'}, 400);
			} else {
				$(this).find("img").stop(true, false).animate({opacity: '1'}, 400);
			}
		});
		
		if($.browser.msie && parseInt($.browser.version)<9){
			$('#intro .langs .headline a').not("."+aktywny).fadeOut(function() {
				$(this).css({display: 'none'});
				$('#intro .langs .headline a.'+aktywny).fadeIn();
			});
			
			$('#intro .haslo div').not("."+aktywny).fadeOut(function() {
				$(this).css({display: 'none'});
				$('#intro .haslo div.'+aktywny).fadeIn();
			});
			$('#intro .desc .wstep div').not("."+aktywny).fadeOut(function() {
				$(this).css({display: 'none'});
				$('#intro .desc .wstep div.'+aktywny).fadeIn();
			});			
		}else{
			$.each($('#intro .langs .headline a, #intro .haslo div, #intro .desc .wstep div'), function() {
				var temp_id = $(this).attr("class");
				if(temp_id != aktywny) {
					$(this).stop(true, false).animate({opacity: '0'}, 400, function() {
						$(this).css({display: 'none'});
					});
				} else {
					$(this).stop(true, false).animate({opacity: '1'}, 400).css({display: 'block'});
				}			
			});			
		}	
		

	}, function() {
		$('#intro .langs h3 img').stop(true, false).animate({opacity: '1'}, 400);
		$.each($('#intro .langs .headline a, #intro .haslo div, #intro .desc .wstep div'), function() {
			var temp_id = $(this).attr("class");
			if(temp_id != 'pl') {
				$(this).stop(true, false).animate({opacity: '0'}, 400, function() {
					$(this).css({display: 'none'});
				});
			} else {
				$(this).stop(true, false).animate({opacity: '1'}, 400).css({display: 'block'});
			}			
		});
	});
});
