
var State='';

function SetState( s )
{
	State=s;
}

function set_page ()
{
	try 
	{
		var map = $('the_map_id');
		
		if ( map )
		{
			var flashvars = { 
				ShowState:State
			};
			
			var params = {
			  menu: "false",
			  wmode: "transparent",
			  loop: "false",
			  scale: "exactfit"
			};
			
			var attributes = { };
			
			swfobject.embedSWF("pageimages/flash/cUSA.swf", "real_map_id", "640", "450", "9.0.0", null , flashvars, params, attributes );
		}
	}
	catch(e) { alert(e); }
	
	try
	{
		var SBobj=$('sidebar');
		if ( SBobj )
		{
			var size = 0;
			
			var obj = $('top');
			if ( obj ) size += obj.offsetHeight;
			
			obj = $('middle');
			if ( obj ) size += obj.offsetHeight; 
			
			obj = $('bottom');
			if ( obj ) size += obj.offsetHeight;
			
			SBobj.style.height = (document.viewport.getHeight() - size) + "px";
		}
	}
	catch( e )
	{
		alert(e);
	}
	
}

Event.observe(window, 'load', set_page);
Event.observe(window, 'resize', set_page);

function LoadHTML( alink , name , width )
{
	if ( alink )
	{
		$('header_text').innerHTML='<h1>Select from Service Areas in ' + name + '</h1>';
		$('list_header').innerHTML='<p><strong>Select from the locations below for more information.</strong></p>';
		// $('html_region').style.marginLeft='-' + (500 - width) + 'px';
		$('the_map_id').style.width = ((width/1)+240) + 'px';
		new Ajax.Updater('html_region', alink, { } );
	}
	else
	{
		$('html_region').style.marginLeft='0px';
		$('html_region').innerHTML='';
		$('list_header').innerHTML='';
		$('header_text').innerHTML='<h1>Click on a RED state below to find locations in your area</h1>';
	}
}

function BackToMap()
{
	args = location.href.toQueryParams();
	location.href='index.php?p=' + args.p;
}

function ClickState( state_name )
{
	args = location.href.toQueryParams();
	location.href='index.php?p=' + args.p + '&state=' + state_name;
}

// Menu Code

function set_menu(a,style)
{
	var div= $('m_'+a);
	var PC = $('l_'+a);
	
	if ( style )
	{
		PC = $(PC.parentNode);
		div.style.visibility='visible';
		div.clonePosition(PC,{ offsetTop: 0, offsetLeft: -5+PC.getWidth(), setHeight: false, setWidth: false });
	}
	else
	{
		if ( !div.realHeight )
			div.realHeight = div.getHeight();
		div.style.height = div.realHeight + 'px';
		
		div.clonePosition(PC,{ offsetTop: 22, offsetLeft: -5, setHeight: false, setWidth: false });
		EffectReg[ a ] = Effect.SlideDown( div, { duration: .3 } );
		setTimeout(function(){div.style.visibility='visible';},50);
	}
}

var ShowThese = new Array();
var ShowAll = null;
var HideAll = null;
function show_menu( id )
{
	clearTimeout(HideAll);
	clearTimeout(ShowAll);
	
	ShowAll=setTimeout( function() {
		
		//console.log('post');
		ShowThese.each(function(i){
			if($('m_'+i))
				$('m_'+i).show();
		} );
		
		$$('.obj_menu').each( function(i) {
			var myID = 1*(''+i.id).substring(2);
			if ( ShowThese.indexOf( myID ) == -1 )
			{
				if ( EffectReg[ myID ] )
				{
					EffectReg[ myID ].cancel();
					EffectReg[ myID ] = 0;
				}
				i.hide();
			}
		} );
		
		ShowThese = new Array();
	}, 50 );
	
	if ( ShowThese.indexOf( 1*id ) == -1 )
	{
		ShowThese = new Array();
		Parentage[id].each( function(i) {
			ShowThese.push(i);
		} );
		// console.log(ShowThese);
	}
}

function hide_menu()
{
	clearTimeout(HideAll);
	clearTimeout(ShowAll);
	
	HideAll=setTimeout(function() {
		$$('.obj_menu').each( function(i) {
			var myID = 1*(''+i.id).substring(2);
			if ( EffectReg[ myID ] )
			{
				EffectReg[ myID ].cancel();
				EffectReg[ myID ] = 0;
			}
			i.hide();
		} );
	}, 50 );
}

