// JavaScript Document

if( FlashDetect.installed )
{
	var projectsPage = location.href.split('projects.php')[1];
	
	if( projectsPage != undefined )
	{
		window.location.href = 'index.php';
		console.log( 'change "window.location.href" when going live' );
	}
}
else
{
	var query = location.href.split('?id=')[1];
	var deepLink = location.href.split('#')[1];
	var projectsPage = location.href.split('projects.php')[1];
	
	if( deepLink != undefined   &&   projectsPage == undefined )
	{
		deepLink = fixQuery( deepLink );
		window.location.href = 'projects.php?id=' + deepLink;
	}
	else if( query != undefined   &&   projectsPage == undefined )
	{
		query = fixQuery( query );
		window.location.href = 'projects.php?id=' + query;
	}
	else
	{
		//just displays index HTML page
	}
}


function fixQuery( query ) //this should mirror php/class.htmlgenerator.php -> fixQuery( query );
{
	if( query.indexOf( '/profile/' ) === 0 )
	{
		query = query.split( '/profile/' ).join( 'profile-' );
	}
	else if( query.indexOf( '/portfolio/' ) === 0 )
	{
		query = query.split( '/portfolio/' ).join( 'portfolio-' );
	}
	else if( query.indexOf( '/testimonials/' ) === 0 )
	{
		query = query.split( '/testimonials/' ).join( 'testimonials-' );
	}
	else if( query.indexOf( '/press/' ) === 0 )
	{
		query = query.split( '/press/' ).join( 'press-' );
	}
	else if( query.indexOf( '/the-showroom/' ) === 0 )
	{
		query = query.split( '/the-showroom/' ).join( 'the-showroom-' );
	}
	
	query = query.split( '/' ).join( '-' );
	
	if( query.indexOf('-') == 0 ) return '';
	
	return query;
}
