jQuery(document).ready(function() {
 // hides the slickbox as soon as the DOM is ready
 // (a little sooner than page load)
  jQuery('#slickbox').hide();
 // shows the slickbox on clicking the noted link
  jQuery('a#slick-show').click(function() {
  jQuery('#slickbox').show('slow');
  return false;
  });
 // hides the slickbox on clicking the noted link
  jQuery('a#slick-hide').click(function() {
  jQuery('#slickbox').hide('fast');
  return false;
  });
 // toggles the slickbox on clicking the noted link
  jQuery('a#slick-toggle').click(function() {
  jQuery('#slickbox').slideToggle(400);
  return false;
  });
  // fuzzy timestamps
  jQuery('time.timeago').timeago();

  // change the search
  $("#selectsearch").change(function() {
  var action = $(this).val() == "drink" ? "drinks" : "users";
  $("#SearchForm").attr("action", "/" + action + "/search/");
  $("#SearchQ").attr("search","data[User][search]");
  $("#SearchQ").attr("name","data[User][search]");
  });

  // toggles user drinks & user comments on user profile page
  $('.user-latest-comments').hide();
  $('.user-latest-wall').hide();
	
  $('#tabs li').click(function() 
	{
		var $this = $(this);
	
	    if ($this.attr("id") == ('tab-drink')) 
		{
				
			$("#tab-drink").removeClass().addClass("active");
			$("#tab-comment").removeClass("active").addClass();
			$("#tab-wall").removeClass("active").addClass();
			
			$('.user-latest-cocktails').show();
			$('.user-latest-comments').hide();
			$('.user-latest-wall').hide();
	    } 
		else if ($this.attr("id") == ('tab-comment')) 
		{
	    		$("#tab-drink").removeClass("active").addClass();
			$("#tab-comment").removeClass().addClass("active");
			$("#tab-wall").removeClass("active").addClass();
	
			$('.user-latest-comments').show();
			$('.user-latest-cocktails').hide();
			$('.user-latest-wall').hide();
	   	} 
		else if ($this.attr("id") == ('tab-wall')) 
		{
	    		$("#tab-drink").removeClass("active").addClass();
			$("#tab-comment").removeClass("active").addClass();
			$("#tab-wall").removeClass().addClass("active");
	
			$('.user-latest-comments').hide();
			$('.user-latest-cocktails').hide();
			$('.user-latest-wall').show();
	   	} 
		else 
		{
                        $('.user-latest-cocktails').show();
			$('.user-latest-comments').hide();
			$('.user-latest-wall').hide();
	    }

    return false;

	});

// shows drink name in overlay on hover in the mydrinks widget
  $("#my-drinks img").hover(function() {
            $(this).next("p").animate({opacity: "show", top: "-75"}, "slow");
          }, function() {
            $(this).next("p").animate({opacity: "hide", top: "-85"}, "fast");
  });

// hides flash message
  setTimeout(function() {
    $('#flashMessage').fadeOut('slow');
  }, 3000); // <-- time in milliseconds

// hides alert message 
  setTimeout(function() {
    $('#alert').hide('slow');
  }, 10000); // <-- time in milliseconds

// adds http:// to url field so user doesnt forget

  //  Initialize auto-hint fields
        $('INPUT#UserWebsite').focus(function(){
	  if($(this).val() == '') {
	    $(this).val($(this).attr('title'));
	  }
            
        });
	
// get param url
jQuery.fn.extend({getUrlParam:function(d){d=escape(unescape(d));var c=[],b=null;if($(this).attr("nodeName")=="#document"){if(window.location.search.search(d)>-1)b=window.location.search.substr(1,window.location.search.length).split("&")}else if($(this).attr("src")!="undefined"){var a=$(this).attr("src");if(a.indexOf("?")>-1){b=a.substr(a.indexOf("?")+1);b=b.split("&")}}else if($(this).attr("href")!="undefined"){a=$(this).attr("href");if(a.indexOf("?")>-1){b=a.substr(a.indexOf("?")+1);b=b.split("&")}}else return null;
if(b===null)return null;for(a=0;a<b.length;a++)escape(unescape(b[a].split("=")[0]))==d&&c.push(b[a].split("=")[1]);return c.length===0?null:c.length==1?c[0]:c}});

});

// shows comment loading after click and disables second click on submit
// first hide the loading div
$('#loading').hide();
// when comment is submitted then pop up the loading div
$('#CommentAddForm').submit(function() {
    $('#loading').show(); // show message
    $('html, body').animate({scrollTop:0}, 'slow'); // scroll to top of page
    $('#loading').append('<div><p>Your comment is being saved, this will only take a moment.</p></div>'); // show our message

    $(":submit", this).attr("disabled", "disabled");  // disable submit button after initial click
});

