//Browsers
$.browser.chrome = navigator.userAgent.toLowerCase().indexOf("chrome")!=-1;

// JavaScript Document
var SrchCont = 'Поиск';
var CommCont = 'Гость';



/////////////////////////////////////////////////////////////////
function getOrder(selector, cookieName, cookieExpiry) {
	$.cookie(cookieName, $(selector).sortable("toArray"), { expires: cookieExpiry, path: "/" });
}
 
// function that restores the list order from a cookie
function restoreOrder(selector, cookieName, sortableObj) {
	var list = $(selector);
	if (list == null) return;
	var cookie = $.cookie(cookieName);
	if (!cookie) return;
	var IDs = cookie.split(","),
		items = list.sortable("toArray"),
		rebuild = new Array();
	for ( var v=0, len=items.length; v<len; v++ ){
		rebuild[items[v]] = items[v];
	}
}

var urlGrabber = function(){
	var matches = new Array();
	matches = location.href.match(/\#(.*)$/);
	if (matches){
		return matches[1];
	}
	return false;
}

$(document).ready(function() {	
	
		$('span.dropdownMenuItem img').click(function(){
			$(this).parent().find('ul').show();
			$(this).parent().addClass('active');
		});
		$('span.dropdownMenuItem').mouseleave(function(){
			$(this).find('ul').hide();
			$(this).removeClass('active');
		});

		if($("#newsSort").length) {
			$("#newsSort").mouseover(function(){
				$(this).sortable({
					handle: 'div.title',
					axis: 'y',
					distance: 5,
					update: function() {
						getOrder("#newsSort", "NewsBlocksOrder", 7);
					}
				});			
				restoreOrder("#newsSort", "NewsBlocksOrder", "#newsSort.ui-sortable");
			});
		}
					
		$("#gadgets").mouseover(function(){
			$(this).sortable({
				handle: 'div.title',		
				axis: 'y',
				distance: 5,
				update: function() { 
					getOrder("#gadgets", "listOrder", 7);
				}
			})
			restoreOrder("#gadgets", "listOrder", "#gadgets.ui-sortable");
		});

		/*
		if (typeof(hostname) == 'undefined') {
			var address = window.location.href;
			if ($(document).width() > '1200' || address.search('http://tochka.net') != -1) {
				$.cookie('ws', '1', {
					  expires: 1,
					  path: "/",
					  domain: ".tochka.net"
				}); 
				document.getElementById('all').className = 'widescreen'; 
			} else {
				$.cookie('ws', null, {
					  expires: 1,
					  path: "/",
					  domain: ".tochka.net"
				});
				$('#all').removeClass('widescreen');
				$('div.left').hide();
				
			} 
			$('#main.profile,#main.frontpage').each(function() {
				$('#all').removeClass('widescreen');
			});
		}
		*/


/* MOUSE OVER AND PRESSDOWN*/
/*
		$('div.left ul.menu li').each(function() {
			divClass = $(this).children().attr('class');
			$(this).children().css({
				'background' : 'url('+location.static+'main/images/menu_icons/'+divClass+'.gif) no-repeat 8px 0'
			});
		});
*/
		/*$('li.mailG table').each(function() {
			$(this).find('tr:last').find('td').css({
				'background-image' : 'none'
			});
		});

		$('li.mailG table tr').hover(function() {
			$(this).addClass('current');
		}, function () {
			$(this).removeClass('current');
		});*/

		$('li.gadget a.minimizeButton').click(function minGadg() {
													   
			if ($.browser.msie && $.browser.version == 6) {
				$(this).parents('li.gadget').find('div.content').toggle();
				$(this).parents('li.gadget').find('div.footer').toggle();
			} else {
				$(this).parents('li.gadget').find('a.refresh').toggle();
				$(this).parents('li.gadget').find('div.content').slideToggle("slow");
				$(this).parents('li.gadget').find('div.footer').slideToggle("slow");
			}
			$(this).parents('li.gadget').toggleClass('minimized');

			var obj = $(this).parents('li.gadget').attr('id'),
				objC = $(this).parents('li.gadget').hasClass('minimized');
			
			$.cookie(obj, objC);

			return false;
		});

		/*$('div.todayWeather').each(function(){
			$(this).find('div.TabContent:first').show();
			$(this).find('ul.tabs li:first').addClass('selected');
		});*/
		$('div.todayWeather ul.tabs li').mouseenter(function(){
			$(this).parent().find('li').removeClass('selected');
			$(this).addClass('selected');
			var selTab = $(this).find('a').attr('href').replace('#', '');
			$(this).parents('div.todayWeather').find('div.TabContent').hide().filter('#'+selTab).show();
			return false;
		});

		$('div.FeaturedNews').each(function(){
			$(this).find('div.TabContent:first').show();
			$(this).find('ul.tabs li:first').addClass('selected');
		});
		$('div.FeaturedNews ul.tabs li').mouseenter(function(){
			$(this).parent().find('li').removeClass('selected');
			$(this).addClass('selected');
			
			if($(this).find('a').attr('rel'))
				var selTab = $(this).find('a').attr('rel').replace('#', '');
			else
				var selTab = $(this).find('a').attr('href').replace('#', '');
			
			$(this).parents('div.FeaturedNews').find('div.TabContent').hide().filter('#'+selTab).fadeIn();
			return false;
		});
/*
		$('div.FeaturedNews ul.tabs li').click(function(){
			return false;
		});
*/
		/*$('div.FeaturedNews').each(function(){
			$(this).find('div.FeaturedNewsItem:first').show();
			$(this).parents('#main').find('#hotNews_gadget li:first').addClass('selected');
		});*/
		
		/*$('div.NewsBlock, div.roundCornersBlock:not(.noscripts) span').each(function(){
			$(this).find('div.TabContent').hide().filter(':last').show();
			//$(this).find('ul.tabs li:last').addClass('selected');
			$(this).find('div.sizeButtons').show();
		});*/
		$('div.NewsBlock ul.tabs li, div.roundCornersBlock:not(.noscripts) span ul.tabs li').click(function(){
			$(this).parent().find('li').removeClass('selected');
			$(this).addClass('selected');
			var selTab = $(this).find('a').attr('href').replace('#', '');
			$(this).parents('div.content').find('div.TabContent').hide().filter('#'+selTab).show();
			return false;
		});

		$('div.roundCornersBlock:not(.noscripts)').each(function(){
			if($(this).hasClass("noevent"))
				return false;
			$(this).find('div.TabContent').hide().filter(':first').show();
			if(location.href.indexOf("passport.") == -1 && location.href.indexOf("games.") == -1)
				$(this).find('ul.tabs li:last').addClass('selected');
			$(this).find('div.sizeButtons').show();
		});

		$('div.roundCornersBlock:not(.noscripts) ul.tabs li').click(function(){
			if($(this).hasClass("noevent"))
				return;
			
			$(this).parent().find('li').removeClass('selected');
			$(this).addClass('selected');
			var selTab = $(this).find('a').attr('href').replace('#', '');
			$(this).parents('div.content').find('div.TabContent').hide().filter('#'+selTab).show();
			return false;
		});
		
		/*$('li.NewsBlock').each(function(){
			$(this).find('div.TabContent').hide().filter(':last').show();
			//$(this).find('ul.tabs li:last').addClass('selected');
			$(this).find('div.sizeButtons').show();
		});*/
		$('li.NewsBlock ul.tabs li').click(function(){
			$(this).parent().find('li').removeClass('selected');
			$(this).addClass('selected');
			var selTab = $(this).find('a').attr('href').replace('#', '');
			$(this).parents('div.content').find('div.TabContent').hide().filter('#'+selTab).show();
			return false;
		});
		
		/*$('div.search').each(function(){
			//$(this).find('ul.tabs li:first').addClass('selected');
		});*/
		$('div.search ul.tabs li').click(function(){
			$(this).parent().find('li').removeClass('selected');
			$(this).addClass('selected');
			return false;
		});
		
		$('div.search form input.textField').focus(function(){
			srchVal = $(this).val();
			if (srchVal == SrchCont) {
				$(this).val('');
			}
		}).blur(function(){
			srchVal = $(this).val();
			if (srchVal == '') {
				$(this).val(SrchCont);
			}
		});
		
		$("div.search form").submit(function(){
			var srchVal = $(this).find("input.textField").val();
			return (srchVal != SrchCont && srchVal) ? true : false;
		});
		
		
		$('#news_categories ul.tabs li').click(function() {
			_link = $(this).find('a').attr('href');
			location.replace(_link);
		});

/*		$('div.editProfile').each(function(){

			$(this).find('ul.tabs li:first').addClass('selected');
			$(this).find('div.TabContent').hide().filter(':first').show();

		});
		$('div.editProfile ul.tabs li').click(function(){
	//		$(this).parent().find('li').removeClass('selected');
	//		$(this).addClass('selected')
	//		selTab = $(this).find('a').attr('href').replace('#', '');
	//		$(this).parents('div.content').find('div.TabContent').hide().filter('#'+selTab).show();
		//	return false;
		});*/
		
		$('li.gadget').each(function(){
			//$(this).find('ul.tabs li:first').addClass('selected');
			i = 500;
			$(this).find('div.dropdown ul').each(function() {
				$(this).find('li').hide().filter(':first').show()
				$(this).parents('div.top').css('z-index',i);
				i = i-10;
			})
			$(this).find('div.selectBar ul').each(function() {
				$(this).find('li.selected').width($(this).find('a').width()+20);
				$(this).find('li').hide().filter(':first').show()
			})
			$(this).find('div.gadgetTab').hide().filter(':first').show();
		});
		$('li.gadget ul.tabs li').click(function(){
			$(this).parent().find('li').removeClass('selected');
			$(this).addClass('selected');
			var selTab = $(this).find('a').attr('href').replace('#', '');
			$(this).parents('div.content').find('div.gadgetTab').hide().filter('#'+selTab).show();
			return false;
		});
		
		var __prev = "";
		var __prev_search_city_field_tip = "";
		$('#search_city_field').focus(function() {
			if (__prev == "" && this.value.length > 10) {
				__prev_search_city_field_tip = this.value;
				this.value = "";
			}
		});
		
		$('#search_city_field').blur(function() {
			if (this.value == "") {
				this.value = __prev_search_city_field_tip;
			}
		});
		
		var __search_city_field_pos = -1;
		var __search_city_field_rows = 0;
		$('#search_city_field').keyup(function(e) {
			switch (e.which) {
				case 38:
					__search_city_field_pos--;
					if (__search_city_field_pos<0) {
						__search_city_field_pos = __search_city_field_rows-1;
					}
					break;
				case 40:
					__search_city_field_pos++;
					if (__search_city_field_pos>=__search_city_field_rows) {
						__search_city_field_pos = 0;
					}
					break;
				case 13:
					var url = $("div.cityField div.citiesList ul li:eq(" + __search_city_field_pos + ") a").attr("href");					
					if (url) {
						document.location.href = url;
						return;
					}
			}
			
			var name = this.value;
			if (__prev == name) {
				if (__search_city_field_pos>=0) {
					$("div.cityField div.citiesList ul li").removeClass("selected");
					$("div.cityField div.citiesList ul li:eq(" + __search_city_field_pos + ")").addClass("selected");
				}
				return;
			}
			__prev = name;
			$.getJSON(_WEATHER_URL + "async/search_city/?name=" + encodeURIComponent(name) + "&callback=?", function(data) {
				var html = "";
				__search_city_field_rows = data.length;
				$.each(data, function(i) {
					html+='<li style="width: 230px;"><a href="?ww_city=' + this.id + '">' + this.name + '</a></li>';
				});
				$("div.cityField div.citiesList").html("<ul>" + html + "</ul>");
				$("div.cityField div.citiesList").css("display", "block");
			});
		});
		
		$('#DropDownCitiesList a.close').click(function(){
			$(this).parents('#DropDownCitiesList').hide();
			__prev = "";
			$('#search_city_field').val(__prev_search_city_field_tip);
			$("div.cityField div.citiesList").css("display", "none");
			return false;
		});
		
		$('div.popup_container a.close').click(function(){
			$(this).parents('div.popup_container').hide();
			$('div.popup_overlay').hide();
			return false;
		});


		$('div.weather h1').each(function(){
			var titleWidth = 60+$(this).find('span').width();
			$(this).find('div.dropdown').css({'left':titleWidth})

			$(this).find('div.dropdown ul').each(function() {
				$(this).find('li').hide().filter(':first').show()
				$(this).parents('div.top').css('z-index',i);
				i = i-10;
			})
		});

		$('div.dropdown ul').click(function(){
			if($(this).hasClass("disable_old_events")) {
				return true;
			}
			$(this).toggleClass('active');
			$(this).find('li').toggle().filter(':first').show();
			$(this).parents('li.gadget').css('z-index','310');
			$(this).parents('li.gadget').next().css('z-index','300');
			return false;
		});
		
		$('div.dropdown ul').mouseleave(function(){
			if(!$(this).parent().hasClass("links")) {  
				$(this).removeClass('active');
				$(this).find('li').hide();
				if(!$(this).hasClass("disable_old_events")) {
					$(this).find('li').filter(':first').show();
				} else {
					$(this).find('li').filter('.selected').show();
				}
			}
		});
		
		$('div.selectBar ul').hover(
			function(){
				$(this).css('background-image', 'url(images/gadgets/btn_select_a.gif)');
			}, function(){
				$(this).css('background-image', 'url(images/gadgets/btn_select.gif)');
			}
		);
		
		$('div.selectBar ul').click(function(){
			$(this).toggleClass('active');
			$(this).find('li').toggle().filter(':first').show();
			$(this).parents('li.gadget').css('z-index','310');
			$(this).parents('li.gadget').next().css('z-index','300');
			
			return false;
		});
		$('div.selectBar ul').mouseleave(function(){
			$(this).removeClass('active');
			$(this).find('li').hide().filter(':first').show();
		});

/*
		$('div.newsFull div.options ul').each(function() {
			if ($.browser.safari) {
				$(this).width($(this).parent().width()+7);
			} else if ($.browser.msie) {
				$(this).width($(this).parent().width());
			} else if ($.browser.opera) {
				$(this).width($(this).parent().width());
			} else {
				$(this).width($(this).parent().width()+12);
			}
		})
*/

		/*$('div.search').each(function(){
			$(this).find('ul.tabs li:first').addClass('selected');
		});
		$('div.search ul.tabs li').click(function(){
			$(this).parent().find('li').removeClass('selected');
			$(this).addClass('selected')
			return false;
		});
		
		$('div.search form input.textField').focus(function(){
			srchVal = $(this).val();
			if (srchVal == SrchCont) {
				$(this).val('');
			}
		});
		$('div.search form input.textField').blur(function(){
			srchVal = $(this).val();
			if (srchVal == '') {
				$(this).val(SrchCont);
			}
		});*/

		$('div.comments form input.textfield').focus(function(){
			srchVal = $(this).val();
			if (srchVal == CommCont) {
				$(this).val('');
			}
		});
		$('div.comments form input.textfield:first').blur(function(){
			srchVal = $(this).val();
			if (srchVal == '') {
				$(this).val(CommCont);
			}
		});

		
		$('.hotNewsG li').click(function(){
			$(this).parent().find('li').removeClass('selected');
			$(this).addClass('selected');
			var selTab = $(this).attr('id').replace('#', '');
			$(this).parents('#main').find('div.FeaturedNewsItem').hide().filter('#'+selTab).show();
			return false;
		});

/*		$('div.advancedSearch').each(function(){
			//$(this).find('ul.tabs li:first').addClass('selected');
		});*/
		$('div.advancedSearch ul.tabs li').click(function(){
			$(this).parent().find('li').removeClass('selected');
			$(this).addClass('selected');
			return false;
		});


		$('div.select input').click(function(){
			$(this).parent().find('ul').toggle();
			$(this).parent().parent().find('div').css('z-index','100');
			$(this).parents('.gadgetTab').find('div').css('z-index','100');
			$(this).parents('table').find('div').css('z-index','100');
			$(this).parents('tr').next().find('div').css('z-index','100');
			$(this).parent().css('z-index','110');
			$(this).parents('li.gadget').css('z-index','310');
			$(this).parents('li.gadget').next().css('z-index','300');
		});
		$('div.select').mouseleave(function(){
			$(this).find('ul').hide();
		});
		$('div.select ul li').mouseenter(function(){
			$(this).addClass('current');
			if ($.browser.msie) {
				$(this).parent().animate({opacity: 1.0}, 50); 
			}
		});
		$('div.select ul li').mouseleave(function(){
			$(this).removeClass('current');
		});
		$('div.select ul li').click(function(){
			if ($(this).hasClass('disabledLI')) return false;
			$(this).parents('div.select').find('input:first').val($(this).text());
			$(this).parents('div.select').find('input:last').val($(this).attr('key'));
			$(this).parent().hide();
		});

		
		

function pause(ms)
{
var date = new Date();
var curDate = null;
do { curDate = new Date(); }
while(curDate-date < ms);
}
		/*$('span.dropdownMenuItem ul').each(function(){
			$(this).hide();
		});*/
	
/*		
		$('div.options a.remember').live('click',function(){
			$(this).parent().addClass('selected');
			return false;
		});
		$('div.options').mouseleave(function(){
			$(this).find('a.remember').parent().removeClass('selected');
		});
*/

		$('div.options span.icons a.remember').live('click',function(){
			$(this).next().slideDown('fast');
			$(this).parent().addClass('rem_active');
			return false;
		});
		$('div.options span.icons div ul').mouseleave(function(){
			$(this).parent().slideUp('fast');
			$(this).parent().parent().removeClass('rem_active');
		});


		$('div.popup_container a.minus').live('click', function(){
			$(this).parent().find('a.plus').next().show();
			$(this).parent().find('a.plus').removeClass('plus').addClass('minus');

			$(this).removeClass('minus').addClass('plus');
			$(this).next().hide();
			return false;
		});
		$('div.popup_container a.plus').live('click', function(){
			$(this).parent().find('a.minus').next().hide();
			$(this).parent().find('a.minus').removeClass('minus').addClass('plus');

			$(this).removeClass('plus').addClass('minus');
			$(this).next().show();
			return false;
		});

		$('div.popup_container a.close').click(function(){
			$(this).parents('div.popup_container').hide();
			$('div.popup_overlay').hide();
			return false;
		});
		$('#DropDownCitiesList a.close').click(function(){
			$(this).parents('#DropDownCitiesList').hide();
			return false;
		});

		$('div.comm_turner a').click(function() {
			if ( $(this).attr('class') != 'selected') {
				$(this).parent().next().toggle();
			}
			$(this).parent().find('a').removeClass('selected');
			$(this).addClass('selected');
			return false;
		});
		
		$('a.otherCityDropDown').click(function(){
			$('#DropDownCitiesList').toggle();
			return false;
		});
		
		$('div.borderBlock a.openButton').click(function(){
			$(this).parents('div.borderBlock').find('div.inner').toggle();
			$(this).toggleClass('openStatus');
			return false;
		});
		
		
	/*	$('a.keyboard').click(function(){
			$(this).toggleClass('opened');
			$(this).next().slideToggle('fast');
			return false;
		});*/

		
		/*
		
		
		$('div.DaySelector a.btn_next').click(function(){
			if ($('#NewsListDaySelector').css('left') < '-541px' || $('#NewsListDaySelector').css('left') == '0px'  || $('#NewsListDaySelector').css('left') == '-91px' ) {
				$('#NewsListDaySelector').animate({left: '-=182'}, 'slow');
				$(this).parent().find('a.notAblePrev').removeClass('notAblePrev');
				if ($('#NewsListDaySelector').css('left') == '-455px') {
					$(this).addClass('notAbleNext');
				}
			} else if ($('#NewsListDaySelector').css('left') < '-637px') {
				$('#NewsListDaySelector').animate({left: '-=91'}, 'slow');
				$(this).addClass('notAbleNext');
			};
			return false;
		});
		$('div.DaySelector a.btn_prev').click(function(){
			if ($('#NewsListDaySelector').css('left') < '-91px') {
				$('#NewsListDaySelector').animate({left: '+=182'}, 'slow');
				$(this).parent().find('a.notAbleNext').removeClass('notAbleNext');
				if ($('#NewsListDaySelector').css('left') == '-182px') {
					$(this).addClass('notAblePrev');
				}
			} else if ($('#NewsListDaySelector').css('left') < '-92px') {
				$('#NewsListDaySelector').animate({left: '+=91'}, 'slow');
					$(this).addClass('notAblePrev');
			};
			return false;
		});
*/
/*
		$('#tv_gadget a.btn_next').live('click',function(){
			var countLi = $(this).parent().find('.programms > li').size(),
				liHeight = 27,
				liPerTime = 4,
				maxTop = (countLi-(liPerTime+1))*-liHeight,
				itemX = $(this).parent().find('.programms'),
				itemTop = parseInt(itemX.css('top'));			
			if (itemTop > maxTop || itemTop == 0) {
				itemX.animate({top: '-='+liHeight*liPerTime}, 'slow');
			};
			return false;
		});
		$('#tv_gadget a.btn_prev').live('click',function(){
			var countLi = $(this).parent().find('.programms > li').size(),
				liHeight = 27,
				liPerTime = 4,
				maxTop = (countLi-(liPerTime+1))*-liHeight,
				itemX = $(this).parent().find('.programms'),
				itemTop = parseInt(itemX.css('top'));
			if (itemTop < 0) {
				itemX.animate({top: '+='+liHeight*liPerTime}, 'slow');
			};
			return false;
		});
*/
		$('#tv_gadget a.btn_prev').live('click', function(){return false;});
		$('#tv_gadget a.btn_next').live('mouseover',function(){
			var countLi = $(this).parent().find('.programms > li').size(),
				liHeight = 27,
				liPerTime = 4,
				speed = 160 * countLi,
				maxTop = (countLi-(liPerTime+1))*-liHeight,
				itemX = $(this).parent().find('.programms'),
				container = $(this).parent().find('.programms'),
				contHeight = parseInt(container.height()),
				itemTop = parseInt(itemX.css('top'));
			if (itemTop > maxTop || itemTop == 0) {
				itemX.animate({top: '-='+(contHeight+itemTop-liHeight*5)}, speed);
			};
			return false;
		});
		$('#tv_gadget a.btn_prev').live('mouseover',function(){
			var countLi = $(this).parent().find('.programms > li').size(),
				liHeight = 27,
				liPerTime = 4,
				speed = 120 * countLi,
				maxTop = (countLi-(liPerTime+1))*-liHeight,
				itemX = $(this).parent().find('.programms'),
				container = $(this).parent().find('.programms'),
				contHeight = parseInt(container.height()),
				itemTop = parseInt(itemX.css('top'));
			if (itemTop < 0) {
				itemX.animate({top: 0}, speed);
			};
			return false;
		});
		$('#tv_gadget a.btn_next, #tv_gadget a.btn_prev').live('mouseout', function(){
			$(this).parent().find('.programms').stop();
		});
		
		$('div.news #NewsListDaySelector').each(function(){
			items = $(this).find("li");
			for (i=1;i<items.size();i++) {
				if (items[i].className == 'selected') {
					var selNum = i+1;
					if (selNum < (items.size()-3)) {
						selScroll = -(selNum-4)*91;
					} else {
						selScroll = -(7)*91;
					};
					if (selNum > 3) {
						$('#NewsListDaySelector').animate({left: selScroll}, 'fast');
						$(this).parents('div.DaySelector').find('a.notAblePrev').removeClass('notAblePrev');
						if (selNum > 10) {
							$(this).parents('div.DaySelector').find('a.btn_next').addClass('notAbleNext');
						}
					}
				}
			}
		});

		$('#tv_gadget').find('ul li:gt(0)').live('click',function(){
			var curClass = $(this).attr('class').replace(/\s+\w+$/,'').substr(4);
			$('#tv_gadget .gadgetTab').find('.oneProgramm').each(function(){
				if ($(this).hasClass(curClass)) {
					$(this).addClass('sel_'+curClass);
				}
			});			
		});

		$('#tv_gadget').find('ul li:eq(0)').live('click',function(){
			var curClass = $(this).attr('class').replace(/\s+\w+$/,'').substr(4);
			$('#tv_gadget .gadgetTab').find('.oneProgramm').each(function(){
				$(this).attr('class', $(this).attr('class').replace(/sel_\w+$/, ''));
			});			
		});
		/*map widget*/
		
		$('#map_city').focus(function(){
			$(this).val('');
			$('#map_str').val('');
		});

		$('#map_str').focus(function(){
			$(this).val('');
		});
		
		/*map widget*/


		/*mail widget*/
		
		$('#mail_refresh').click(function(){
			$.post('/mainpage/mail_refresh', {}, function(data){
				$('#gadget1').find('table tr:gt(0)').remove();
				$('#gadget1').find('table').append(data);
			});
			return false;
		});
		
		
		$('a[id^=mail_subject]').live('mouseover',function(){
			var id = $(this).attr('id').replace('mail_subject','');
			$('#fullmail_'+id).show('fast');
		}).live('mouseout',function(){
			var id = $(this).attr('id').replace('mail_subject','');
			$('#fullmail_'+id).hide('fast');
		});
		
		/*mail widget*/
		
		$('#main div.GalleryBigImg').find('a.imageCont_wBG, a.btn_prev, a.btn_next').mouseover(function(){
			$(this).parent().find('a.btn_prev, a.btn_next').show();
		})
		$('#main div.GalleryBigImg').find('a.imageCont_wBG, a.btn_prev, a.btn_next').mouseout(function(){
			$(this).parent().find('a.btn_prev, a.btn_next').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(''));

}();

var minimizeTab = function(id){
	if ($.browser.msie && $.browser.version == 6) {
		$('#'+id+' .sizeButtons .minimize').hide();$('#'+id+' .sizeButtons .maximize').hide();
	};
	$('#'+id+' div.content').find('.TabContent').each(function(i){
		$('#'+id+' div.content #tab-1'+(i+1)+' ul li:eq(9), #'+id+' div.content #tab-1'+(i+1)+' ul li:eq(8)').hide();
		$('#'+id+' div.content #tab-1'+(i+1)+' .topNew span').hide();
	});
	$('#'+id+' .sizeButtons .minimize').css('background-position', '0 100%');
	$('#'+id+' .sizeButtons .maximize').css('background-position', '100% 0');
	if ($.browser.msie && $.browser.version == 6) {
		function ttt2() {$('#'+id+' .sizeButtons .minimize').show();$('#'+id+' .sizeButtons .maximize').show();}
		setTimeout(ttt2,200)
	};
}
var maximizeTab = function(id){
	if ($.browser.msie && $.browser.version == 6) {
		$('#'+id+' .sizeButtons .minimize').hide();$('#'+id+' .sizeButtons .maximize').hide();
	};
	$('#'+id+' div.content').find('.TabContent').each(function(i){
		$('#'+id+' div.content #tab-1'+(i+1)+' ul li:eq(9), #'+id+' div.content #tab-1'+(i+1)+' ul li:eq(8)').show();
		$('#'+id+' div.content #tab-1'+(i+1)+' .topNew span').show();
	});
	$('#'+id+' .sizeButtons .minimize').css('background-position', '100% 0');
	$('#'+id+' .sizeButtons .maximize').css('background-position', '0 100%');		
	if ($.browser.msie && $.browser.version == 6) {
		function ttt2() {$('#'+id+' .sizeButtons .minimize').show();$('#'+id+' .sizeButtons .maximize').show();}
		setTimeout(ttt2,200)
	};
}




/*var showFullMessage = function(id){
	$('div[id=^fullmail]').hide();
	var mesNumber = id.replace('fullmail_', '');
	$.post('/mainpage/getfulltext/'+mesNumber, {}, function(data){
		$('#body_'+mesNumber).empty().append(data);
		$('#fullmail_'+mesNumber).show('fast');
	});
}*/