
function init_contacts()
{
  $(function(){

    $('#contactstop').css('overflow', 'hidden');

    function each_a(i, e)
    {

      $(e).click(function()
      {
        var h = $('#contactstop').height();

        $('#contactstop').animate({ height: 0 }, h * 4, null, function()
        {

          $('#contactstop').css('height', 'auto').css('display', 'none');
          $('#contactstop').html( $('.full', $(e).parents()[4] ).html() );

          var h = $('#contactstop').height();

          $('#contactstop').css('height', 0).css('display', 'block');

          $('#contactstop').animate({ height: h }, h * 4);

        });

        return false;
      });

    }

    $('#contacts td.c3 a').each(each_a);
    $('#contacts td.c1 a').each(each_a);

  });

}


function init_rightpanel()
{
  $(function() {
    var is_open = false;
    var rp_right = parseInt($('#rightpanel').css('right'));

    $('#rightpanel').mouseenter(function()
    {
//      if ($('#rightpanel').data('animating')) return;

      $('#rightpanel').data('animating', true);

      $('#rightpanelwrap').stop(true).animate({ width: 270 }, 500);
      $('#rightpanel').stop(true).animate({ right: 0 }, 500, null, function()
      {
        is_open = true;
        $('#rightpanel').data('animating', false);
      });

      return false;
    });

    $('#rightpanel').mouseleave(function()
    {
//      if ($('#rightpanel').data('animating')) return;

      $('#rightpanelwrap').stop(true).animate({ width: 70 }, 500);
      $('#rightpanel').stop(true).animate({ right: rp_right }, 500, null, function()
      {
        is_open = false;
        $('#rightpanel').data('animating', false);
      });

    });

  });
}


function init_sitemaplink()
{
  $(function(){
    var animating = false;
    var h = $('#sitemap').height() + 90;
//    $('#sitemap').css('overflow', 'hidden').height(0);
    var min_h = 0;
    var is_open = ($('#sitemapwrap').height() > min_h);

//    if ($.browser.msie) h -= 15;

    $('#sitemapwrap').css('overflow', 'hidden');
    $('#sitemap').css('overflow', 'hidden');

    $('#sitemaphead a.sitemaplink').click(function()
    {
      if (animating) return false;

      animating = true;
      if (is_open)
      {
        $('#sitemapwrap').animate({ height: min_h }, (h - min_h) * 4, null, function()
        {
          is_open = false;
          animating = false;
        });
      }
      else
      {
        $('#sitemapwrap').animate({ height: h }, (h - min_h) * 4, null, function()
        {
          is_open = true;
          animating = false;
        });
      }

      return false;
    });
  });
}


function easeOutCubic(x, t, b, c, d)
{
  return c*((t=t/d-1)*t*t + 1) + b;
}

function init_brands_scroller()
{
//  return;
  $(function(){

    var step = 2;
    var pos = 0;
    var scr = $('#brands .mid');
    if (!scr) return;

    $('#brands .left a').click(function(){
      pos -= 50;
      if (pos < 0) pos = 0;
      return false;
    });

    $('#brands .right a').click(function(){
      pos += 50;
      var max = scr.scrollWidth() - scr.innerWidth();
      if (pos > max) pos = max;
      return false;
    });

    function scrollSlide()
    {

      var min = 0;
      var max = scr.scrollWidth() - scr.innerWidth();

//      var val = easeOutCubic(0, pos - min, min, max - min, 30);

      pos += step;
      if (pos >= max) step = -step;
      else if (pos <= min) step = -step;

      scr.scrollLeft(pos);
    }

    setInterval(scrollSlide, 30);
  });
}

try {
  // Create scrollWidth method
  $.fn[ 'scrollWidth' ] = function(val) {
  if (!this[0]) return;

  return val != undefined ?

  // Set the scrollWidth
  this.each(function() {
  this == window || this == document ?
  window.scrollWidth( val ) :
  this[ 'scrollWidth' ] = val;
  }) :

  // Return the scrollWidth
  this[0] == window || this[0] == document ?
  self[ 'scrollWidth' ] ||
  $.boxModel && document.documentElement[ 'scrollWidth' ] ||
  document.body[ 'scrollWidth' ] :
  this[0][ 'scrollWidth' ];
  };
}
catch (e) {}


function init_labelify()
{
  $(function(){
    $(".labelify").labelify({
      labelledClass: 'labelHighlight'
    });
  });
}


function init_voted_box()
{
  $(function(){
    var animating = false;
    var div = $('#votebox .rwrap');
    var is_open = (div.height() != 0);

    var h = $('#votebox .rwrap .results').outerHeight();
    var min_h = 0;

    if ($.browser.msie) h += 10;

    div.css('overflow', 'hidden');

    $('#votebox a.voted').click(function()
    {
      if (animating) return false;

      animating = true;
      if (is_open)
      {
        div.animate({ height: min_h }, (h - min_h) * 4, null, function()
        {
          is_open = false;
          animating = false;
        });
      }
      else
      {
        div.animate({ height: h }, (h - min_h) * 4, null, function()
        {
          is_open = true;
          animating = false;
        });
      }

      return false;
    });
  });

}


function init_request_form()
{

}

