var patch_width = 149;
var patch_height = 129;

var hovertexts = new Object;
var normaltexts = new Object;
var hoversizes = new Object;

normaltexts.cell1 = "Security Services";
normaltexts.cell2 = "Investigations";
normaltexts.cell3 = "Missing Persons Investigations";
normaltexts.cell4 = "Cyber Security";
normaltexts.cell5 = "Asset Recovery";
normaltexts.cell6 = "Facility Management";
normaltexts.cell7 = "Project Management";
normaltexts.cell8 = "Legal Services";
normaltexts.cell9 = "Proud Affiliates";
normaltexts.cell10 = "Overseas Law Enforcement Instructor Job Opportunities";
normaltexts.cell11 = "CBT / Training &amp; Exercises";
normaltexts.cell12 = "Honorable Warriors Fellowship Network";
normaltexts.cell13 = "About G1";
normaltexts.cell14 = "Mission &amp; Values";
normaltexts.cell15 = "NAICS Codes";
normaltexts.cell16 = "Contact Us";

hoversizes.cell1 = "1em";
hoversizes.cell2 = ".7em";
hoversizes.cell3 = "1em";
hoversizes.cell4 = ".7em";
hoversizes.cell5 = ".8em";
hoversizes.cell6 = "1.1em";
hoversizes.cell7 = ".7em";
hoversizes.cell8 = "1em";
hoversizes.cell9 = "1.3em";
hoversizes.cell10 = ".65em";
hoversizes.cell11 = ".7em";
hoversizes.cell12 = ".7em";
hoversizes.cell13 = ".9em";
hoversizes.cell14 = "1.3em";
hoversizes.cell15 = "1.3em";
hoversizes.cell16 = "1.3em";

hovertexts.cell1 = "<ul><li>Armed / Unarmed</li><li>Patrol &amp; Event Security</li><li>Campus Response</li></ul>";
hovertexts.cell2 = "<ul><li>Case Development</li><li>Background Checks</li><li>Threat Assessment</li><li>Corp. Investigations</li><li>General Investigations</li><li>Litigation Support</li></ul>";
hovertexts.cell3 = "<ul><li>Missing Persons</li><li>Kidnap Victims</li><li>Threat Assessment</li></ul>";
hovertexts.cell4 = "<ul><li>Backup &amp; Restore</li><li>Server / Website Review</li><li>Vulnerability Scans</li><li>Traffic Analysis</li><li>Network Topology</li><li>Analysis of Firewall</li></ul>";
hovertexts.cell5 = "<ul><li>Lost Inheritances</li><li>Insurance Refunds</li><li>Tax Returns</li><li>Lost Mail</li><li>Business Name Change</li></ul>";
hovertexts.cell6 = "<ul><li>Facility Security 24/7</li><li>Janitorial / Custodial</li></ul>";
hovertexts.cell7 = "<ul><li>Project Controls</li><li>Scheduling</li><li>Budget Analysis</li><li>Supply Chain Management</li><li>Quality Assurance</li></ul>";
hovertexts.cell8 = "<ul><li>Process Serving</li><li>Filing / Delivery</li><li>Investigations</li></ul>";
hovertexts.cell9 = "Proud Affiliates";
hovertexts.cell10 = "Instructors Needed For:<ul><li>Crisis Response</li><li>VIP Protection</li><li>Instructor Development</li><li>Advanced Counter-terrorism</li><li>Preventing Attacks on Soft Targets</li></ul>";
hovertexts.cell11 = "<ul><li>Threat Assessment</li><li>First Responder</li><li>Weapons &amp; Self-Defense</li><li>Security Tech Systems</li><li>VIP Escort Protection</li><li>And More...</li></ul>";
hovertexts.cell12 = "<ul><li>Honorable Warriors Fellowship Network</li><li>Formerly Known as Black And Gray Angels</li><li>Fallen Warriors Virtual Memorial Wall</li></ul>";
hovertexts.cell13 = "<ul><li>Certifications</li><li>Licenses</li><li>History</li><li>Growth</li></ul>";
hovertexts.cell14 = "Mission &amp; Values";
hovertexts.cell15 = "NAICS Codes";
hovertexts.cell16 = "Contact Us";



function show_patch( event )
{
	var tgtid = event.currentTarget.id;
	var tgt = $( '#' + tgtid );
	var td_width = tgt.width();
	var td_height = tgt.height();
	var xscale = td_width / patch_width;
	var yscale = td_height / patch_height;
	var scalefactor = 1;
	
	if( xscale > yscale )
	{
		scalefactor = yscale;
	}
	else
	{
		scalefactor = xscale;
	}
	
	var new_width = patch_width * scalefactor;
	var new_height = patch_height * scalefactor;
	var x_offset = (td_width - new_width) / 2;
	var y_offset = (td_height - new_height) / 2;
	
	
	$(".patch", tgt).width( new_width );
	$(".patch", tgt).height( new_height );
	$(".patch", tgt).css( 'top', y_offset + 'px' );
	$(".patch", tgt).css( 'left', x_offset + 'px' );

	$('a', tgt).css( 'font-size', hoversizes[tgtid] );
	$('a', tgt).html( hovertexts[tgtid] );
	
	var txt_height = $('span', tgt).height();
	var txt_offset = ( td_height - txt_height ) / 2;
	$('span', tgt).css('top', txt_offset + 'px' );
	
	$('#side_image').attr( 'src', 'images/' + tgtid + '.png' );
}

function hide_patch( event )
{
	var tgtid = event.currentTarget.id;
	var tgt = $('#' + event.currentTarget.id );
	
	$(".patch", tgt).width( 0 );
	$(".patch", tgt).height( 0 );
	
	$('a', tgt).css( 'font-size', '1.3em' );
	$('a', tgt).html( normaltexts[tgtid] );
	
	var txt_height = $('span', tgt).height();
	var txt_offset = ( tgt.height() - txt_height ) / 2;
	$('span', tgt).css('top', txt_offset + 'px' );
	
	$('#side_image').attr( 'src', 'images/side_image_1.jpg' );
}

function fix_text()
{
	for( i = 1; i <= 16; i++ )
	{
		targ_div = $('#cell' + i );
		targ_txt = $('span', targ_div);
		
		txt_height = targ_txt.height();
		div_height = targ_div.height();
		txt_offset = ( div_height - txt_height ) / 2;
		targ_txt.css('top', txt_offset + 'px' );
	}
}

function preload_images() 
{
	var d=document; 
	if(d.images)
	{ 
		// Declare storage array only if it does not already exist...
		if(!d.MM_p) d.MM_p=new Array();
		
    	var i;
    	var j = d.MM_p.length;
    	var srcname = "";
    	
    	for(i = 0; i <= 16; i++)
    	{
	    	srcname = "images/cell" + i + ".png";
    		d.MM_p[j] = new Image; 
			d.MM_p[j++].src = srcname;
		}
    }
}


$(document).ready( function()
{
	$('#main_content').fadeTo(0, .85);
	
	$('#nav_table div').bind( 'mouseenter', function( event )
	{
		show_patch( event );
	});
	$('#nav_table div').bind( 'mouseleave', function( event )
	{
		hide_patch( event );
	});
	
	fix_text();
	preload_images();
});
