// HIL Template Version 9.1
// ------------------------------------------------------------------------------------------
// Omniplayer Interaction Initialization values

var oPlayer = $('div#omniplayer')['prevObject'];


// ------------------------------------------------------------------------------------------
// Link to artist detail page

$('.link-artist-detail').live('click', function(e){
	
	// Prevent default anchor behavior
	e.preventDefault(e);
	
	// Build the link
	artistID 	= $(this).attr('href');
	link 		= "http://" + siteDomain + "/" + artistPage + artistID;
	
	// Redirect the user
	window.location = link;
	
});


// ------------------------------------------------------------------------------------------
// Volume controls

$('#omniplayer .oplink-vol-down, #omniplayer .oplink-vol-up').live('click',function(e) {

	// Prevent default anchor behavior for volume buttons. No default behavior is defined for mouseup, mouseover, and mouseleave.
	e.preventDefault();
});

$('#omniplayer .oplink-vol-up').live('mousedown',function(e) {

	// While the mouse is down, keep incrementing the volume.
	$.fn.omniplayer.countUp('start');
});

$('#omniplayer .oplink-vol-up').live('mouseup mouseout mouseleave',function(e) {

	// When the mouse leaves or is released stop incrementing the volume.
	$.fn.omniplayer.countUp();
});

$('#omniplayer .oplink-vol-down').live('mousedown',function(e) {

	// While the mouse is down, keep decreasing the volume.
	$.fn.omniplayer.countDown('start');
});

$('#omniplayer .oplink-vol-down').live('mouseup mouseout mouseleave',function(e) {

	// When the mouse leaves or is released stop decrementing the volume.
	$.fn.omniplayer.countDown();
});


$('a.oplink-vol-trigger').live('click', function(e){
	e.preventDefault();
	$('div.op-volume').slideToggle(500);
});


// ------------------------------------------------------------------------------------------
// Flyout Toggles

// ------------------------------------------
// Toggle the Artist flyout

$('a.artist-omni-trigger, a.follow-artist').live('click',function(){
	$('#artist-info-container').slideToggle(500);

	// Turn off the history flyout
	if ( $('#op-history-container').is(':visible') ) {
		$('#op-history-container').slideToggle(500);
	}

	// Turn off the channel flyout
	if ( $('#op-channel-container').is(':visible') ) {
		$('#op-channel-container').slideToggle(500);
	}
	return false;
});

// ------------------------------------------
// Toggle the History flyout

$('.op-history-trigger').live('click',function(){
	$('#op-history-container').slideToggle(500);

	// Turn off the artist flyout
	if ( $('#artist-info-container').is(':visible') ) {
		$('#artist-info-container').slideToggle(500);
	}

	// Turn off the channel flyout
	if ( $('#op-channel-container').is(':visible') ) {
		$('#op-channel-container').slideToggle(500);
	}
	return false;
});

// ------------------------------------------
// Toggle the Channel flyout

$('.op-channel-trigger').live('click',function(){
	$('#op-channel-container').slideToggle(500);

	// Turn off the artist flyout
	if ( $('#artist-info-container').is(':visible') ) {
		$('#artist-info-container').slideToggle(500);
	}

	// Turn off the history flyout
	if ( $('#op-history-container').is(':visible') ) {
		$('#op-history-container').slideToggle(500);
	}
	return false;
});

// ------------------------------------------
// Turn off flyouts if an Artist's Show title is clicked

$('.next-show-title a').live('click',function(){
	$('#artist-info-container').slideToggle(500);

	// Turn off the history flyout
	if ( $('#op-history-container').is(':visible') ) {
		$('#op-history-container').slideToggle(500);
	}

	// Turn off the channel flyout
	if ( $('#op-channel-container').is(':visible') ) {
		$('#op-channel-container').slideToggle(500);
	}

});


// ------------------------------------------------------------------------------------------
// Omniplayer playlist buttons

// ------------------------------------------
// Default Playlist
$('.playlist-default').live('click',function(e){
	e.preventDefault();
	$.fn.omniplayer.getPlaylist('playlist','','',$('div#omniplayer'));
});

// ------------------------------------------
// Upcoming Shows
$('.playlist-upcoming').live('click',function(e){
	e.preventDefault();
	$.fn.omniplayer.getPlaylist('upcoming','true','Music from Upcoming Shows',$('div#omniplayer'));
});

// ------------------------------------------
// Individual Artist
$('.playlist-artist').live('click',function(e){
	e.preventDefault();
	var val = $(this).attr('href');
	val = (val=='' || val=='#' || typeof val=='undefined' || val==null) ? $(this).find('span').attr('class') : val;
	plName = $(this).attr('rel');
	$.fn.omniplayer.getPlaylist('artist',val,plName,$('div#omniplayer'));
});

// ------------------------------------------
// Individual Performance
$('.playlist-performance').live('click',function(e){
	e.preventDefault();
	var val = $(this).attr('href');
	val = (val=='' || val=='#' || typeof val=='undefined' || val==null) ? $(this).find('span').attr('class') : val;
	plName = $(this).attr('rel');
	$.fn.omniplayer.getPlaylist('performance',val,plName,$('div#omniplayer'));
});

// ------------------------------------------
// Favorite songs or songs from favorite artists
$('.playlist-favorites').live('click',function(e){
	e.preventDefault();
	var val = $(this).attr('href');
	val = (val=='' || val=='#' || typeof val=='undefined' || val==null) ? $(this).find('span').attr('class') : val;
	plName = $(this).attr('rel');
	$.fn.omniplayer.getPlaylist('favorites',val,plName,$('div#omniplayer'));
});

// ------------------------------------------
// Genre
$('.playlist-genre').live('click',function(e){
	e.preventDefault();
	var val = $(this).attr('href');
	val = (val=='' || val=='#' || typeof val=='undefined' || val==null) ? $(this).find('span').attr('class') : val;
	$.fn.omniplayer.getPlaylist('genre',val,'',$('div#omniplayer'));
});


// ------------------------------------------------------------------------------------------
// Random stuff

// ------------------------------------------
// Move to the end of the song - For testing only

$('#omniplayer .oplink-end').live('click',function(e) {
	e.preventDefault();	
	playlist = $('#omniplayer')[0]['playlist'];
	position = $('#omniplayer')[0]['position'];
	song = $('#omniplayer')[0]['song'];
	song.setPosition(song.duration-2000);
});


// ------------------------------------------
// Play a song???

function omniPlaylist() {
	if ( $('#omniplayer .oplink-play').is(':visible') ) {
		$('#omniplayer .oplink-pause').fadeIn();
		$('#omniplayer .oplink-play').hide();
	}
}
