function addScript(data) {
    if (data == "") {
        return true;
    }
    var script = document.createElement("script");
    script.src = data;
    document.getElementsByTagName('head')[0].appendChild(script);
    //document.lastChild.firstChild.appendChild(script);
}

function addStyle(data){
	if (data == "") {
        return true;
    }
    
    var style = document.createElement("link");
    style.rel = 'stylesheet';
    style.type = 'text/css';
    style.href = data;
    document.getElementsByTagName('head')[0].appendChild(style);
    //document.lastChild.firstChild.appendChild(style);
}

if(typeof $ == 'undefined'){
	addScript('http://admin.resonate.org.nz/theme/js/jquery-1.4.2.min.js');
}
if(typeof(flowplayer) != 'function'){
	addScript('http://admin.resonate.org.nz/player/flowplayer/flowplayer-3.2.2.min.js');
}

var persist = setTimeout('keepAlive()',480000);

function keepAlive(){

	script = document.createElement('script');

    script.src = 'http://admin.resonate.org.nz/keepalive.php?rand='+Math.random();

    document.getElementsByTagName('head')[0].appendChild(script);

	persist = setTimeout('keepAlive()',480000);

}

function dump(arr, level) {
    var dumped_text = "";
    if (!level) level = 0;

    // The padding given at the beginning of the line.
    var level_padding = "";
    for (var j = 0; j < level + 1; j++)
    level_padding += "    ";

    if (typeof(arr) == 'object') { //Array/Hashes/Objects 
        for (var item in arr) {
            var value = arr[item];

            if (typeof(value) == 'object') { //If it is an array,
                dumped_text += level_padding + "'" + item + "' ...\n";
                dumped_text += dump(value, level + 1);
            } else {
                dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
            }
        }
    } else { //Stings/Chars/Numbers etc.
        dumped_text = "===>" + arr + "<===(" + typeof(arr) + ")";
    }
    return dumped_text;
}






function dosomething(area) {
	var selected = area.val();
	var attr = area.attr('name').replace('authorraw','');
	$('#author'+attr).val(selected);
	
	var iconid = area.find('option[value='+selected+']').attr('rel');
	if(iconid=='' || typeof(iconid)=='undefined')iconid=1;
	
	var html = '';
	if($('.current_icon'+attr).length<1)attr='';
	var rel = $('.current_icon'+attr).attr('rel');
	if(typeof(rel)=='undefined')rel='';
	html += '<ul id="selectable"><li class=\"ui-state-default\"><img src=\"/images/icon.php?i='+iconid+'\"><img src=\"/theme/images/delete_1.png\" class=\"delete_icon\" onclick=\"Icons.remove_icon(\''+iconid+'\',0,'+rel+');\"></li></ul>';
	$('.current_icon'+attr).html(html);
	if($('.icon_from'+rel).length>0)$('.icon_from'+rel).html('[ speaker ]');
	else $('.icon_from').html('[ speaker ]');
	//document.getElementById('author'+attr).value = selected;
}

