/////////////////////////////////////////////////////////////////////////////////////////

function initSizing()
{
	initInterfaceDivs();
	
	$('#logo').attr("src", header_logo_image);
	$('#biglogo').attr("src", header_logo_big_image);
	
	//togglePopupMenu();
	
	$(window).bind('resize', function() {hideAllPanels(); fixDivSizes(); setTimeout(function(){fixDivSizes();}, 50);}).trigger('resize');
	
	$('body').show();
	setTimeout(function(){$('#loader').hide(); fixDivSizes();}, 250);
}

/////////////////////////////////////////////////////////////////////////////////////////

function fixDivSizes()
{
	positionMainInterface();
	
	var fht = $('#footer').height();
	var hht = $('#header').height();
	var wh = $(window).height();
	var rpht = wh-fht-hht-20;
	//$('#content').css('height', wh-fht-hht-20);
	$('#reportpane').css('height', rpht);
	//$('#categorypane').css('height', rpht);
	
	var reports_title_height = $('#reportpane').find('.ui-jqgrid-titlebar').outerHeight();
	var reports_header_height = $('#reportpane').find('.ui-jqgrid-htable').outerHeight();
	var reports_pager_height = $('#pg_reportstablepager').height();
	
	var reportstablewidth = $("#reportpane").width()-(11*2) + 23;
	var reportstableheight = $("#reportpane").height()-reports_title_height-reports_pager_height-reports_header_height-20-4 + 23;
	
	jQuery("#reportstable").setGridWidth(reportstablewidth, false); 
	jQuery("#reportstable").setGridHeight(reportstableheight);
	$('#reportstablepager_left').css('width', '');
	
	$("#reportstable").closest("div.ui-jqgrid-view")
    .children("div.ui-jqgrid-titlebar")
    .css("text-align", "center")
    .children("span.ui-jqgrid-title")
    .css("float", "none");
	
	var lpw = 0;
	if($("#leftpane").length != 0)
		lpw = $("#leftpane").width();
	if(lpw < 0)
		lpw = 0;
	var lph = $("#reportpane").height();
	var tabh = $(".ui-tabs-nav").height() + 6; 
	var ctw = lpw-(10*2);
	if(ctw < 0)
		ctw = 0;
	var ctpadx = 21, ctpady = 24;
	if($('#domaincategorytable').is(':visible')) {
		var domain_pager_height = $('#pg_domaincategorytablepager').height();
		var domain_header_height = $('#gbox_domaincategorytable').find('.ui-jqgrid-htable').outerHeight();
		var cth = lph-domain_pager_height-domain_header_height-tabh-20;
		jQuery("#domaincategorytable").setGridWidth(ctw+ctpadx, true); 
		jQuery("#domaincategorytable").setGridHeight(cth+ctpady); 
	}
	else if($('#domainquerytable').is(':visible')) {
		var domain_pager_height = $('#pg_domainquerytablepager').height();
		var domain_header_height = $('#gbox_domainquerytable').find('.ui-jqgrid-htable').outerHeight();
		var qth = lph-domain_pager_height-domain_header_height-tabh-20;
		jQuery("#domainquerytable").setGridWidth(ctw+ctpadx, true); 
		jQuery("#domainquerytable").setGridHeight(qth+ctpady); 
	}
	
	positionCustomQueriesWindow();
}

/////////////////////////////////////////////////////////////////////////////////////////

function positionMainInterface()
{
	var lpw = 0;
	if($("#leftpane").length != 0)
		lpw = $("#leftpane").width();
	if(lpw < 0)
		lpw = 0;
	var lph = $("#reportpane").height();
	
	var fh = 0;
	if($('#footer').is(':visible'))
		fh = $('#footer').outerHeight();
	
	var headheight = $("#header").outerHeight();
	var dheight = $(window).height()-fh-headheight;
	if($(window).height() <= 612) 
		dheight = 612-fh-headheight;
	
	jQuery("#content").height(dheight, true); 
	$(".reportdata").css('height', dheight+3);
}

/////////////////////////////////////////////////////////////////////////////////////////

function positionCustomQueriesWindow()
{
	var lph = $("#leftpane").height();
	var tabh = $('#categorytab').find(".ui-tabs-nav").height() + 6; 
	var panel_height = lph-tabh-20;
	$("#customqueries").css('height', panel_height+1);
	
	var offset = 0;
	if($("#customqueries-box").height() >= panel_height)
		offset = 24;
}

/////////////////////////////////////////////////////////////////////////////////////////

function initInterfaceDivs()
{
	// Add a bunch of dummy divs so that we can adjust the colors
	$("#header").append('<div class="ui-widget-content" style="display:none"></div>');
	$("#header").append('<div class="ui-widget-header" style="display:none"></div>');
	$("#header").append('<div class="ui-state-default" style="display:none"></div>');
	$("#header").append('<div class="ui-state-highlight" style="display:none"></div>');
	$("#header").append('<div class="ui-state-active" style="display:none"></div>');
	$("#header").append('<div class="ui-state-hover" style="display:none"></div>');
	$("#header").append('<div class="ui-state-error" style="display:none"></div>');
}
