fps = 30;
load_time = 1;

current_background=1;
background_interval = 0;
current = 0;

function init()
{
	load_all_sections('layout');
	
	current_template = window.location.href.toString().split('/')[window.location.href.toString().split('/').length-1].split('#')[0].split('.')[0].toUpperCase();
	
	default_page = window.location.href.toString().split('#')[1];
	
	if(default_page != undefined && default_page.indexOf('-') != -1)
	{
		default_page = default_page.split('-')[0]
	}
	
	if(default_page != undefined)
	{
		setTimeout(default_page.toUpperCase()+'(\'init\')',load_time*2500);
	}
	else if(current_template != '' && current_template != 'INDEX')
	{
		setTimeout(current_template+'(\'init\')',load_time*2500);
	}
	else
	{
		setTimeout('HOME(\'init\')',load_time*2500);
	}
}

function move_arrow(destination)
{
	navigation_arrow_section.direction='right';
	move_to = Number(ID('navigation_arrow').style.left.toString().split('px')[0]);
		
	if(move_to > destination)
	{
		navigation_arrow_section.startx=destination;
		navigation_arrow_section.unload_section();
	}
	if(move_to < destination)
	{
		navigation_arrow_section.startx=move_to;
		navigation_arrow_section.x=destination;
		navigation_arrow_section.load_section();
	}
}

/*function fade_background(background)
{
	if(current_background !=0)
	{
		ID('background_'+current_background).style.opacity = 100-current;
		ID('background_'+current_background).style.MozOpacity = (100-current)/100;
		ID('background_'+current_background).style.KhtmlOpacity = (100-current)/100;
		ID('background_'+current_background).style.filter = "alpha(opacity=" + 100-current + ")"; 
		//object.visibility = 'visible';
	}
	
	if(current<100)
	{
		ID('background_'+background).style.opacity = current;
		ID('background_'+background).style.MozOpacity = current/100;
		ID('background_'+background).style.KhtmlOpacity = current/100;
		ID('background_'+background).style.filter = "alpha(opacity=" +current + ")";
		current+=1;
	}
	else
	{
		ID('background_'+background).style.opacity = 100;
		ID('background_'+background).style.MozOpacity = 1;
		ID('background_'+background).style.KhtmlOpacity = 1;
		ID('background_'+background).style.filter = "alpha(opacity=" + ID('background_'+background).style.opacity + ")";
		current=0;
		current_background=background;
		clearInterval(background_interval);
	}
}
*/
function HOME(init)
{
	if(ready || init != undefined)
	{
		load_all_sections('home');
		unload_all_sections('about_remedy');
		unload_service();
		unload_all_sections('services');		
		unload_all_sections('service_content');
		
		if(window.location.href.toString().split('#')[1] == 'case_studies')
		{
			cs_reset();
		}		
		
		
		unload_all_sections('default_case_studies');
		unload_all_sections('case_studies_nav');
		unload_all_sections('case_studies_content');
		unload_news();
		unload_all_sections('business_units');
		unload_all_sections('business_unit_content');
		unload_all_sections('contact_us');
		unload_all_sections('contact_us_form');
		unload_all_sections('contact_us_confirmation');
		move_arrow(557);
		document.title = 'Remedy Media Group: Cure for the Common';
		window.location.href='#home';
	}
}

function ABOUT_REMEDY(init)
{
	if(ready || init != undefined)
	{
		unload_all_sections('home');
		load_all_sections('about_remedy');
		unload_service();
		unload_all_sections('services');
		unload_all_sections('service_content');
		
		if(window.location.href.toString().split('#')[1] == 'case_studies')
		{
			cs_reset();
		}		
		
		unload_all_sections('default_case_studies');
		unload_all_sections('case_studies_nav');
		unload_all_sections('case_studies_content');
		unload_news();
		unload_all_sections('business_units');
		unload_all_sections('business_unit_content');
		unload_all_sections('contact_us');
		unload_all_sections('contact_us_form');
		unload_all_sections('contact_us_confirmation');
		move_arrow(617);
		document.title = 'Remedy Media Group: About Remedy';
		window.location.href='#about_remedy';
	}
}

function SERVICES(init)
{
	if(ready || init != undefined)
	{
		unload_all_sections('home');
		unload_all_sections('about_remedy');
		
		if(window.location.href.toString().indexOf('#') != -1 && window.location.href.toString().indexOf('-') != -1 && window.location.href.toString().split('#')[1].split('-')[0] == 'services')
		{
			default_service = window.location.href.toString().split('#')[1].split('-')[1];
		}
		else
		{
			default_service = undefined;
		}
		
		if(default_service != undefined)
		{
			quick_load_service(default_service);
		}
		else
		{
			unload_service();
			load_all_sections('services');
			load_all_sections('service_content');
			document.title = 'Remedy Media Group: Services';
			window.location.href='#services';
		}
		
		if(window.location.href.toString().split('#')[1] == 'case_studies')
		{
			cs_reset();
		}		
		
		
		unload_all_sections('default_case_studies');
		unload_all_sections('case_studies_nav');
		unload_all_sections('case_studies_content');
		unload_news();
		unload_all_sections('business_units');
		unload_all_sections('business_unit_content');
		unload_all_sections('contact_us');
		unload_all_sections('contact_us_form');
		unload_all_sections('contact_us_confirmation');
		move_arrow(686);
	}
}

