$(document).ready( function() {
   if ( $.browser.msie && parseInt($.browser.version, 10) <= 6 )
     setTimeout('resizeMenu()', 500); // wait for iefixes
   else
     resizeMenu();
     
    //popup banner 
    var pathname = $(location).attr('href');
    
    /* popup
    
		$('#popup').center();
		$('#popup').fadeIn('fast');
		$('.close_button').click(function() { $('#popup').fadeOut() } );
		setTimeout(function() { $('#popup').fadeOut('fast'); }, 12000);
	*/ 
});

function resizeMenu() {

   // resize menu items
   var targetW = $('#main_menu').width();
   var itemCount = $('#main_menu .drop_down').children('li').length;
   if (itemCount) {
      var realW = 0;
      $('#main_menu .drop_down').children('li').each(function() { realW += $(this).width(); });
      realW += itemCount - 1; // add separators

      var addToEach = Math.floor((targetW - realW)/itemCount);
      var addToLast = targetW - (realW + itemCount*addToEach); // calculate loss by Math.float

      $('#main_menu .drop_down').children('li').each(function(index) {
         var item = $(this).children('a').children('span');
         if (index == itemCount-1)
            item.width(item.width() + addToEach + addToLast);
         else
            item.width(item.width() + addToEach);
      });
   }

   ie6menuFix();
}

function ie6menuFix() {
   // fix dropdown menu for ie6
   if ($.browser.msie && $.browser.version.substr(0,1)<7) {
      $('body').append(
         $('<iframe>').
            addClass('mask').
            css({
               border: '0px',
               position: 'absolute',
               display: 'none',
               background: '#fffffc'
            })
      ).append(
         $('<div>').attr('id', 'main_menu_copy')
                   .html($('#main_menu').html())
                   .css({
                      position: 'absolute',
                      top: $('#main_menu').offset().top,
                      left: $('#main_menu').offset().left,
                      width: $('#main_menu').width(),
                      'z-index': 15000
                    })
      );

      $('#main_menu_copy ul.drop_down > li.submenu').hover(
		function() {
		  var sub = $(this).children('ul');
		  sub.css({
			visibility: 'visible'
		  });
		},
		function() {
		  var sub = $(this).children('ul');
		  sub.css({
			visibility: 'hidden'
		  });
		}
      );

      /**$('#main_menu_copy ul.drop_down > li.submenu').hover(
            function() {
               var sub = $(this).children('ul');
               sub.css({
				 'z-index': '15000',
				 display: 'block'
               });
               $('iframe.mask').css({
                  width: sub.width(),
                  height: sub.height(),
                  top: sub.offset().top,
                  left: sub.offset().left,
                  'z-index': 14990
               }).hide();
            },
            function() {
               $('iframe.mask').hide();
               sub.hide();
            }
      );*/
   }
}

function printOrder(_url) {
	printWindow = window.open(_url,
							  "printWindow","toolbar=0, location=0, status=1, resizable=1, menubar=1, "+
							  "scrollbars=1, width=750, height=540");
	printWindow.focus();
}

jQuery.fn.center = function () {
	this.css("position","absolute");
	this.css("top", (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop() + "px");
	this.css("left", (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft() + "px");
	return this;
}


function sredi_sadrzaj() {} // dummy

