
$(document).ready(function(){
	//Sidebar Accordion Menu:
		$("#menu li ul").hide(); // Hide all sub menus
		$("#menu li a.aktualne").parent().find("ul").slideToggle("slow"); // Slide down the aktualne menu item's sub menu
		
		$("#menu li a.menu_navi").click( // When a top menu item is clicked...
			function () {
				//$(this).parent().siblings().find("ul").slideUp("normal"); // Slide up all sub menus except the one clicked
				//$(this).next().slideToggle("normal"); // Slide down the clicked sub menu
                $(this).parent().find("ul").slideToggle("normal");
				return false;
			}
		);
		
		$("#menu li a.no-submenu").click( // When a menu item with no sub menu is clicked...
			function () {
				window.location.href=(this.href); // Just open the link instead of a sub menu
				return false;
			}
		); 

    // Sidebar Accordion Menu Hover Effect:
		
		$("#menu li .menu_navi").hover(
			function () {
				$(this).stop().animate({ paddingRight: "25px" }, 200);
			}, 
			function () {
				$(this).stop().animate({ paddingRight: "15px" });
			}
		);

    //Minimize Content Box
		
		//$(".kwadrat_nag h3").css({ "cursor":"s-resize" }); // Give the h3 in Content Box Header a different cursor
		$(".kwadrat_zakmnij .kwadrat_tresc").hide(); // Hide the content of the header if it has the class "closed"
		$(".kwadrat_zakmnij .kwadrat_karta").hide(); // Hide the tabs in the header if it has the class "closed"
		
		//$(".kwadrat_nag h3").click( // When the h3 is clicked...
		//	function () {
		//	  $(this).parent().next().toggle(); // Toggle the Content Box
		//	  $(this).parent().parent().toggleClass("kwadrat_zakmnij"); // Toggle the class "kwadrat_zakmnij" on the content box
		//	  $(this).parent().find(".kwadrat_karta").toggle(); // Toggle the tabs
		///	}
		//);

    // Content box tabs:
		
        $('.kwadrat .kwadrat_tresc div.karta_tresc').hide(); // Hide the content divs
		$('ul.kwadrat_karta li a.karta_domyslna').addClass('aktualne'); // Add the class "aktualne" to the default tab
		$('.kwadrat_tresc div.karta_domyslna').show(); // Show the div with class "karta_domyslna"
		
		$('.kwadrat ul.kwadrat_karta li a').click( // When a tab is clicked...
			function() {
                                if ($(this).hasClass('zapotrzebowanie_ajax'))
                                {
                                                name = $(this).attr('href');
                                                new_needs(name.substring(1, name.length));
                                }
				$(this).parent().siblings().find("a").removeClass('aktualne'); // Remove "aktualne" class from all tabs
				$(this).addClass('aktualne'); // Add class "aktualne" to clicked tab
				var aktualneTab = $(this).attr('href'); // Set variable "aktualneTab" to the value of href of clicked tab
				$(aktualneTab).siblings().hide(); // Hide all content divs
				$(aktualneTab).show(); // Show the content div with the id equal to the id of clicked tab
				return false; 
			}
		);

    //Close button:
		
		$(".close").click(
			function () {
				$(this).parent().fadeTo(400, 0, function () { // Links with the class "close" will close parent
					$(this).slideUp(400);
				});
				return false;
			}
		);

    // Alternating table rows:
		
		$('tbody:not(#trzy) tr:even').addClass("alt-row"); // Add class "alt-row" to even table rows
        
        var i = 1;
        var alt = true;
        $('#trzy').find('tr').each(function(){
                if (alt)
                    $(this).addClass("trzyzero");
                else
                    $(this).addClass('trzyjeden');
                if (i % 3 == 0)
                        alt = !alt;
                i++;
        });

    // Check all checkboxes when the one in a table head is checked:
		
		$('.spr_wsz').click(
			function(){
				$(this).parent().parent().parent().parent().find("input[type='checkbox']").attr('checked', $(this).is(':checked'));   
			}
		);

    // Initialise Facebox Modal window:
		
		$('a[rel*=modal]').facebox(); // Applies modal window to any link with attribute rel="modal"

    // Initialise jQuery WYSIWYG:
		
		$(".wysiwyg").wysiwyg(); // Applies WYSIWYG editor to any textarea with the class "wysiwyg"
        
        //info dla ikonek
        $('#image_info').hide();
        $(".imadze").mouseenter(function(){
                //pokaz
                if ($('#image_info').is(':hidden'))
                {
                        var pos = getXY(this);
                        $('#image_info').html($(this).attr('title'));
                        h = $('#image_info').height();
                        w = $('#image_info').width();
                        $('#image_info').css('top', pos[1] - 40 - (h / 2 + h / 4)).css('left', pos[0] - ($(this).width() / 2) - (w / 2)).show();
                }
        });
        $(".imadze").mouseleave(function(){
                //ukryj
                if ($('#image_info').is(':visible'))
                $('#image_info').hide();
        });
        
        //VALIDATORY!!
        $('.blur').blur(function(){
			$(this).click(validate_blur(this));
		});
        
        $('input[type=radio]').click(function(){
           set_valid(this, true);    
        });
});

function closep(obj)
{
        $(obj).parent().fadeTo(400, 0, function () { // Links with the class "close" will close parent
                $(this).slideUp(400);
        });
        return false;
}

function set_imadze()
{
        $(".imadze").mouseenter(function(){
                //pokaz
                if ($('#image_info').is(':hidden'))
                {
                        var pos = getXY(this);
                        $('#image_info').html($(this).attr('title'));
                        h = $('#image_info').height();
                        w = $('#image_info').width();
                        $('#image_info').css('top', pos[1] - 40 - (h / 2 + h / 4)).css('left', pos[0] - ($(this).width() / 2) - (w / 2)).show();
                }
        });
        $(".imadze").mouseleave(function(){
                //ukryj
                if ($('#image_info').is(':visible'))
                $('#image_info').hide();
        });
        $('tbody:not(#trzy) tr:even').addClass("alt-row");
}
  
  
  
