
// Кнопка "Подать заявку"
$(document).ready(function(){
	var btn = $('.b-header .menu A.add-request');
	btn.mousedown(function(){ $(this).css('background-position', '0 -82px'); });
	btn.mouseup(function(){ $(this).css('background-position', '0 -41px'); });
	btn.hover(
		function(){ $(this).css('background-position', '0 -41px'); },
		function(){ $(this).css('background-position', '0 0'); }
	);
});


/* Экспертное мнение */
$(document).ready(function(){
	
	
	// Выбор мнения
    $('.b-header .opinion .tabs A').click(function(){
		$('.b-header .opinion .tabs .cur').stop().animate({
			'left': ($(this).position().left-4)+'px'
		}, 600);
		var forShow = $(this).parent().attr('data-id');
		$('.b-header .opinion .body').stop(true, true).fadeOut(400, function(){
			$('.b-header .opinion .body LI').removeClass('cur');
			$('.b-header .opinion .body LI[data-id='+forShow+']').addClass('cur');
			$('.b-header .opinion .body').fadeIn(400);			
		});
		return false;
	});
	
	
	// Убрать рамку вокруг картинки (для IE8)
	$('.b-header .opinion .tabs A').focus(function(){
		$(this).blur();
	});	
	
	
    // Инициализация
	var i = 0;
    $('.b-header .opinion .tabs LI').each(function(){
		i++;
		$(this).attr('data-id', 'm-'+i);
	});
	i = 0;
    $('.b-header .opinion .body LI').each(function(){
		i++;
		$(this).attr('data-id', 'm-'+i);
	});
	$('.b-header .opinion .tabs .cur').show();
	$('.b-header .opinion .body .m-1').show();
		
	
});


/* Номинации */
$(document).ready(function(){
	
	
	// Выбор элемента меню
/*    $('.b-nominations .menu A').click(function(){
		$('.b-nominations .menu LI').removeClass('cur');
		$(this).parent().addClass('cur');
		$('.b-nominations .tab').hide();
		$('.b-nominations .'+$(this).attr('data-id')).show();
		return false;
	});*/
	
	
	// Убрать рамку вокруг элемента меню (для IE8)
	$('.b-nominations .menu A').focus(function(){
		$(this).blur();
	});	
	$('.b-nominations .tbl-menu A').focus(function(){
		$(this).blur();
	});
	$('.b-nominations .view A').focus(function(){
		$(this).blur();
	});
	
	// Синхронная подсветка ссылок
	$('.b-nominations .sites A').hover(
		function(){ $('A', $(this).parent().parent()).addClass('hover'); },
		function(){ $('A', $(this).parent().parent()).removeClass('hover'); }
	);
	
	
	// Таблица - подсветка строк
	$('.b-nominations .tbl TD').hover(
		function() {
			$(this).parent().addClass('hover');
		},
		function() {
			$(this).parent().removeClass('hover');
		}
	);
	
	
	// Функция сортировки таблицы
	function nominationsTableSort(table, type) {
		
		var rows = new Array();
		var n = -1;
		$('.item', table).each(function(){
			n++;
			rows[n] = new Array();
			rows[n]['html'] = $(this).html();
			rows[n]['count'] = $('.'+type, $(this)).attr('data-count')*1;
		});
		
		rows.sort(function(i, ii) {
			if (i['count'] > ii['count'])
				return -1;
			else if (i['count'] < ii['count'])
				return 1;
			else
				return 0;
		});
		
		var i = -1;
		$('.item', table).each(function(){
			i++;
			$(this).html(rows[i]['html']);
			$('.pos', this).html(i+2);
		});
		
	}
	
	
	// Сортировка таблицы по ходу экспертного голосования
	$('.b-nominations .tbl-menu .experts').click(function(){
		
		$(this).parent().prev().removeClass('cur');
		$(this).parent().addClass('cur');
		
		nominationsTableSort($(this).parent().parent().next(), 'experts');
		
		$('.voting_key').unbind();
		$('.voting_key').click(function(){
			$('#captcha .site_id').val($(this).attr('num'));
			showCaptcha();
		});
		return false;
	});
	
	
	// Сортировка таблицы по рейтингу интернет голосования
	$('.b-nominations .tbl-menu .users').click(function(){
		
		$(this).parent().next().removeClass('cur');
		$(this).parent().addClass('cur');
		
		nominationsTableSort($(this).parent().parent().next(), 'votes');
		
		$('.voting_key').unbind();
		$('.voting_key').click(function(){
			$('#captcha .site_id').val($(this).attr('num'));
			showCaptcha();
		});

		return false;
	});
	
	
	// Включить просмотр скриншотами
	$('.b-nominations .view .ss').click(function(){
		$('.b-nominations .tbl-wrap').hide();
		$('.b-nominations .sites').show();
		$(this).parent().addClass('cur');
		$(this).parent().next().removeClass('cur');

		return false;
	});
	
	
	// Включить просмотр таблицами
	$('.b-nominations .view .tbl').click(function(){
		$('.b-nominations .tbl-wrap').show();
		$('.b-nominations .sites').hide();
		$(this).parent().addClass('cur');
		$(this).parent().prev().removeClass('cur');
		$('.b-nominations .tbl-menu .users').click();		
		
		return false;
	});
	
	
	// Инициализация
	var i = 0;
    $('.b-nominations .tab').each(function(){
		i++;
		$(this).addClass('tab-'+i);
	});
	i = 0;
    $('.b-nominations .menu A').each(function(){
		i++;
		$(this).attr('data-id', 'tab-'+i);
	});
	
	
});


