//<![CDATA[
$(document).ready(function() {

  // reset text in all input fields
  $('input[type=text], textarea').reSetValue();

  // lang overlay
  $('.overlay').hide();
  $('.lang-head').click(function() {
    toggleXtra($(this));
    return false;
  });

  // hide lang on click outside the element    
  $(document).click(function(event) {
    var t = $(event.target);
    if (!t.parent().hasClass('lang-head') && !t.parents().hasClass('overlay')) {
      $('.overlay').hide();
    }
  });

  // tip-friend modal function
  $('div.lightboxme').hide();
  $('a.lightboxme').click(function() {
    var t = $(this).attr('rel');
    $('div.' + t).lightbox_me({
      centered: true,
      overlayCSS: { background: '#333', opacity: .5 },
      overlaySpeed: 300,
      lightboxSpeed: "normal"
    });
    return false;
  });

  $('a[rel=tipfriend]').click(function() {
    $('.lb_overlay, div.lightboxme').fadeOut(500);
    $('div.tipfriend').lightbox_me({
      centered: true,
      overlayCSS: { background: '#333', opacity: .5 },
      overlaySpeed: 300,
      lightboxSpeed: "normal"
    });
    return false;
  });

});

function toggleXtra(ref) {
  /* vars */
  var all = $('.overlay');
  var pre = all.prev();
  var el = ref.next();
  /* toggle class */
  pre.removeClass('active');
  $(ref).addClass('active');
  if (el.is(':visible')) {
    all.hide();
  } else if (el.is(':hidden')) {
    all.hide();
    el.show();
  }
  return false;
}

//]]>
        
        

