// JavaScript Document
function makemehappy(that){
    that.qtip(
		{
		id: that.attr('id'),
		content:
			{
      ajax:
				{
				method: 'get',
				url: that.attr('rel')
        /*,
				success: function(response, status) {
             // Update content data
             this.set('content.text', response);
						return false;
				} */
			}
		},
		position: {
				at: 'left top',
				my: 'right top',
				type: 'static',
				adjust: {
					scroll: true,
					resize: false
					}
				},
		style: { classes: 'memo-board-tip' },
    show: 'click',
		hide: 'click',
		 events: {
		 show: 	function() {
					$('a[rel]#cart').qtip('hide');
					},
		 focus: function(event, api){
				 $('#minimemo a.tool2').qtip('focus');
			}
		 }
		});
	  that.qtip('show');
		//that.qtip('click');
}
function makemehappy2(that){
      that.qtip(
		{
		id: that.attr('id'),
		content:
			{
			ajax:
				{
				method: 'get',
				url: that.attr('rel')
        /*,
				success: function(response, status) {
            // Update content data
            this.set('content.text', response);
						return false;
					} */
				},
			title: { button: true }
		},
		position: {
				at: 'left top',
				my: 'right top',
				type: 'static',
				adjust: {
					scroll: false,
					resize: false
					}
				},
		style: { classes: 'cart-board-tip' },
		show: 'click',
		hide: 'click',
		 events: {
		 show: 	function() {
					$('a.memo-top').qtip('hide');
					},
		 focus: function(event, api){
				 $('#minicart a.tool2').qtip('focus');
			}
		 }
		});
		that.qtip('show');
}
$(document).ready(function()
{
    $('a.memo-top').each(function()
   {
    //
     $(this).click(
         function(){
           makemehappy($(this));
           return false;
         }
      );
	});

   $('a[rel]#cart').each(function()
   {
    $(this).click(
         function(){
           makemehappy2($(this));
           return false;
         }
      );
	});
	

// GENRE TABS

   $('.tag-class a').each(function()
   {
      $(this).qtip(
      {
		id: $(this).attr('id'),
		content: 
			{
			ajax: 
				{
				method: 'get',
				url: $(this).attr('rel'),
				data: $(this).val(),
				success: function(response, status) {                        
                        var data;
						data = response;
 
                        // Update content data
                        this.set('content.text', data);
						
						return false;
					}
				}
		},

          position: {
					at: 'top center',
					my: 'top center',
				 	type: 'static'
				},
		 show: 'click',
         hide: 'unfocus',
         style: {
			classes: 'genrestyle-tip'
				}
		});
	});

 $('a.tool').css('display','none');

 $('a.tracktool').each(function()
   {
    if($(this).attr('rel')=='loaded') return true;
	  var id_parts=$('a.tool').attr('title').split('_');
	  //$('a.tool').attr('title','Share');

	  var content = '<a href="http://www.facebook.com/sharer.php?u=http://';
      content += $(this).attr('title');
      content += '" target="_blank">Share on Facebook</a>';
	  content += '<a href="http://twitter.com/home?status=Currently reading http://';
      content += $(this).attr('title');
      content += '" target="_blank">Share on Twitter</a>';
	  content += '<a href="http://www.stumbleupon.com/submit?url=http://';
      content += $(this).attr('title');
      content += '" target="_blank">Share on StumbleUpon</a>';
	  content += '<a href="mailto:?subject=';
	  content += $(this).attr('rel');
	  content += '&body=A%20friend%20has%20sent%20you%20the%20following%20link%20from%20artistxite.com.%0AClick%20on%20the%20link%20below%2C%20or%20copy%20and%20paste%20the%20link%20into%20your%20browser%3A%0Ahttp%3A%2F%2F';
      content += encodeURI($(this).attr('title'));
	  content += '%0AVisit%20artistxite%20at%20http%3A%2F%2Fwww.artistxite.com%0ADiscover%20new%20tunes%20and%20old%20favorites%2C%20forgotten%20treasures%20and%20upcoming%20artists.%0AListen%20to%20every%20single%20track.%0ABuy%20your%20favorite%20tunes%2C%20get%20good%20bargains%20and%20pre-order%20future%20releases.%0A%0Aartistxite.%20Where%20Music%20Matters.%20">Send to a friend</a>';

      $(this).qtip(
      {
        content: content,
        position: {
			my: 'right center',
			at: 'right center',
			adjust: {
					screen: false
					}
				},
         show: 'click',
         hide: 'unfocus',
         style: {
			classes: 'bookmark-tip'
         }
	});
   });


   $('#content a.buy').each(function()
   {
      var id_parts=$(this).attr('id').split('_');
      if($(this).hasClass('pre'))
        $(this).attr('title','Pre-Order '+id_parts[1]);
      else
        $(this).attr('title','Buy '+id_parts[1]);
      $(this).click(
         function(){
           in_cart(id_parts[1],id_parts[2],id_parts[3]);
		   $('a[rel]#cart').qtip('hide');
		   $('a.memo-top').qtip('hide');
           return false;
         }
      );
   });
   $('#content a.memo').each(function()
   {
      var id_parts=$(this).attr('id').split('_');
      $(this).attr('title','Add '+id_parts[1]+' to memo');
      $(this).click(
         function(){
           in_memo(id_parts[1],id_parts[2],id_parts[3]);
		   $('a[rel]#cart').qtip('hide');
		   $('a.memo-top').qtip('hide');
           return false;
         }
      );
   });
   $('#content a.memo-done').each(function()
   {
      var id_parts=$(this).attr('id').split('_');
      $(this).attr('title','Remove '+id_parts[1]+' from memo');
      $(this).click(
         function(){
           in_memo(id_parts[1],id_parts[2],id_parts[3]);
		   $('a[rel]#cart').qtip('hide');
		   $('a.memo-top').qtip('hide');
           return false;
         }
      );
   });
   $('#content a.bought').each(function()
   {
      var id_parts=$(this).attr('id').split('_');
      $(this).attr('title','Remove '+id_parts[1]+' from cart');
      $(this).click(
         function(){
           in_cart(id_parts[1],id_parts[2],id_parts[3]);
		   $('a[rel]#cart').qtip('hide');
		   $('a.memo-top').qtip('hide');
           return false;
         }
      );
   });
   $('#content a.bundle-only-buy').each(function()
   {
      var id_parts=$(this).attr('id').split('_');
      $(this).attr('title','Bundle only');
      $(this).click(
         function(){
		   $('a[rel]#cart').qtip('hide');
		   $('a.memo-top').qtip('hide');
         }
      );
   });

   $('#content a.preorder').each(function()
   {
      var id_parts=$(this).attr('id').split('_');
      $(this).attr('title','can not be bought separately');
      $(this).click(
         function(){
		   $('a[rel]#cart').qtip('hide');
		   $('a.memo-top').qtip('hide');
         }
      );
   });

// DOWNLOAD LINKS
/*
   $('a.zipload').each(function()
   {
    $(this).click(
         function(){
        //alert(lockerdatastring);return false;   
	if(!inprogress){
            inprogress=true;
            $('#update').html('prepare loading...');
            $('#lockerlayer').show();
            setTimeout('dopoll()', 2000);
            setTimeout("document.images['spinningwheel'].src='/img/ico/loader.gif'", 2000);
           }
         }
      );
    
   	  var content = '<div class="patiency">Please be patient while your download is being processed - this may take a moment.</div>';
	  content += '<div class="loader"><img src="/img/ico/loader.gif" alt="generating zip file" /></div>';
    content += '<div id="downloadmessage"></div>';
    content += '<div class="patiency">Do not close this browser window or click the ‘back’ button - or this download process will be discontinued.</div>';
    content += '<a href="#" id="closeoverlay">CLOSE</a>';
   
      $(this).qtip(
      {
		content: {
			text: content
		},
		 show: 'click',
         hide: {
				event: 'click',
				target: $('#closeoverlay')
		 },
         style: {
			classes: 'ui-tooltip-dark'
				},
		 position: {
		 		at: 'top left',
				my: 'top left',
				type: 'static',
				target: $('#index'),
				adjust: {
					x: 200
				},
			}
		});
		
	});*/
}); 
var failed=0;
function realdl(){
  inprogress=false;
  lockerdatastring="";
  document.images['spinningwheel'].style.visibility='visible';
  $('#lockerlayer').hide();
}
function dopoll(){
  //alert('poll=true&'+lockerdatastring);
  $.ajax({
			url: "/gettest.php",
			type: "POST",
      dataType: 'json',
      data: 'poll=true&'+lockerdatastring,
			async: false,
			success: function(data) {
        $('#update').html(data.message);
        if(data.status!="error" && data.status!="complete"){
          setTimeout(function() { dopoll(); }, 1000);
        }
        if(data.status=="nolog"){
           window.location.replace('?forcelogin=true');
        }
        if(data.status=="complete"){
           document.images['spinningwheel'].style.visibility='hidden';
           $('#update').html(data.message+"<br/><br/><a onclick=\"realdl();\" href='/downmp3.php?id="+data.did+"' class='downloadbutton'>Download Now</a><br/><br/>");
           //window.location.replace('/downmp3.php?id='+data.did);

        }
        /*
        if(data.status=="pending"){
          $('#update').html(data.message);
          setTimeout(function() { dopoll(); }, 1000);
        }
        else if(data.status=="fail"){
          $('#update').html('waiting for connection');
          if(failed<5)
            setTimeout('dopoll()', 1000);
          failed++;
        }
        else{
          $('#update').html("Finished");
          $('#lockerlayer').hide();
        } */
			}});

}

