/**
 * Actionscript pushes the value to javascript 
 */
if (typeof console != 'object') {
	console = function() {	}
	console.log = new Function('return true')
}
function asjs_update_hash(received_hash)
{
	location.hash = received_hash;
	console.log('%' + received_hash + '%');
}

/**
 * Actionscript requesting decoded hash
 */
function asjs_get_decoded_hash()
{
	hash = location.hash.substring(1).toLowerCase(); // removes hash sign in front
	return hash;
}



//functions from example
function getFlashMovie(movieName) 
{   
	var isIE = navigator.appName.indexOf("Microsoft") != -1;   
	return (isIE) ? window[movieName] : document[movieName];  
}  

function formSend()
{   
	// checks to see if the function inside the flash file is defined
	if (typeof getFlashMovie("skilltree_builder").sendTextToFlash == 'function') {
		hash = asjs_get_decoded_hash();
		console.log('received hash from url: ' + hash);
		getFlashMovie("skilltree_builder").sendTextToFlash(hash);  
		console.log('formSend() called');
	} else {
		console.log('not ready');
	}
}    

function getTextFromFlash(string_from_flash)  // flash calls this
{   
	// ignore the first message from flash file
	if (ready == true)
	{
		string_from_flash = jQuery.trim(string_from_flash);
		console.log("getTextFromFlash() called with this value: " + string_from_flash);   
		asjs_update_hash(string_from_flash);
	}
	else
	{
		ready = true;
		console.log("ignoring first msg from flash: " + string_from_flash);
	}
	return str + " received";  
}

function work(string_from_flash) {
	console.log('work(): ' + string_from_flash);
}

var ready = false;
var spam_interval;
function start_spam() {
	spam_interval = setInterval('formSend()', 100);
	console.log('--- starting spam');
}
function stop_spam() {
	clearInterval(spam_interval);
	console.log('--- stopping spam');
}


$(document).ready(function() {
	console.log(asjs_get_decoded_hash());

	start_spam();
});