/*
 * jQuery homeCol
 * 
 * Copyright (c) 2008 Łukasz Świerżewski
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * @version 1.0.0
 * @author Łukasz Świerżewski
 * @mailto lukasz at zirpe dot com
 */

jQuery.fn.extend({
 homeCol: function(options) {
  return this.each(function() {
   new jQuery.HomeCol($(this), options);
  });
 }
});

jQuery.HomeCol = function(o_element, am_options) {
 var options = am_options || {};

 var $o_line = $('.line', o_element);
 var $o_image = $('.image', o_element);

 var i_defaultHeight = $o_line.height();
 var i_diffHeight = ($o_line.offset()).top;
 var b_resetLine = true;

 init();

 function init() {
  //if (!options) {}

  $o_image.css({visibility: 'visible', opacity: 0});

  $('li', o_element).each(function() {
   var i_heightForItem = ($(this).offset()).top - i_diffHeight + $(this).height();

   $(this).hover(function() {
    b_resetLine = false;
    $(this).addClass('hover');
    $o_image.stop().animate({opacity: 1}, 200);
    $o_line.stop().animate({height: i_heightForItem + 'px'}, 200);
   }, function() {
    b_resetLine = true;
    $(this).removeClass('hover');
    setTimeout(function() {
     if (b_resetLine) {
      $o_image.animate({opacity: 0}, 200);
      $o_line.animate({height: i_defaultHeight + 'px'}, 200);
     }
    }, 300);
   }).click(function() {
    document.location = $('a:first', this).attr('href');
   });
  });

 }

};
