var YC = {
  themeUrl: null,

  setup: function(url){
    this.themeUrl = url;
    $('body').addClass('js-enabled');
    this.setupServicesPromo();
    this.setupInputs();
	this.setupFacebox();
	this.setupTooltip();
  },

  /* Setup services promo */
  setupServicesPromo: function(){
    var promo = $('#promo .services');

    var itemConfig = {    
         sensitivity: 3,
         interval: 100, 
         over: function(){ 
			    $(this).siblings().removeClass('hover');
			    $(this).addClass('hover'); 
			  }, 
         timeout: 50, 
         out: function(){} 
    };

    var listConfig = {    
         sensitivity: 3,
         interval: 100, 
         over: function(){}, 
		     timeout: 50, 
         out: function(){
			     $(this).find('.hover').removeClass('hover');
		     } 
    };

    promo.find('li').hoverIntent(itemConfig);
	  promo.find('ul').hoverIntent(listConfig);
  },

  /* Setup inputs behavior */
  setupInputs: function(){
    $('input[type=text]').each(function(idx, elm){
      
      // for empty val inputs add Label as default value
      var val = $(elm).val();
  
      var lbl = $(elm).prev();
      var label = '';
      if(!(lbl.css('left') == 'auto' )) {
        label = $(elm).prev().text();
      }
      
      if( (val == '' ) && (label != '' )) {
        $(elm).val(label);
      }
      
      // Clear default values on enter
      val = $(elm).val();
      $(elm).
        focus(function(){
          if($(this).val() == val){
            $(this).val('');
          }
        }).
        blur(function(){
          if($(this).val()=='') {
            $(this).val(val);
          }
        });
    });
  
  },

  setupFacebox: function(){
    $('a[rel*=facebox]').facebox({
      opacity      : 0.5,
      loadingImage : this.themeUrl + '/js/facebox/loading.gif',
      closeImage   : this.themeUrl + '/js/facebox/closelabel.gif'
	}); 
  },

  setupTooltip: function(){
	$('a').each(function(idx, elm){
	  elm = $(elm);
	  if(elm.attr('title') == '') {
		var img = elm.find('img:only-child');
		if(img.size() == 1) {
		  elm.attr('title', img.attr('alt'));
		} else {
		  elm.attr('title', $(elm).text());
		}
	  }
	});
  }

}
