function previewBar2Bottom(height) {
  jQuery('#previewbar').css('top', jQuery('#content').height() - jQuery('#preview').height() - jQuery('#previewbar').height());
}

function adjustHeight() {
  // adjusting height of panels
  jQuery('#content').height('100%');
  jQuery('.main .leftbar').height('100%');
  jQuery('.main .rightbar').height('100%');

  mheight = Math.max(jQuery('#content').height() - 1, jQuery('.main .leftbar').height(), jQuery('.main .rightbar').height());

  jQuery('.main .leftbar').height(mheight);
  jQuery('.main .rightbar').height(mheight);
  jQuery('#content').height(mheight);
  
  previewBar2Bottom();
}

function writeMail() {
  m1 = 'info';
  m3 = 'typotheque';
  m5 = 'com';
  m2 = '@';
  m4 = '.';
  
  m = m1 + m2 + m3 + m4 + m5;
  
  document.write('<a href="mailto: ' + m + '" title="Contact">Contact</a>');
}

function writeMailName(name, m1, m2, m3, m4, m5) {
  
  m = m1 + m2 + m3 + m4 + m5;
  
  document.write('<a href="mailto: ' + m + '" title="Email">' + name + '</a>');
}


// loaded after document is ready 
jQuery(document).ready(function() {
  adjustHeight();
  
  // preview functionality
  jQuery('a.load-thumb').click(function() {
  	var img = jQuery('img', this).attr('src');
    jQuery('#preview a').attr('href', jQuery(this).attr('href'));
    jQuery('#preview img').attr('src', img.replace(/small/, 'title'));
    adjustHeight();
    return false;
  });
  
  // news
  jQuery('a.load-news').click(function() {
    jQuery.ajax({
      type: 'GET',
      url: jQuery(this).attr('href'),
      success: function(html) {
        jQuery('.main .rightbar').html(html);
        adjustHeight();
      }
    });
    return false;
  });
  
  jQuery('span.tooltip').tooltip({
		track: true,
		delay: 0,
		showURL: false,
		showBody: ' - ',
		extraClass: 'pretty',
		fixPNG: true,
		left: -270
	});
  
  // poll
  jQuery('label.poll').click(function() {
    jQuery.ajax({
      type: 'GET',
      url: jQuery(this).parent('form').attr('action'),
      data: '&cal-pref=' + jQuery(this).prev('input[type=radio]').val(),
      success: function(html) {
        jQuery('#poll').html(html);
        adjustHeight();
      }
    });
    return false;
  });
  
  jQuery('label.poll').prev('input[type=radio]').click(function() {
    jQuery.ajax({
      type: 'GET',
      url: jQuery(this).next('label.poll').parent('form').attr('action'),
      data: '&cal-pref=' + jQuery(this).val(),
      success: function(html) {
        jQuery('#poll').html(html);
        adjustHeight();
      }
    });
    return false;
  });
});