cs_nav_loaded = false;

function CASE_STUDIES(init)
{
	if(ready || init != undefined)
	{
		unload_all_sections('home');
		unload_all_sections('about_remedy');
		unload_service();
		unload_all_sections('services');
		unload_all_sections('service_content');
		unload_news();
		unload_all_sections('business_units');
		unload_all_sections('business_unit_content');
		unload_all_sections('contact_us');
		unload_all_sections('contact_us_form');
		unload_all_sections('contact_us_confirmation');
		
		
		move_arrow(752);
		
		if(window.location.href.toString().indexOf('#') != -1 && window.location.href.toString().indexOf('-') != -1 && window.location.href.toString().split('#')[1].split('-')[0] == 'case_studies')
		{
			default_study = window.location.href.toString().split('#')[1].split('-')[1];
		}
		else
		{
			default_study = undefined;
		}
		
		
		if(default_study != undefined)
		{
			quick_load_case_study(default_study);
		}
		/*else if(current_study != '')
		{
			unload_case_study();
		}*/
		else
		{
			load_all_sections('default_case_studies');
			load_all_sections('case_studies_nav');
			
			cs_nav_loaded = true;
			
			if(current_study != '')
			{
				unload_case_study('force');
			}
			
			document.title = 'Remedy Media Group: Case Studies';
			window.location.href='#case_studies';
		}		
	}
}

function NEWS(init)
{
	if(ready || init != undefined)
	{
		unload_all_sections('home');
		unload_all_sections('about_remedy');
		unload_service();
		unload_all_sections('services');
		unload_all_sections('service_content');
		
		if(window.location.href.toString().split('#')[1] == 'case_studies')
		{
			cs_reset();
		}		
		
		unload_all_sections('default_case_studies');
		unload_all_sections('case_studies_nav');
		unload_all_sections('case_studies_content');
		
		if(window.location.href.toString().indexOf('#') != -1 && window.location.href.toString().indexOf('-') != -1 && window.location.href.toString().split('#')[1].split('-')[0] == 'news')
		{
			default_news = window.location.href.toString().split('#')[1].split('-')[1];
		}
		else
		{
			default_news = undefined;
		}
		
		if(default_news != undefined)
		{
			quick_load_news(default_news);
		}
		else
		{
			load_news();
			document.title = 'Remedy Media Group: News';
			window.location.href='#news';
		}
		
		unload_all_sections('business_units');
		unload_all_sections('business_unit_content');
		unload_all_sections('services');
		unload_all_sections('service_content');
		unload_all_sections('contact_us');
		unload_all_sections('contact_us_form');
		unload_all_sections('contact_us_confirmation');
		move_arrow(811);
	}
}

function BUSINESS_UNITS(init)
{
	if(ready || init != undefined)
	{
		unload_all_sections('home');
		unload_all_sections('about_remedy');
		unload_service();
		unload_all_sections('services');
		unload_all_sections('service_content');
		
		if(window.location.href.toString().split('#')[1] == 'case_studies')
		{
			cs_reset();
		}
		
		
		unload_all_sections('default_case_studies');
		unload_all_sections('case_studies_nav');
		unload_all_sections('case_studies_content');
		
		if(window.location.href.toString().indexOf('#') != -1 && window.location.href.toString().indexOf('-') != -1 && window.location.href.toString().split('#')[1].split('-')[0] == 'business_units')
		{
			default_business_unit = window.location.href.toString().split('#')[1].split('-')[1];
		}
		else
		{
			default_business_unit = undefined;
		}
		
		if(default_business_unit != undefined)
		{
			quick_load_business_unit(default_business_unit);
		}
		else
		{
			bu_reset();				
			unload_all_sections('business_unit_content');
			document.title = 'Remedy Media Group: Business Units';
			window.location.href='#business_units';
		}
		unload_news();
		load_all_sections('business_units');
		unload_all_sections('contact_us');
		unload_all_sections('contact_us_form');
		unload_all_sections('contact_us_confirmation');
		move_arrow(875);		
	}
}

function CONTACT_US(init)
{
	if(ready || init != undefined)
	{
		unload_all_sections('home');
		unload_all_sections('about_remedy');
		unload_service();
		unload_all_sections('services');
		unload_all_sections('service_content');
		
		if(window.location.href.toString().split('#')[1] == 'case_studies')
		{
			cs_reset();
		}
		
		
		unload_all_sections('default_case_studies');
		unload_all_sections('case_studies_nav');
		unload_all_sections('case_studies_content');
		unload_news();
		unload_all_sections('business_units');
		unload_all_sections('business_unit_content');
		load_all_sections('contact_us');
		load_all_sections('contact_us_form');
		unload_all_sections('contact_us_confirmation');
		move_arrow(950);
		document.title = 'Remedy Media Group: Contact Us';
		window.location.href='#contact_us';
	}
}