$j = jQuery.noConflict();
$j(document).ready(function(){
	$j("#accordion").accordion({ autoHeight: false, collapsible: true, active: false });
	$j("#accordion2").accordion({ autoHeight: false, collapsible: true, active: false });
	$j(".wrapper").accordion({ autoHeight: false, collapsible: true });

	$j(".radio").accordion({ autoHeight: false, collapsible: true, active: false });

	$j("#player_div").jmp3();
	$j(".mbd_label_div").jmp3({filepath: '/tracks/mbd/'});
	$j(".moontribal_label_div").jmp3({filepath: '/tracks/moontribal/'});
	$j(".disoma_label_div").jmp3({filepath: '/tracks/disoma/'});
	
	$j('body').prepend('<div id="tracklist" title="Track list"></div>');
	$j('#tracklist').dialog({
		autoOpen: false,
		maxWidth: 200,
		modal: true,
		position: new Array(150, 200),
		width: 500});
	$j(".radiotable tr:even").find("td:last").bind('click', function() {
			var list = $j(this).parent().next().find('td').html();
			$j('#tracklist').html(list);
			$j('#tracklist').dialog('open');

		}).css('cursor', 'pointer');
	
	$j(".radiotable tr:odd").css('display', 'none');
	
	$j(".player_track a").bind("click", function() {
		$j("#player_track_title").html($j(this).html());
		$j("#player_div").html($j(this).attr('url'));
		$j("#player_div").jmp3();
		return false;
	})
	
	$j("#youtube").append('<img src="/templates/moonbeam/css/images/load.gif" style="width: 55px; height: 55px; margin: 140px auto; display: none;" class="loading" />');
	$j(".box a").bind("click", function() {
		if($j(this).attr('href').indexOf('viewvideo') != -1){
			$j("#youtube object").remove();
			$j('.loading').show();
			$j.post("index.php", 
					{option: 'com_hwdvideoshare',
					   task: 'ajaxgetvideo',
					    req: $j(this).attr('href') },
					function (data) {
					    $j('.loading').hide();
					    $j("#youtube").append(refreshMovie(data))
						//$j("#youtube object param[name='movie']").attr("value", "http://www.youtube.com/v/"+data);
						//$j("#youtube object embed").attr("src", "http://www.youtube.com/v/"+data);
					});
			return false;
		}
	})			
});

function refreshMovie(video_id){
	var html = '';
	html +='<object width="425" height="344">';
	html +='<param name="movie" value="http://www.youtube.com/v/'+video_id+'"></param>';
	html +='<param name="allowFullScreen" value="true"></param>';
	html +='<param name="allowscriptaccess" value="always"></param>';
	html +='<embed src="http://www.youtube.com/v/'+video_id+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed>';
	html +='</object>';
	
	return html;
}

function switchImage(src, origsrc){
	$j('#youtube')
		.html('<a href="' + origsrc + '" rel="lightbox[joomgallery]"><img src="' + src + '" /></a>');
		Slimbox.scanPage();
}