$(function () {
	
	$(function() {
		var zIndexNumber = 1000;
		$('#menu').each(function() {
			$(this).css('zIndex', zIndexNumber);
			zIndexNumber -= 10;
		});
	});
	
	
	$('#menu .submenu').bgiframe();
	$('#menu .submenu').css('display', 'block');

    $('#menu li').hover(function () {
        $(this).toggleClass('hover');
    });

    $('#menu .submenu .bg_center').each(function () {
    	//alert($(this).parent().width());
    	//alert($(this).parent().parent().width() + ' '+ $(this).parent().width());
      
    	$(this).width($(this).parent().parent().width() - 11);
    	//$(this).width(200);
    });

    $('#menu .submenu').each(function () {

      
     	$this = $(this);
        $parent = $this.parent();

        parentCenter = $parent.offset().left + parseInt($parent.css('paddingLeft')) + $parent.width() / 2;
        parentBottom = $parent.offset().top + $parent.height() + parseInt($parent.css('marginTop')) + parseInt($parent.css('marginBottom')) + parseInt($parent.css('paddingTop')) + parseInt($parent.css('paddingBottom'));


        center = { left: parentCenter - $this.width() / 2, top: parentBottom };
        $this.offset(center);

        $('li:last', this).addClass('last');

    });


    $('#menu .submenu').css('display', '');
    
});
