callback_failure_count = 0;

/***********************************************************************************************************/
function addEvent(obj, evType, fn)
{
	 if (obj.addEventListener)
	 {
		 obj.addEventListener(evType, fn, true);
		 return true;
	 } else if (obj.attachEvent)
	 {
		 var r = obj.attachEvent("on"+evType, fn);
		return r;
	 } else
	 {
		return false;
	 }
}



/***********************************************************************************************************/
function retrieve_and_display_content(hash_value)
{


	//document.title = "Pokémon.com : The Official Pokémon Website";
	if(!document.getElementById)
		alert("Please update your browser to IE 6 or higher\nor to Firefox 1.0 or higher");
		
	movie= document.getElementById("site_container");
	if(movie && movie.actionResponse)
	{
		movie.actionResponse(hash_value);
		callback_failure_count = 0;
	}
	else
	{
		if(callback_failure_count<5)
			setTimeout("retrieve_and_display_content('" + hash_value + "')", 500);
		else
			alert("callback failure: movie.actionResponse(): " + movie.name);

		callback_failure_count++;
	}

	//window.scrollTo(0,0);
}


/***********************************************************************************************************/
function user_wants_new_hash(new_hash)
{

	
	if(document.location.toString().indexOf("#")>-1)
	{
		parts = document.location.toString().split('#');
		current_base = parts[0];
		if(parts[1])
			current_hash = parts[1]
		else
			current_hash = "";
	}else
	{
		current_base = document.location.toString();
		current_hash="";
	}

	if(new_hash==default_hash_for_this_page)
	{
		if(document.location.toString().indexOf("#")<0)
			new_hash="";
	}

			
	if(new_hash=="")
		hash_mark=""
	else
		hash_mark="#"


	
	if(new_hash != current_hash)
	{
		scrollTo(0,0);
		document.location = current_base + hash_mark + new_hash;
		if(document.use_frame_based_content_loader)
		{
			document.getElementById("iframe_tracker").setAttribute('src', '/iframe-tracker.html#hash=' + new_hash);
		}
		
		if(content_loader_timeout)
			clearTimeout(content_loader_timeout);
			
		content_loader_timeout = setTimeout("content_loader.check_for_address_bar_change('" +new_hash + "','" + new_hash +"')", 500);
	}
}

