$(document).ready(function(){
/*
    $('#wrapper').center();
    $('#wrapper').parent().css("position","static");
*/

    $("#menu a img").hover(
        function(){
            if($(this).attr("src").indexOf("-on.") == -1) {
                var newSrc = $(this).attr("src").replace("-off.", "-on.");
                $(this).attr("src",newSrc);
            }
        },
        function(){
            if($(this).attr("src").indexOf("-on.") != -1 && !$(this).hasClass('current')) {
                var oldSrc = $(this).attr("src").replace("-on.", "-off.");
                $(this).attr("src",oldSrc);
            }
        }
    );
	$('#content').jScrollPane({reinitialiseOnImageLoad:true, scrollbarMargin:10});
	$.browser.msie6 = $.browser.msie && /MSIE 6\.0/i.test(window.navigator.userAgent) && !/MSIE 7\.0/i.test(window.navigator.userAgent) && !/MSIE 8\.0/i.test(window.navigator.userAgent);
	if ($.browser.msie6) {		
		DD_belatedPNG.fix('*');
	}
	
	$("#newsletter-submit").click(function(){
		var inputVal = $("#email_address").val();
		if(inputVal=='') {
			show_info("Musisz podać adres emailowy.", 0);
			return false;
		}
		else {
			$("#newsletter-form").ajaxForm({
	    		type: "POST",
	    		dataType: "json",
	    		success: function(data) {
	    			$("#newsletter-form").resetForm();
	    			show_info(data.result, data.code);
	    			show_info(data.result, data.code);
	    		}
   			});
		}		
	});
	
	function show_info(info, code) {
		var hideIt;
		if (code == 0) {
			hideIt = function() { hide_info(); };
		}
		else if (code == 1) {
			hideIt = function() { hide_info(); };
		}
				
		$("#newsletter-notifier").html(info).show();
		setTimeout(hideIt, 5000);
	}
	function hide_info() {
		$("#newsletter-notifier").hide();
	}
});

$.preloadImages = function() {
    for(var i = 0; i < arguments.length; i++) {
        $("><img>").attr("src", arguments[i]);
    }
}

$(window).bind('load', function() {
    $('img.menu-item').each(function(elm) {
        $.preloadImages($(this).attr("src").replace("-off.", "-on."));
    });
});



$(document).ready(function(){
	var w = document.body.parentNode.clientWidth;
	var h = document.body.parentNode.clientHeight;
	var div_w = $("#wrapper").width();
	var div_h = $("#wrapper").height();
	if((h-div_h)/2 > 0) $('#wrapper').css({ position:"relative", top:(h-div_h)/2, left:(w-div_w)/2, width:div_w, height:div_h });
	else $('#wrapper').css({ position:"relative", top:0, left:(w-div_w)/2, width:div_w, height:div_h });

});

var resizeTimer = null;

function centerize() {
	var div_w = $("#wrapper").width();
	var div_h = $("#wrapper").height();
	var w1 = document.body.parentNode.clientWidth-div_w;
	var h1 = document.body.parentNode.clientHeight-div_h;
	$("#wrapper").animate({left:w1/2});
	if((h1)/2 > 0) $("#wrapper").animate({top:h1/2});
	else $("#wrapper").animate({top:0});
}

$(window).bind("resize", function(e){
	if (resizeTimer) clearTimeout(resizeTimer);
	resizeTimer = setTimeout(centerize, 300);
});



