var current_title;

function update_title(title)
	{
	current_title = title;
	document.title = 'Oasis Post / '+title;
	}

function confirm_title()
	{
	document.title = 'Oasis Post / '+current_title;
	}



//var current_background;

var loaded_background = false;

function load_background(section, extra)
	{
	
		if(loaded_background == false)
		{
		var delay = 2000;
		
		loaded_background = true;
		var fxBg = new Fx.Tween('background-image', {duration:1000});
		fxBg.start('opacity', $('background-image').getStyle('opacity'), '1').chain(function() {

//		var image = 'WebLogo.00014.jpg';
//		document.getElementById('page-body').style.background = "url(system/images/backgrounds/WebLogo.00014.jpg) no-repeat center center";

	    });
		
		
//		setTimeout(function(){load_background_finish()},delay);
		setTimeout(function(){show_interface(section, extra)},(delay + 1000));
		}


	
	}


function load_background_finish()
	{
	
		if(document.getElementById('background') && document.getElementById('background-image'))
		{
		var fxEnd = new Fx.Tween('background', {duration:1000});
		fxEnd.start('opacity', $('background').getStyle('opacity'), 0).chain(function() {
		document.getElementById('background-image').innerHTML = '';
		document.getElementById('background').style.display = 'none';
	    });
		
		}
	
	}



function update_url(value)
	{
	var clean_value = clean_up_value(value);
	current_hash = clean_value;
	parent.location.hash = clean_value;
	update_title(value);
	}



function clean_up_value(value)
	{
	value = str_replace(' - ', '-', value);	
	value = str_replace('/', '-', value);	
	value = str_replace(' ', '-', value);
	value = str_replace('&', '-', value);
	value = str_replace('.', '', value);
	value = str_replace('\'', '', value);
	value = str_replace('"', '', value);
	value = str_replace('!', '', value);
	
	return strtolower(value);
	}



function get_hash_param_id(param, type)
	{
	var id = false;
	
	
	
		if(type == 'normal')
		{
	
			for ( keyVar in sections ) 
			{
				if(sections[keyVar]['name'])
				{
				var this_id = sections[keyVar]['id'];
				var title = clean_up_value(sections[keyVar]['name']);
				
					if(title == param)
					{
					id = this_id;
					}
				
				}
				
			}
	
		} else if(type == 'work') {

			for ( keyVar in work ) 
			{
				if(work[keyVar]['title'])
				{
				var this_id = work[keyVar]['id'];
				var title = clean_up_value(stripslashes(work[keyVar]['title']));
				
					if(title == param)
					{
					id = this_id;
					}
				
				}
				
			}

		} else if(type == 'person') {

		
			for ( keyVar in users ) 
			{
				if(users[keyVar]['username'])
				{
				var this_id = users[keyVar]['id'];
				var title = clean_up_value(users[keyVar]['username']);
				
					if(title == param)
					{
					id = this_id;
					}
				
				}
				
			}
		
		} else if(type == 'news') {

		
			for ( keyVar in news ) 
			{
				if(news[keyVar]['title'])
				{
				var this_id = news[keyVar]['id'];
				var title = clean_up_value(news[keyVar]['title']);
				
					if(title == param)
					{
					id = this_id;
					}
				
				}
				
			}
		
		}
	
	
		if(id)
		{
		return id;
		} else {
		return false;
		}
	
	}



function show_interface(section, extra)
	{
//	alert(section+' '+extra);
	
		if(Browser.Engine.trident)
		{
		update_status('browser', 'IE');
		update_status('browser_version', 'v'+Browser.Engine.version);
		} else {
		update_status('browser', 'Not IE');
		update_status('browser_version', 'v'+Browser.Engine.version);
		}




	$('footer').setStyle('opacity', '1');
	$('footer').setStyle('display', 'block');

	$('wrapper').setStyle('display', 'none');
	$('wrapper').setStyle('opacity', '0');
	
	
	var url_array = explode('#', location.href);
	var hash_param;
	(url_array[1]) ? hash_param=url_array[1] : hash_param=false;
	


		if(hash_param)
		{
		var id;
		
			if(id = get_hash_param_id(hash_param, 'normal'))
			{
			go_to(id);
			}else if(id = get_hash_param_id(hash_param, 'work')) {
			section = section_ids['our work'];
			sections[section]['extra_params'] = sections[section]['extra_params']+'&video_id='+id;
			go_to(section, true);
			}else if(id = get_hash_param_id(hash_param, 'person')) {
			show_person(id, hash_param);
			}else if(id = get_hash_param_id(hash_param, 'news')) {
			sections[section_ids['news']]['extra_params'] = sections[section_ids['news']]['extra_params']+'&featured_id='+id
			go_to(section_ids['news']);
			} else {
			go_to(section);
			}
		
		
		} else {
		
			if(extra !== 'home')
			{
			
				switch(section)
				{
				
					case 'person':
					show_person(extra);
					break;
				  
					case 'category':
					show_category(extra);
					break;
				  
					default:
					
				}
			
			} else {
			go_to(section);
			}

		}
	}


function tester()//temp
	{
		document.getElementById('wrapper').style.visibility = 'visible';//temp
		document.getElementById('wrapper').style.display = 'block';//temp
		document.getElementById('wrapper').style.opacity = '1';//temp
	}


	function dom_ready(section, extra)
	{
		
		if(document.getElementById('background'))
		{

/*
		load_background_finish(); //temp
		document.getElementById('wrapper').style.display = 'none';//temp
		document.getElementById('wrapper').style.opacity = '1';//temp
		show_interface(section, extra); //temp
*/


		$('background-image').setStyle('opacity', '0');
		
		toggle_loading(1);

		document.getElementById('background-image').innerHTML = '<img onload="load_background(\''+section+'\', \''+extra+'\')" src="system/images/backgrounds/WebLogo.OASIS2.jpg" alt="WebLogo.OASIS2" width="1920" height="1200"/>';






/*
		
			if( (Browser.Engine.trident) && (Browser.Engine.version < 5) )
			{
			document.getElementById('background').style.display = 'none';
			document.getElementById('page-body').style.background = "url(system/images/backgrounds/WebLogo.OASIS.jpg) no-repeat center center;";
			document.getElementById('page-body').style.backgroundAttachment = "fixed";
			} else {
			load_background('WebLogo.OASIS.jpg');
			}

		setTimeout(function(){show_interface(section, extra)},1000);
*/
		
		
		} else {
		show_interface(section, extra);
		}

	

	}



