var tooltip_title;

$(document).ready(function(){
	
	/*
	// Dashboard open/close
	$('#col_right .dashboard_right a').click(function(){	
		$('#col_right .dashboard').slideToggle(400);
		$('img', this).attr('src', toggleImage($('img', this).attr('src')));
		return false;
	});
	
	// Dashboard previous/next
	$('#col_right .dashboard ul.nav li a').click(function(){
		
		var nextGraph = 0;
		var totalGraphs = 0;
		var next = ($(this).parent().attr('class') == "next");

		$('#col_right .dashboard .graph').each(function(i){
			if ($(this).is(':visible')) {
				if (next) {
					nextGraph = i + 1;
				}
				else {
					nextGraph = i - 1;
				}
			}
			totalGraphs = i;
		});
		
		if (nextGraph > totalGraphs) nextGraph = 0;
		if (nextGraph < 0) nextGraph = totalGraphs;
		
		$('#col_right .dashboard .graph:visible').hide();
		$('#col_right .dashboard .graph').eq(nextGraph).show();
		
		return false;
	});
	*/
	
	$('.show_staff_handbook').click(function()
	{
		
		  var url = "/handbook"
		  
		  //find out which entity we're checking
		  
		  var dialog = $('<div style="display:hidden;width:400px;"></div>').appendTo('body');
        // load remote content
        dialog.load(
            url, 
            {},
            function (responseText, textStatus, XMLHttpRequest) {
                dialog.dialog({ modal: true, 
              	  title: 'UK Staff Handbook Content',
              	width: 400,
                });
            }
        );
        //prevent the browser to follow the link
        return false;
	});
	
	
	// Tooltip
	$('.tooltip').hover(function(){
		
		tooltip_title = $(this).attr('title');
		var top = $(this).position().top - $(this).height();
		var left = $(this).position().left + ($(this).width() / 2);
		var title = tooltip_title;
		
		if (title.indexOf('|') !== -1) {
			var split = title.split('|');
			title = '<h1>' + split[0] + '</h1>' + split[1];
		}
		
		var tooltip = '<div id="tooltip" style="top: ' + top + 'px; left: ' + left + 'px"><div class="top">' + title + '</div><div class="bottom"></div></div>';

		// Remove title
		$(this).attr('title', '');

		// Show tooltip
		$(tooltip).appendTo('body');

	}, function() {
		
		// Add title back
		$(this).attr('title', tooltip_title);

		// Remove tooltip
		$('#tooltip').remove();
	});
	
	// Our values
	$('div.our_values div.box').hover(function(){
		$('div.out', this).hide();
		$('div.over', this).show();
	}, function() {
		$('div.out', this).show();
		$('div.over', this).hide();
	});
	
	// Shadowbox
	Shadowbox.init({
		handleOversize: "drag",
		overlayOpacity: 0.8
	});
	
	//$(".more").hide();
	//$(".menu_tab_item div.menu_tab_item_child").hide();
	//$(".menu_tab_item.selected div.menu_tab_item_child").show();
});

function toggleImage(src) {
	if (src.indexOf('_up') !== -1) {
		return src.replace('_up', '_down');
	}
	else {
		return src.replace('_down', '_up');
	}
}

function openEnlargeWindow(id, print) {
	return open('/index.php?action=PublicDisplayGraphEnlarge&graph_id=' + id + '&print=' + print,'newwin','toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=0,width=610,height=610');
}

function toggleCheckbox(check, group) {
	$('div.group' + group + ' input').each(function(){
		if (check) {
			$(this).attr('checked', 'checked');
			//$(this).attr('disabled', 'disabled');
		}
		else {
			$(this).removeAttr('checked', 'checked');
		}
	});
}