/* Форма регистрации */
$(document).ready(function(){
	
	
	// Выбор номинации
	$('.b-reg .nomination SELECT').change(function(){
		$('.b-reg .nomination-info LI').removeClass('cur');
		$('.b-reg .nomination-info LI[data-id='+$('.b-reg .nomination OPTION:selected').attr('data-id')+']').addClass('cur');
	});
	
	
	// Инициализация выбора номинации
	var i = 0;
	$('.b-reg .nomination OPTION').each(function(){
		i++;
		$(this).attr('data-id', 'i'+i);
	});
	var i = 0;
	$('.b-reg .nomination-info LI').each(function(){
		i++;
		$(this).attr('data-id', 'i'+i);
	});
	$('.b-reg .nomination SELECT').change();
	
	
	// Включение необходимых вариантов выбора CMS
	function RegForm_SelectCMS_change() {
		$('.b-reg .select-cms SELECT').attr('disabled', 'disabled');
		$('.b-reg .select-cms INPUT').hide();
		if ( $('#cms-other').attr('checked') ) {
			$('.b-reg .select-cms SELECT').attr('disabled', '');
			if ( $('.b-reg .select-cms .my:selected').length ) {
				$('.b-reg .select-cms INPUT').show();
			}
		}
	}
	
	
	// Выбор CMS
	$('.b-reg .cms .radio INPUT').change(function(){
		RegForm_SelectCMS_change();
		if ( $('.b-reg .select-cms INPUT').css('display')!='none' ) {
			$('.b-reg .select-cms INPUT').focus();
		}
	});
	$('.b-reg .select-cms SELECT').change(function(){
		RegForm_SelectCMS_change();
		if ( $('.b-reg .select-cms INPUT').css('display')!='none' ) {
			$('.b-reg .select-cms INPUT').focus();
		}
	});
	
	
	// Инициализация выбора CMS
	RegForm_SelectCMS_change();
	
	
});


/* Фотогалерея */
/*$(document).ready(function(){
	
	// Инициализация
	$('.b-award .gallery .i').lightBox({
		imageBlank: 'images/blank.gif',
		imageLoading: 'images/lightbox-ico-loading.gif',
		imageBtnClose: 'images/lightbox-btn-close.gif',
		imageBtnPrev: 'images/lightbox-btn-prev.gif',
		imageBtnNext: 'images/lightbox-btn-next.gif'
	});
	
});*/

//Счет оставшихся символов
$(document).ready(function(){
	$('#desc').keyup(function(){
		var count = $(this).val();
		count = count.length;
		var string = $('#desc').val();
		var c = 500 - count;
		if(500-count<0){
			$('#desc').val(string.substr(0, 500));
			c = 0;
		}
		$('#counter').html(c);
	});
});

// Очистка формы
$(document).ready(function(){
	$('.to_clear').click(function(){
		if($(this).val()=="Ваше ФИО" || $(this).val()=="Укажите телефон или E-mail")
			$(this).val('');
	});
});

//-------------------//
//overall functions //

var ua = navigator.userAgent.toLowerCase();
var isOpera = (ua.indexOf('opera')  > -1);
var isIE = (!isOpera && ua.indexOf('msie') > -1);

function gDH() {
	return Math.max(document.compatMode != 'CSS1Compat' ? document.body.scrollHeight : document.documentElement.scrollHeight, gVH());
}
function gDW() {
	return Math.max(document.compatMode != 'CSS1Compat' ? document.body.scrollWidth : document.documentElement.scrollWidth, gVW());
}
function gVH() {
	return ((document.compatMode || isIE) && !isOpera) ? (document.compatMode == 'CSS1Compat') ? document.documentElement.clientHeight : document.body.clientHeight : (document.parentWindow || document.defaultView).innerHeight;
}
function gVW() {
	return ((document.compatMode || isIE) && !isOpera) ? (document.compatMode == 'CSS1Compat') ? document.documentElement.clientWidth : document.body.clientWidth : (document.parentWindow || document.defaultView).innerWidth;
}

function ShowOverAll() {
	$(".b-overall").css("height", (gDH()));
	$(".b-overall").css("width", (gDW()));
	$(".b-overall IFRAME").css("height", (gDH()));
	$(".b-overall IFRAME").css("width", (gDW()));
	$(window).resize(function(){
		$(".b-overall").css("height", (gDH()));
		$(".b-overall").css("width", (gDW()));
		$(".b-overall IFRAME").css("height", (gDH()));
		$(".b-overall IFRAME").css("width", (gDW()));
	});
	$(".b-overall").show();
}

function HideOverAll() {
	$(".b-overall").hide();
}

//overall functions //
//-------------------//
