 $(document).ready(function() {
 		$('div.message').animate({opacity: 1.0}, 3500, function(){ $(this).fadeOut(1000); });
		if ( $("#login").length > 0 ) { $("#login").validationAideEnable(); }
		
		
		// initialize mp3 previews
		window.previewPlayers = new Array();
		 	$("embed").each(function(i) {
				if (navigator.appName.indexOf("Microsoft") != -1) {
						window.previewPlayers[i] = window[$(this).attr("name")];
					} else {
						window.previewPlayers[i] = window.document[$(this).attr("name")];
					}
			 	});
			 	
			 $("object").each(function(i) {
				if (navigator.appName.indexOf("Microsoft") != -1) {
						window.previewPlayers[i] = window[$(this).attr("id")];
					} else {
						window.previewPlayers[i] = window.document[$(this).attr("id")];
					}
			 	});
					  // mp3 preview showing, hiding
					  $('.mp3_show').click(function(){
						$('.mp3_preview').height(0);   
					
							$(this).parent().parent().children().children().height(30);
								if (isDefined(window.player_target)) { window.old_target = window.player_target; }
								
								window.player_target = $(this).attr("id").split('track_')[1];
								
								if (isDefined(window.old_target)) { stopOldPlayback(window.old_target); }
								if (isDefined(window.player_target)) { playAnMp3Preview(window.player_target); }
					   });
					   
						   $('.mp3_preview_hide').click(function(){
							  $('.mp3_preview').height(0);          	
						   });
						   
						   function close_previews() { $('.mp3_preview').height(0); }
	
						   function playAnMp3Preview(flash_id) {
							
									var target = window.previewPlayers[flash_id];
									//var target = document.getElementById("mp32");
									target.loadMp3();
								}
							
						    function stopOldPlayback(flash_id) {
									var old_target = window.previewPlayers[flash_id];
									old_target.stopMp3();
								}

	 // swap small store thumbnails information
	  $('.release_detail').hide();
		$('#release_0').show();	
	   $('.releases_small').mouseover(function(){
		$('.release_detail').hide();         
		  
		   var re = /([_\-\w]+$)/i;
				var target = $('cover_' + re.exec(this.id)[1]);
				var target = $('#release_'+this.id.split('cover_')[1]);
				
				target.show();
	   });
   
   
  // store image swap 
  // $('.product_images:not(:first)').hide();
		
		$('.product_image').each(function(){
					
					$(this).children(".product_images:not(:first)").hide();
					}
				);
	
	window.pos = 0;
	var image_count = $('.product_images').size();	
	//if (image_count < 2) {  $("#pagination").animate({"top": "-=50px"}, 500, "easeInExpo"); }
    

   // gallery image swap (forward)
   $('.forward').click(function(){
    			
    			if (image_count > window.pos+1) {
    					
						var target = '#image_'+window.pos;
						$(target).slideUp(800, "easeOutExpo");
						window.pos++;
						var target = '#image_'+window.pos;
						$(target).slideDown(700, "easeInExpo");
						
						 $.ajax({
								   type: "POST",
								   url: "library/ajax/update_name.php",
								   data: "pos="+window.pos+"&id="+ window.id,
								   dataType: "html",
								   success: function(msg){
								   		$("#image_name").html(msg);
								   }
								 });
								 
								  $.ajax({
								   type: "POST",
								   url: "library/ajax/update_description.php",
								   data: "pos="+window.pos+"&id="+ window.id,
								   dataType: "html",
								   success: function(msg){
								   		$("#image_description").html(msg);
								   }
								 });
						
				}		
      		return false;
   });
   
   					// gallery image swap (numbered)
  					 $('.thumbnail').click(function(){
  					 $(this).parent().children('.thumbnail').removeClass("selected-pagination");
  					 $(this).addClass("selected-pagination");
  					    
						$(this).parent().parent().parent().children().children("li:visible").slideUp(400, "easeOutCubic");
						$(this).parent().parent().parent().children().children('.image_'+$(this).parent().children('.thumbnail').index(this)).slideDown(400, "easeOutCubic");
	
							return false;
					  });
   
   // gallery image swap (backward)
   $('.back').click(function(){
   				
   				if (window.pos > 0) {
    				    var target = '#image_'+window.pos;
						$(target).slideUp(800, "easeOutExpo");
						window.pos--;
						var target = '#image_'+window.pos;
						$(target).slideDown(700, "easeInExpo");
							 $.ajax({
									   type: "POST",
									   url: "library/ajax/update_name.php",
									   data: "pos="+window.pos+"&id="+ window.id,
									   dataType: "html",
									   success: function(msg){
											$("#image_name").html(msg);
									   }
									 });
									 
									 	  $.ajax({
								   type: "POST",
								   url: "library/ajax/update_description.php",
								   data: "pos="+window.pos+"&id="+ window.id,
								   dataType: "html",
								   success: function(msg){
								   		$("#image_description").html(msg);
								   }
								 });
				}		
			return false;			
   });

	// input default text hide on focus
/*	$('.email').focus(function(){
			
   			var value = $(this).attr("value"); 
   			if (value != "" && value.indexOf("@") < 0) { $(this).attr("value", ""); }
   }); */
	
    
   // billing toggle (paypal, authorize.net)
    $('.gateway_payment').click(function(){
		  $('.payment_details').slideToggle("medium");          	
	   });
   
   	// ajax content
	/* $('.menu li a').click(function(){   
		 //	if (ajax == true) {
					$("span#ajax_content").slideUp(600, "easeOutQuint");  
					target = $(this).attr('class');				
										 $.ajax({
								   type: "POST",
								   url: "pages/"+$(this).attr('class')+".php",
								   data: "ajax=true",
								   dataType: "html",
								   success: function(msg){
									 $("span#ajax_content").html(msg);
									 $("span#ajax_content").slideDown(500, "easeOutQuint");
									
								   }
								 });	
			
					return false;
				//}
		   }); */
		   
	  		  // accordian menu 
			  var id_query = String(window.location);
			  var querystring = id_query.split('&id=');
			  var id = querystring[1];
				  if (id_query.indexOf("&") > -1) { $("#menu_"+id).parent().next("dd").show(); } else { $("dd:first").show(); }
		
				$("dt a.sliding_menu").click(function(){
					$("dd:visible").slideUp("medium");
					$(this).parent().next().slideDown("medium");
					return false;
				}); 
			   
		   });
   
   					// roster load by ajax
   					function artist(id){   

					//$("div#content").hide(300); 
						$.ajax({
								   type: "POST",
								   url: "pages/artist.php",
								   data: "ajax=true&artist="+id,
								   success: function(msg){
									 
									 $("div#content").html(msg);
									 $("div#content").show(200);
									
								   }
								 });
						   return false;
					    }  
		
		function isDefined(variable) { value = variable || 0; return value; }
		

		/*	function check_format() {
					if (document.addtocart.category_id.value != "") { 
						 	document.addtocart.submit(); return true; } 
						 			else { alert('Please select which type you would like.'); return false; } */



				function options_change(category_id,product_id) {
	
							$("span#options_container").hide();  
							
								$.ajax({
								   type: "POST",
								   url: "library/ajax/options_change.php",
								   data: "category_id="+category_id+"&product_id="+product_id,
								   dataType: "html",
								   success: function(msg){
									
									if (msg.indexOf("no results") == -1) { 
									 $("span#options_container").html(msg);
									 $("span#options_container").slideDown(250, "easeOutExpo"); }
										
										
								   }

							});
						}
						
				function removeHTMLTags(string){
 	
 	 			string = string.replace(/&(lt|gt);/g, function (strMatch, p1){
 		 			return (p1 == "lt")? "<" : ">";
 				});
 					return string.replace(/<\/?[^>]+(>|$)/g, "");

}		
		