$.fn.qtip.styles.language_switcher = {
  width: 220,
  padding: 15,
  background: ((jQuery.browser.msie) ? '#3b3b3b' : 'rgba(0,0,0,0.6)'),
  color: '#fff',
  textAlign: 'left',
  border: {
     width: 1,
     radius: 6,
     color: '#000'
  },
  tip: 'topRight'
}

$.fn.qtip.styles.event = {
  width: 460,
  padding: 20,
  background: '#f0f0f0',
  color: '#6a6a6a',
  textAlign: 'left',
  border: {
     width: 5,
     color: '#bc2525'
  },
  tip: 'bottomMiddle',
  title: {
    background: '#cd5c5c',
    color: '#fff'
  }
}

$(document).ready(function()
{
  /**
   * Clears the search field on focus and returns
   * to original state if left empty
   */
  $('#search_field').focus(function()
  {
    if ($(this).val() === 'search...') $(this).val('');
  });
  $('#search_field').blur(function()
  {
    if ($(this).val() === '') $(this).val('search...');
  });
  
  /**
   * Set rules for language switcher tooltip control
   */
  $('#language_switcher').click(function(){return false});
  $('#language_switcher').qtip({
    content: $('#languages'),
    show: 'click',
    hide: 'unfocus',
    position: {
      corner: {target: 'bottomLeft', tooltip: 'topRight'},
      adjust: {x: 10}
    },
    style: 'language_switcher',
    api: {
      beforeShow: function(){
        this.elements.target.addClass('active');
        if (jQuery.browser.msie && jQuery.browser.version === '6.0') DD_belatedPNG.fix('#languages a');
      },
      beforeHide: function(){
        this.elements.target.removeClass('active');
      }
    }
  });
  
  $('a.event').click(function(){
    var title = $(this).text();
    return false});
  $('a.event').qtip({
    content: {
      title: 'xxx',
      text: 'yyy'
    },
    show: 'click',
    hide: 'unfocus',
    position: {
      corner: {target: 'topMiddle', tooltip: 'bottomMiddle'}
    },
    style: 'event',
    api: {
      beforeShow: function(){
        this.updateTitle(this.elements.target.text());
        this.updateContent($(this.elements.target.attr('href')).html());
      }
    }
  });
});