(function($){$.fn.ghostText = function() {
  return this.each(function(){

    this.showGhost = function()
    {
      if($(this).val() == "")
        $(this).val($(this).attr("data-label")).addClass("ghosted");
    }
    
    this.hideGhost = function()
    {
      if($(this).val() == $(this).attr("data-label"))
        $(this).val("").removeClass("ghosted");
    }
    
    this.showGhost();
    $(this).attr("autocomplete", "off");    // Sorts out bug.
    
    $(this).focus(function(e) { 
      e.target.hideGhost();
    });
    
    $(this).blur(function(e) {
      e.target.showGhost();
    });
    
    $(this).parents("form:first").submit(function(e) {
      $("input[type=text][data-label]", e.target).each(function() { 
        if(this.hideGhost) this.hideGhost(); 
      });
    });
  });
};})(jQuery);

(function($){$.fn.makePretty = function() {
  return this.each(function(){
    /* Makes the pretty rounded corner inputs. */
    $("input[type=text], input[type=password]", this).each(function() {
      if ($(this).parents("div.rounded-input:first").length == 0)
      {
        $(this).wrap("<div class='rounded-input'><div /></div>");
        $(this).parents("div.rounded-input:first").attr("style", $(this).attr("style"));
        $(this).attr("style", "");
        $(this).css("width", "100%");
      }
    });

    /* Ghost Labels, automatically added and removed from around text inputs
       Labels are specified via the data-label attribute on the element.
    */
    $("input[type=text][data-label]", this).ghostText();
    
    
    // to apply only to checkbox use:
    $('input[type="checkbox"]').not($('.terms_and_conditions input[type="checkbox"]')).ezMark();
    $('.terms_and_conditions input[type="checkbox"]').ezMark({checkboxCls: 'ez-checkbox-small', checkedCls: 'ez-checked-small'});
    
    // for only radio buttons:
    $('input[type="radio"]').ezMark();
    
  });
};})(jQuery);


$(document).ready(function() {
  
  $.fn.fancybox.defaults.width = 590;
  $.fn.fancybox.defaults.height = 370;

  /* Any button with the class of print will print the page when clicked. */
  $("button.print").live("click", function(e)
  {
    window.print();
  });
  
  // $(".slider").slider();
  $(".fader").fader();
  
  $(".postcode-search").autocomplete('/postcodes', { mustMatch: true, delay: 200 });
  $(".framed-interaction-area").append("<div class='clear'>.</div>").append("<br/>");
  
  $(document).makePretty();
  $(document).bind("fancybox:show", function() { $("#fancybox-inner").makePretty(); });

 /**
 	Adds the active class to the menu tab according to the URL
  */ 
  $(".menu li").removeClass("active");
  match = window.location.href.match(/[a-z0-9]\/([a-z_-]+)/);
  if(match == null) { match = "home"; }
		
  switch (match[1]) {
	 case 'detailed_connection': $(".menu li.connect_later").addClass("active"); break;  
	 case '': $(".menu li.home").addClass("active"); break;  
	 case 'quick_connect': $(".menu li.connect_me").addClass("active"); break;  
	 case 'promotions': $(".menu li.promos").addClass("active"); break;  
	 case 'moving-tips': $(".menu li.moving_tips").addClass("active"); break;  
	 case 'about-us': $(".menu li.about_us").addClass("active"); break;  
	 default : $(".menu li.home").addClass("active");
	}

});

