﻿$(document).ready(function(){

	if($.browser.msie && $.browser.version < 7){
		$('<div class="ie6-sux">Уважаемый посетитель! Ваш браузер <b>Internet Explorer 6 технически и морально устарел</b>! Эту версию уже даже не поддерживает её создатель - компания Microsoft. Пожалуйста <a href="http://ie.yandex.ru">обновите браузер на новую версию</a>!</div>').prependTo('.wrap');
	}

	$('.cat-thumbs')
	.hide()
	.append($('.cat > ul > li:first > ul:first').clone())
	.fadeIn(300, function(){
		if($.browser.msie) $(this).removeAttr('style');
	});
	
	$('.main-content').css({'font-size': '1'+'1'+'p'+'x'});
	
	$('.cat > ul > li:last').css({'margin-bottom': '0'});
	$('.summary-content div:last').css({'margin-right': '0'});
	
	$('.reg')
	.hover(
		function(){ $(this).addClass('reg-hover'); },
		function(){ $(this).removeClass('reg-hover'); }
	)
	.mousedown(
		function(){ $(this).addClass('reg-mousedown'); }
	)
	.mouseup(
		function(){ $(this).removeClass('reg-mousedown'); }
	)
	.click(
		function(){ window.location = '/partners/register/'; }
	);

	$('.btn-search')
	.hover(
		function(){ $(this).addClass('btn-search-hover'); },
		function(){ $(this).removeClass('btn-search-hover'); }
	)
	.mousedown(
		function(){ $(this).addClass('btn-search-mousedown'); }
	)
	.mouseup(
		function(){ $(this).removeClass('btn-search-mousedown'); }
	)
	.click(
		function(){ $(this).parent().submit(); }
	)

	var t;
	
	function setLiActive(li){
		$('.cat > ul > li').removeClass('active hover');
		li.addClass('active');
		$('.cat-thumbs')
		.html('')
		.hide()
		.append(li.find('ul:first').clone())
		.fadeIn(300, function(){
			if($.browser.msie) $(this).removeAttr('style');
		});
	}
	
	$('.cat > ul > li')
	.mouseenter(function(){
		if($(this).hasClass('active')) return;
		$(this).addClass('hover');
		var li = $(this);
		t = setTimeout(function(){ setLiActive(li); }, 500);
	})
	.mouseleave(function(){
		if($(this).hasClass('active')) return;
		$(this).removeClass('hover');
		if(t) clearTimeout(t);
	})
	.click(function(){
		if($(this).hasClass('active')) return;
		if(t) clearTimeout(t);
		setLiActive($(this));
	})
	$('.cat > ul > li:first').addClass('active');
	
	
	$('.cat-thumbs > ul > li').live({
		'mouseenter': function(){ $(this).addClass('hover'); },
		'mouseleave': function(){ $(this).removeClass('hover'); },
		'click': function(){ window.location = $(this).find('a').attr('href'); }
	});

	$('.form-search input[name=text]')
	.focusin(
		function(){
			$(this).addClass('focused').animate({width: '258px'}, 200);
			if($(this).val() == 'Поиск по сайту') $(this).val('');
		}
	)
	.focusout(
		function(){
			$(this).removeClass('focused').animate({width: '95px'}, 200);
			if($(this).val() == '') $(this).val('Поиск по сайту');
		}
	)
	if($.browser.webkit) $('.form-search .btn-search').css('top','2px');
	
	$('.form-search').submit(function(){
		var q = $(this).find('input[name=text]').val();
		if(q == 'Поиск по сайту' || q == '') return false;
	});
	
	var share = $('#share');
	share.css({left: screen.width/2 - share.outerWidth()/2+'px'});
	
});
