var tracklist_ids  = [];
var playlist_ids   = [];
var rating_dom_ids = {};

var page_actions = {
  'albums_outOfPrintAlbums': function()
  {
  },
  'albums_product': function()
  {
	  if($(".recording p").length > 3)
	  {
		r = $(".recording");
		r.hide();
		more = $('<div class="button"><a href="#" id="more_toggle">More Info</a></div><div class="clear"></div>');
		r.after(more);
		t = $("#more_toggle");
		t.click(function(e) {
			e.preventDefault();
			r.slideToggle(400, function() {
					t.html(t.html() == "More Info" ? "Less Info" : "More Info");
				}
			);
		});
	  }
  },
  'dgdseSymphonyExplorer_exploreVariation': function()
  {
	var animSpeed = 400;
	$('.tracks.multiple').hide();
	$('.dgdShop_BuyButtons_Track a').click(function(e) {
		e.preventDefault();
	});
	$('.play.symphonyvariation').click(function(e) {
		e.preventDefault();
		$('.tracks.multiple').slideUp(animSpeed);
	});
	
	$('.movement').each(function() {
		var movement = $(this);
		movement.find('.play.symphonyvariationmovement, .button.buy>a').click(function(e) {
			e.preventDefault();
			var tracks = movement.next('.tracks.multiple');
			$('.tracks.multiple').not(tracks).slideUp(animSpeed);
			tracks.filter(':hidden').slideDown(animSpeed);
		});
		
	});
	
	
	$('.make_favorite_symphony_variation').click(function(e) {
		e.preventDefault();
		var self = $(this);
		var parent = self.parent();
		
		if(!self.hasClass('busy')) {
			parent.fadeTo(200, .5);
			$.ajax({
				url:this.href
				, data:{_ajax:1}
				, success:function(data, textStatus, XMLHttpRequest) {
					parent.fadeOut(400, function() { parent.prev().fadeIn(400); });
				}
				, error:function(XMLHttpRequest, textStatus, data) {
					parent.fadeTo(200, 1);
					self.removeClass('busy');
					login_actions.errorCallback(XMLHttpRequest, textStatus, data);
				}
			});
		}
		self.addClass('busy');
	});
	
  },
  'user_register': function()
  {
	  $('.privacy_policy').click(function(event) {
		  event.preventDefault();
		  $.get($(this).attr("href"), function(data){
			  $.blockUI({ message: data });
			  $("#privacypolicy_wrap").append($("Hello"));
			  $(".blockOverlay, #close").attr('title', 'Click to close.').click(function(event) {
				  event.preventDefault();
				  $.unblockUI();
			  });
		  });
	  });
  },
  'home_index': function()
  {
    $(".textteaser").cycle({
        fx: 'fade'
      , timeout: 5000
      , cleartypeNoBg: true
    });
  },
  'mymahler_peoplesMahler': function()
  {
	  $('.next4').hide();
	  $('.exploreTop5').click(function(event) {
	  	event.preventDefault();
	  	$(this).parent().next().closest("ul").slideToggle();
	  	$(this).closest("li").toggleClass("active");
	  });
  }
};

var login_actions = {
		submit: function(formNode)
		{
			var form = $(formNode);
			$.ajax({
				url: form.attr("action"),
				data: form.serialize(),
				type: 'POST',
				error: function(XMLHttpRequest, textStatus) { $('.blockMsg').html(XMLHttpRequest.responseText); },
				success: login_actions.signInCallback
			});
		},
		
		errorCallback: function(XMLHttpRequest, textStatus)
		{
			$.blockUI({ message: XMLHttpRequest.responseText });
			$('.blockOverlay').attr('title', 'Click to unblock').click($.unblockUI); 
		},
		
		signInCallback: function(data, textStatus, XMLHttpRequest)
		{
			if (data) {
				$('#content').html(data);
			}
			
			$.get(lang_prefix + '/menu/user', function(data, textStatus, XMLHttpRequest) {
				$('#user_menu').html(data);
			});
			
			$.unblockUI();
		}
};



$(document).ready(function(){
	// things to hide on dom ready	
	$('ul.sf-menu').each(function() {
		var menu = $(this);
		if(menu.parents('.movement, .tracks.multiple').length<1) {
			menu.superfish(
				{
					dropShadows:   false    
				}	
			);
		}
	});
	
	body_id = document.body.id;
	if(page_actions[body_id])
	{
		page_actions[body_id]();
	}
	
	
	// bind: Drop Down Navigation Behaviour
	// for all <SELECT> with class "change_location"
	$('select.change_location').change(function(){
		window.location.href = $(this).val();
	});
	
	$('#mdm_status ul li').mouseover(function(e) {
		$(this).addClass('mouseover');
	});
	$('#mdm_status ul li').mouseout(function(e) {
		$(this).removeClass('mouseover');
	});
	
	$('.tooltip').tooltip({
		  top: 28
		, left: -14
		, fade: "fast"
		, track: true
		, showURL: false
		, bodyHandler: function() {
			
			var text = "";
			var t = $(this).context.tooltipText;
			var parts = t.split('|');
			if(parts.length > 1) {
				$.each(parts, function(key, value) {
					if($.trim(value))
					{
						text += (!key ? ['<h1>', value, '</h1>'] : ['<p class="line', key, '">', value, '</p>']).join('');
					}
				});
				
			} else {
				text = t;
			}
			
			return '<div class="header"><div class="corner">&#160;</div><div class="clear"></div></div><div class="content alternative_b">'+text+'</div><div class="footer"><div class="corner">&#160;</div><div class="clear"></div></div><div class="arrow">&#160;</div>';
		}
	});
	// remove alt tags in tooltip childrens images (ie)
	$('.tooltip img').removeAttr('alt');
	/*
	$.cookie('hD?7@87#', 'available');
	if($.cookie('hD?7@87#') != 'available') {
		$.ajax({
			url:lang_prefix+'/main/staticEnableCookies'
			, type:'get'
			, success:function(data, textStatus, XMLHttpRequest) {
				$.blockUI({ message:XMLHttpRequest.responseText });
				$('.blockOverlay').click($.unblockUI);
			}
		});
	}
	*/
});


