/*
---------------------------------------------
* jQuery-Plugin "Navigation Equal Width"
* Version: 1.0, 1.1.2011
* by Lazarev Alexsandr, regatagroup@gmail.com
* Daronet: Dev Group
---------------------------------------------
*/

/*Navigation Equal Width*/
function BlackNavigationEqualWidth(w) {
  var curwidth = 0;
  var totalelements = 0;
  //Need display:none in your css for correct render js.
  //Restore display:block after 100% width calculation.
  $('.models-panel ul').css('display', 'block');
  $('.models-panel li a.ShortTitle').each(function() {
    curwidth = curwidth + $(this).outerWidth();
    totalelements = totalelements + 1;
  });

  if ((w - curwidth) > 0) { 
    var pad = Math.floor(((w - curwidth) / totalelements) / 2);
    $('.models-panel li a.ShortTitle')
						.css('padding-left', pad + 'px')
						.css('padding-right', pad + 'px')

    // Check for remainder
    var newwidth = curwidth + (totalelements * (pad * 2));

    // Add padding to last element to close remainder gap		
    if (newwidth < w) {
      var remainder = (w - newwidth ) / 2;
      $('.models-panel li a.ShortTitle:last')
						.css('padding-right', (pad + remainder) + 'px')
						.css('padding-left', (pad + remainder) + 'px');
						$('.models-panel li:last')
						.addClass('last');
    }
  }
}

$(document).ready(function() {
  //Start function
  BlackNavigationEqualWidth(980);
		
		//Homepage cars detail popup
  $(function() {
    $('.models-panel li').hover(
		  function() {
		    var $this = $(this);
		    $(this).addClass('hover')
		    $('.popup, .popup2', $this).stop(true, true).fadeIn('fast').css({ 'display': 'block' });
		  },
		  function() {
		    var $this = $(this);
		    $(this).removeClass('hover')
		    $('.popup, .popup2', $this).stop(true, true).fadeOut('fast');
		  }
	  );
  });
		
});		
