if (Drupal.jsEnabled) {
	$(document).ready(
		function () {
			$('.scroll-pane').jScrollPane({scrollbarWidth:4, scrollbarMargin:2});
			//alert('audioPlayerInit()');
	    audioPlayerInit();
			// pop up additional information on input filters
			$('a[href$=filter/tips]').attr('target','_blank');
			//  ML wants stick forum threads bolded
			$('tr:has(img[src$=misc/forum-sticky.png]) td').attr('style','font-weight: bold');
	
		}
	);

	/*
	// handles submit-form on Enter key - (2008-08-16)
	$(function(){
	    $('input').keydown(function(e){
		if (e.keyCode == 13) {
		    $(this).parents('form').submit();
		    return false;
		}
	    });
	});
	*/


	// handle the sliders
	function handle_slider(el)
	{
	    var bar         = el;
	    var handle      = el.down();
	    var slided      = el.previous();

	    var max_scroll  = slided.scrollHeight - slided.offsetHeight;

	    var slider      = new Control.Slider(handle, bar, {
		axis: 'vertical',
		range: $R(0, max_scroll),
		onChange: function(v){ slided.scrollTop = v; },
		onSlide: function(v){ slided.scrollTop = v; }
	    });
	}

	// handle the menu
	function handle_menu(el)
	{
	    var anchors = el.getElementsByTagName('a');
	    var block   = el.next();

	    // loop through links and handle clicks
	    $A(anchors).each(function(link){
		// observe click
		$(link).observe('click', function(e){
		    // update tabs
		    $A(anchors).each(function(a){ $(a.parentNode).removeClassName('current') });
		    $(this.parentNode).addClassName('current');

		    // update block with loading text and spinner graphic
		    block.update('Loading...');
		    block.addClassName('loading');

		    // call ajax and replace block content
		    new Ajax.Updater(block, this.href);
		    block.removeClassName('loading');

		    // stop the default event
		    this.blur();
		    e.stop();
		});
	    });
	}

	// highlight input text on click
	function highlight_embed()
	{
	    if(window.getSelection) {
		this.setSelectionRange(0, this.value.length);
		this.select();
	    } else {
		var range = this.createTextRange();
		range.moveStart('character', 0);
		range.moveEnd('character', this.value.length);
		range.select();
	    }
	}
}

/*
// fire on dom ready
document.observe("dom:loaded", function(){    
    $('embed-code').observe('focus', highlight_embed);
    //$$('ul.block-menu').each(function(el){ handle_menu(el) });
    $$('div.scroll').each(function(el){ handle_slider(el) });
});
*/



var flashAudioPlayer;
var windowHandle;

/* When the HTML page loads (via the onLoad event of the <body> tag) we have it call the initialize() function. */
function audioPlayerInit() {
	/* Check if the browser is IE. If so, flashAudioPlayer is window.audioPlayer. Otherwise, it's window.document.audioPlayer. The audioPlayer is the id assigned to <object> and <embed> tags. */

	var ie = navigator.appName.indexOf("Microsoft") != -1;
	flashAudioPlayer = (ie) ? window['audioPlayer'] : document['audioPlayer'];

}

var ppCount = 0;
var bob = 'bob parent';
function playerPing(popPlayer) {
	ppCount ++;
	//flashAudioPlayer = windowHandle.flashAudioPlayer;
	flashAudioPlayer = popPlayer;
	//alert("popPlayer="+popPlayer+",bob="+bob);
	return 'cool';
}

function playAddTrack(nid) {

	flashAudioPlayer.playAddTrack(nid);
}

function popMadeloudPlayer(playlist_uri) {
	var e = playlist_uri.split("/");
	var url = 'http://www.madeloud.com/mlplayer/pop';
	if(e[2] == 'user') {
		url += '/'+e[2]+'/'+e[3];
	}
	//alert(playlist_uri+', '+url);
	windowHandle = window.open(url,'madeloudplayer','width=282,height=231,location=no,status=no');
}

function setPopAsPlayer() {
	flashAudioPlayer = windowHandle.flashAudioPlayer;
}
