// CUSTOM JQUERY FUNCTIONS. USE $j TO AVOID CONFLICTS WITH PROTOTYPE

$j(function(){
  // CUSTOM FONTS
  Cufon.replace('.diavloLight',{
    fontFamily:'Diavlo Light',
    textShadow: '-1px -1px 0px #000',
    hover: true
  });
  Cufon.replace('.diavloMed',{
    fontFamily:'Diavlo Medium', 
    hover: true
  });
  Cufon.replace('.catMeta .diavloMed',{
    fontFamily:'Diavlo Medium', 
    textShadow: '-1px -1px 0px #000',
    hover: true
  });
    
  // SCROLLABLE
  $j("#banners").scrollable({
    clickable: false,
    size: 1,
    loop: true,
    activeClass: "active"
  });
  
  $j(function() {
    $j('#banners .items img:eq(1)').addClass('active');
        
    $j('.browse.right').live('click',function() {
      var highlighted = $j('#banners .items img.active');
      $j('#banners .items img').removeClass('active');
      $j(highlighted).next().addClass('active');

      if($j('#banners .items img:last').hasClass('active')) {
        $j('.browse.right').css({'visibility':'hidden'});
      }
    });  

    $j('.browse.left').live('click',function() {
      var highlighted = $j('#banners .items img.active');
      $j('#banners .items img').removeClass('active');
      $j(highlighted).prev().addClass('active');
      $j('.browse.right').css({'visibility':'visible'});
    });
  });
  
  // INITIATE BANNER LINK
  $j('.items img').click(function() {
    var url = $j(this).attr('rel');
    window.location = url;
  });
  
  // CLEAR INPUTS ON FOCUS AND RESTORE ON BLUR
  (function($){
  	$.fn.clearDefault = function(){
  		return this.each(function(){
  			var default_value = $(this).val();
  			$(this).focus(function(){
  				if ($(this).val() == default_value) // Use this if you only want the original value to erase
  				$(this).val("");
  			});
  			$(this).blur(function(){
  				if ($(this).val() == "") $(this).val(default_value);
  			});
  		});
  	};
  })(jQuery);
  
  $j('input.clear-default').clearDefault();
  
  // VERTICALLY ALIGN FUNCTION
  (function ($) {
  $.fn.vAlign = function() {
  	return this.each(function(i){
  	var ah = $(this).height();
  	var ph = $(this).parent().height();
  	var mh = (ph - ah) / 2;
  	$(this).css('margin-top', mh);
  	});
  };
  })(jQuery);  

  // ITEMS TO TARGET FOR VERTICAL ALIGN
  $('.postEntry .date').vAlign();  
});