(function ($) {

/**
 * MainMenu
 * @constructor jQuery
 */
$.widget('ui.MainMenu', $.extend({}, $.ui.Component.prototype, {
    type: 'MainMenu',
    init: function () {

		$('#menu ul li.dropDwn').hover(
			function() {
			    $(this).addClass("active");
			    
			    var ul = $(this).find('ul');
			    if ( ! this.initHeight) {
			        this.initHeight = ul.height();
			        ul.height(0);
				    ul.width($(this).width());
			    }
				ul.stop(true, false).animate({height: this.initHeight}, {
				    duration: (this.initHeight - ul.height()) * 10
				});
			},
			function() {
				$(this).removeClass("active");
				var ul = $(this).find('ul');
				ul.stop(true, false).animate({height: 0}, {
				    duration: ul.height() * 10,
				    complete: function () {
				        ul.hide();
				    }
				});
			}
		);

		$('div.city').hover(
			function() {
				$(this).addClass("activeCity");
				if($.browser.msie){
					$(this).height($(this).find('ul').height()+30);
				}
				$(this).find('ul').show();
			},
			function() {
			    var div = $(this);
				div.removeClass("activeCity").find('ul').hide();
			}
		);

		var cssFix = function(){
		
		  var u = navigator.userAgent.toLowerCase(),
		
		  is = function(t){return (u.indexOf(t)!=-1)};
		
		  $("html").addClass([
		
		    (!(/opera|webtv/i.test(u))&&/msie (\d)/.test(u))?('ie ie'+RegExp.$1)
		
		      :is('firefox/2')?'gecko ff2'
		
		      :is('firefox/3')?'gecko ff3'
		
		      :is('gecko/')?'gecko'
		
		      :is('opera/9')?'opera opera9':/opera (\d)/.test(u)?'opera opera'+RegExp.$1
		
		      :is('konqueror')?'konqueror'
		
		      :is('applewebkit/')?'webkit safari'
		
		      :is('mozilla/')?'gecko':'',
		
		    (is('x11')||is('linux'))?' linux'
		
		      :is('mac')?' mac'
		
		      :is('win')?' win':''
		
		  ].join(''));
		
		}();     

		
		$('#left').each(function() {
			divClass = $(this).attr('class').split(' ').slice(1,2);
			$(this).find('h3').css({
				'background' : 'url('+location.static+'/images/icons/ico_'+divClass+'.gif) no-repeat'
			});
		});
		
		$('div.TopMenu table').each(function(){
			$(this).find('td:first a').css({'border-left' : '#fff 0px solid'});
			$(this).find('td:last a').css({'border-right' : '#fff 0px solid'});
			$(this).find('td.selected').next().find('a').css({'border-left' : '#fff 0px solid'});
			$(this).find('td.selected').prev().find('a').css({'border-right' : '#fff 0px solid'});
		});

    }
}));

})(jQuery);