$( document ).ready( function()
{
  /////////////////////
  // Browser support //
  /////////////////////
  if ( browserSupported() )
  {
    if ( !$.browser.msie )
    {
      var css = $( "<link/>" ).attr(
      {
        type: 'text/css',
        rel: 'stylesheet',
        href: '/css/font.css'
      });
      $( "head" ).append( css );
    }
    else
    {
      $( 'input.upload-overlay' ).each( function()
      {
        $( this ).attr( 'title', 'Double click on this field to edit' );  // need a workaround for IE double click instead
      });
    }
  }
  else
  {
    if ( !$.cookie( 'browser-warning' ) )
    {
      $.cookie( 'browser-warning', 'warned' );
      var message = "You are using an unsupported version of your browser! Supported browsers are:\n\n";
      message    += "\tGoogle Chrome 4 or higher (recommended)\n";
      message    += "\tMozilla Firefox 3.5 or higher (recommended)\n";
      message    += "\tApple Safari 3.1 or higher\n";
      message    += "\tMicrosoft Internet Explorer 7 or higher.\n";
      message    += "\nWe highly recommend that you one of these browsers in order to properly view this website.";
      alert( message );
    }
  }
  /////////////////
  // News ticker //
  /////////////////
  $().newsTicker({
    newsList: "#listticker",
    startDelay: 10,
    placeHolder1: " _",
    placeHolder2: "",
    controls: false,
    stopOnHover: false
  });
});

///////////////
// Functions //
///////////////

function browserSupported()
{
  if ( $.browser.msie )
  {
    if ( parseInt( $.browser.version ) >= 7 ) return true;
  }
  if ( $.browser.mozilla )
  {
    if ( $.browser.version >= '1.9.1' ) return true;
  }
  if ( $.browser.webkit )
  {
    if ( /chrom/.test( navigator.userAgent.toLowerCase() ) )
    {
      if ( $.browser.version >= '532.1' ) return true;
    }
    // http://www.zytrax.com/tech/web/mobile_ids.html
    else if ( /apple/.test( navigator.userAgent.toLowerCase() ) && !( /mobile/.test( navigator.userAgent.toLowerCase() ) ) ) // achtung mobile!
    {
      if ( $.browser.version >= '525' ) return true;
    }
  }
  if ( $.browser.opera )
  {
    if ( parseInt( $.browser.version ) >= 10 ) return true;
  }
  return false;
}

function getDatasetId( el )
{
  var str = el.id;
  var pos = str.lastIndexOf( "_" ) + 1;
  if ( pos < 0 ) return false;
  return str.substr( pos );
}

