$(document).ready(function(){
// Content box tabs:
		
		$('.content-box .content-box-content div.tab-content').hide(); // Hide the content divs
		$('ul.content-box-tabs li a.default-tab').addClass('current'); // Add the class "current" to the default tab
		$('.content-box-content div.default-tab').show(); // Show the div with class "default-tab"
		
		$('.content-box ul.content-box-tabs li a').click( // When a tab is clicked...
			function() { 
				$(this).parent().siblings().find("a").removeClass('current'); // Remove "current" class from all tabs
				$(this).addClass('current'); // Add class "current" to clicked tab
				var currentTab = $(this).attr('href'); // Set variable "currentTab" to the value of href of clicked tab
				$(currentTab).siblings().hide(); // Hide all content divs
				$(currentTab).show(); // Show the content div with the id equal to the id of clicked tab
				return false; 
			}
		);
        
// Sidebar Accordion Menu Hover Effect:
		
		$("#main-nav li .nav-top-item").hover(
			function () {
				$(this).stop().animate({ paddingRight: "25px" }, 200);
			}, 
			function () {
				$(this).stop().animate({ paddingRight: "15px" });
			}
		);
        
        //Close button:
		
		$(".close").click(
			function () {
				$(this).parent().fadeTo(400, 0, function () { // Links with the class "close" will close parent
					$(this).slideUp(400);
				});
				return false;
			}
		);
        
        // Check all checkboxes when the one in a table head is checked:
		
		$('.check-all').click(
			function(){
				$(this).parent().parent().parent().parent().find("input[type='checkbox']").attr('checked', $(this).is(':checked'));   
			}
		);
		
		$('a.check-all').click(function(){
            if($(this).attr('title') == 'checked')
            {
                $("input[type='checkbox']").attr('checked', 'checked');
                $('a.check-all').attr('title', 'uncheck');
                $('a.check-all').html('Отменить выделение');
            }
            else
            {
                $("input[type='checkbox']").attr('checked', '');
                $('a.check-all').attr('title', 'checked');
                $('a.check-all').html('Выделить все');
            }
            
            return false;
		});
		
		$('tr input[type=checkbox]').click(function(){
    
        var el = $("tr").has($(this));
            change_background(el, $(this).attr('checked'));
       }); 
       
       $(".checkall").click(function(){
            var checkboxes = $("table").has($(this)).find("input[type='checkbox']");
            checkboxes.attr('checked', $(this).is(':checked'));
            
            var el = $("tr").has(checkboxes);
            change_background(el, $(this).attr('checked'));
       });
       
       $(".action").click(function(){
          $(this).siblings('.opmenu').css('display', 'block');
       });
       
       $(".opmenu").mouseleave(function(){
            $(this).css('display', 'none');
       });
});

function change_background(el, type)
{
    if(type) {
        el.addClass('row-active');
    } else {
        el.removeClass('row-active');
    }
}
