
$(function()
{
  $('#searchinput').labelify();

  $('#cols .post img').parents('a[rel=g]').fancybox();
});


var preloaded_images = [];

function preloadImages(images)
{
  for (var i=0; i<images.length; i++)
  {
    var im = new Image();
    im.src = images[i];
    preloaded_images.push(im);
  }

}


function initHome()
{
  $(function()
  {
    preloadImages([
      '/images/html/rezgis1-hover.jpg',
      '/images/html/rezgis2-hover.jpg'
    ]);

    $('#main a.rezgis1').mouseover(function()
    {
      $('.colored', this)
        .stop()
        .css('opacity', 0)
        .show()
        .fadeTo(250, 1);

    });
    $('#main a.rezgis1').mouseout(function()
    {
      $('.colored', this)
        .stop()
        .fadeTo(250, 0);

    });

    $('#main a.rezgis2').mouseover(function()
    {
      $('.colored', this)
        .stop()
        .css('opacity', 0)
        .show()
        .fadeTo(250, 1);

    });
    $('#main a.rezgis2').mouseout(function()
    {
      $('.colored', this)
        .stop()
        .fadeTo(250, 0);

    });

  });
}


function initSingleProject()
{
  $(function()
  {
    $('#project .pics a').fancybox();
  });
}

function initSingleNews()
{
  $(function()
  {
//    $('#news .post a.pic').fancybox();
  });
}


function initSlider()
{
  $(function()
  {
    var step = 3;
    var pos = 0;
    var scr = $('#projslides');
    if (!scr) return;

    var projects = $('#projslides > .inner > a');

    var orig_count = projects.length;
    var win_width = $(scr).innerWidth();
    var e_width = $(projects[0]).outerWidth(true);
    var per_window = Math.ceil(win_width / e_width);
    var wrap_pos = orig_count * e_width;

    for (var i=0; i<per_window; i++)
    {
      $(projects[i % projects.length]).clone().appendTo('#projslides > .inner');
    }

    var sleep_steps = 80;

    function scrollSlide()
    {
      if (sleep_steps > 0)
      {
        sleep_steps--;
        return;
      }

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

      pos += step;

      if (pos > wrap_pos) pos -= wrap_pos;

      if (pos >= max) { step = -step; sleep_steps = 80; }
      else if (pos <= min) { step = -step; sleep_steps = 80; }

      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 initVakanceForm(options)
{
  $(document).ready(function()
  {
    $('#upload-btn').uploadify({
      'uploader' : '/scripts/uploadify-btn1.swf',
      'script' : escape(options.upload_url),
      'scriptData' : {},
      'cancelImg' : '/scripts/components/uploadify/cancel.png',
      'auto' : true,
      'width' : 91,
      'height' : 30,
      'buttonText' : escape(options.texts.ieladet),
      'rollover' : false,
      'wmode' : 'transparent',
      'multi' : false,
      'fileDesc' : 'Documents (doc, xls, docx, xlsx, pdf, rtf, txt)',
      'fileExt' : '*.doc;*.xls;*.docx;*.xlsx;*.pdf;*.rtf;*.txt',

      'onComplete' : function(event, queueID, fileObj, response, data)
      {
        if (response != '1')
        {
          $('#vl-debug').html(response);
          return;
        }

      },

      'onAllComplete' : function(e, data)
      {
        cmpPost('vakanceform', 'loadFileDesc', '', {}, {}, function(data)
        {
          $('#file-desc').html(data);

        });

      }

    });

  });

}
