
function magicinput(e){
  if(e.defaultValue == e.value){
    e.value=''
  }
  
  e.onblur = function(){
    if(e.value==''){
      e.value = e.defaultValue;
    }
  }
}

$.fn.starRating = function(){

  var $form = this.parent('form');
  var url = $form.attr('action');
  return this.stars({
    inputType: "select",
    oneVoteOnly: true,
    starClass: 'ui-stars-star',
    starOnClass: 'ui-stars-star-on',
    starHoverClass: 'ui-stars-star-hover',
    cancelHoverClass: 'ui-stars-cancel-hover',
    captionEl: $('#caption'),
    callback: function(ui, type, value){
      $.post(url, $form.serialize(), function(data, textStatus, xhr){
        $('#count').html(data.count);
        $('#avg').html(data.avg);
      });
    }
  });
};


$.fn.enableLyric= function(){
	this.each(function(){
		var $this = $(this);
		var id = $this.attr('data-lyric');
		
		$this.load("/noindex/lyric/"+id);
		
	})
}






$(document).ready(function() {
      $.localScroll();
      $('.table :checkbox.toggle').each(function(i, toggle) {
        $(toggle).change(function(e) {
          $(toggle).parents('table:first').find(':checkbox:not(.toggle)').each(function(j, checkbox) {
            checkbox.checked = !checkbox.checked;
          })
        });
      });
    });
	

	
$(document).ready(function() {
  $('#q').autocomplete({
    source: '/search/autocomplete?',
    minLength: 3
  });
  
  $('#song_title').autocomplete({
    source: '/search/autocomplete?',
    minLength: 3
  });
  
  $(function(){
	  $('.lyric_box').enableLyric();
	});
  
  
  $('a[rel=favorite]').addFavorite();
  $('#stars-wrapper').starRating();
  $(".images a:has(img)").fancybox();
  
  Cufon.replace('.head, .topnav, #footer h6',  { fontFamily: 'Ubuntu Titling Rg' , hover: true, textShadow: '1px 1px rgba(0, 0, 0, 0.2)'
 });
  
  $('.menu-nav li').hover(
			function() {
				$(this).addClass("active");
				$(this).find('.ulwrapper').stop(false, true).slideDown();
				$(this).find('.ulwrapper .ulwrapper').stop(false, true).slideUp('fast');
			},
			function() {
				$(this).removeClass("active");        
				$(this).find('div').stop(false, true).slideUp('fast');
			}
		);
		$('.ulwrapper').hover(
			function() {
				$('.parent').addClass("active_tab");
			},
			function() {
				$('.parent').removeClass("active_tab");        
			}
		);
  
//  window.fbAsyncInit = function() {
//FB.init({appId: 'c7a25d00ec3c551b767c1b2b610dddc8', status: true, cookie: true,
//         xfbml: true}, '/xd_receiver.html');
//};
//(function() {
//var e = document.createElement('script'); e.async = true;
//e.src = document.location.protocol +facebook_host();
//document.getElementById('fb-root').appendChild(e);
//}());
});	


function facebook_host()
{
	var hostname = window.location.hostname;
	
	if(hostname.indexOf('de') > -1)
	{
		return '//connect.facebook.net/de_DE/all.js';
	}
	else
	{
		return '//connect.facebook.net/en_US/all.js';
	}
}




function publish_fb(message)
{
FB.ui(
   {
     method: 'stream.publish',
     message: '',
    },{}
  );

}

