$(function () {  
    $('div#collections_pagination.pagination a').live("click", function () {  
        $.get(this.href, null, null, 'script');  
        return false;  
    });  
    SetupMoreLikeThis();
    SetupMarkedListControls();
    SetupAltMixes();
});

function SetupMoreLikeThis(){
  $('span.more_like_this a').click(function(e){
  	e.preventDefault();
  	var url = $(this).attr("href") + "?format=js"
  	jQuery.get(url, function(data) {
  		jQuery.modal(data, {
  			containerCss : {width:"600px"},
  			position:[30,"25%"],
  			maxHeight: 100,
  			onShow: function(dialog){
  				SetupCollectionsWindow();
  				$('a#expand_collection_search').live("click", function(e){
  					e.preventDefault();
  					if (confirm("This will reset your current search.  Are you sure you want to continue?")) {
  						$('form#modal_search').submit();
  					};
  				})
  			},
  			onClose: function(){
  			  $.modal.close();
  			  SetupFlashPlayer(); // reset the width of the players on the main page
  			}
  		});
  		SetupFlashPlayer(196); // set smaller width for collections window
  	});
  })
}

function SetupAltMixes(){
  $('a.alt_mixes').live("click", function(e){
    e.preventDefault();
    var url = $(this).attr("href") + "?format=js"
  	jQuery.get(url, function(data) {
  		jQuery.modal(data, {
  			containerCss : {width:"600px"},
  			position:[30,"25%"],
  			maxHeight: 100,
  			onShow: function(dialog){
  				SetupAltMixesWindow();
 			},
  			onClose: function(){
  			  $.modal.close();
  			  SetupFlashPlayer(); // reset the width of the players on the main page
  			}
  		});
  		SetupFlashPlayer(196); // set smaller width for collections window
  	});
  	$('span.comments').jScrollPane({showArrows:true});
  })
}

function SetupMarkedListControls(){
  if (window.marked_list_id > 0) {
  	EditMarkedList(window.marked_list_id);
  	$('#only_search_marked').click(function() {
  		if ($(this).is(':checked')) {
  			$('#search_marked_list_id').val(window.marked_list_id)
  		} else {
  			$('#search_marked_list_id').val('')
  		}
  		$('#search').submit();
  	})
  } else {
  	CheckMarkedListNotLoggedIn();
  }
}

function SetupAltMixesWindow(){
  SetupModalTracksWindow(300);
  $('div#simplemodal-container').addClass("related_tracks");
  $('div#simplemodal-container').addClass("alt_mixes");
}

function SetupModalTracksWindow(max_height){
  var window_height = $(window).height() - 200
  if (max_height > 0 & window_height > max_height) {
    window_height = max_height;
  }
	$('ul#related_tracks').css("height",window_height);
	SetupFlashPlayer(196);
}

function SetupCollectionsWindow() {
  SetupModalTracksWindow();
  $('div#simplemodal-container').addClass("related_tracks");
	$('div#collections_header a.info').tooltip({
    delay: 0,
    showURL: false,
    opacity: 1,
    extraClass: "infobox",
    showBody: " - ",
    left: -120
  })
}


function SetSortOption() {
  $('div.search_select input').change(function(e){
    self.location = '/tracks?sort_order=' + $(this).val()
  })
}



