$(function() {
	// Плейсхолдеры в полях логина и пароля
	var userEmailPlaceholder = $("#UserEmail").attr("placeholder");
	var userPasswordPlaceholder = $("#UserPassword").attr("placeholder");
	
	SetInputPlaceholder("UserEmail", userEmailPlaceholder);
	SetInputPlaceholder("UserPassword", userPasswordPlaceholder);
	
	HideHeaderMatches();
	
	// Скрытие/Отображение матчей в шапке
	$("a.dev-show-hide").click(function() {
		if ($(".table").attr("status") == "0")
			ShowHeaderMatches();
		else
			HideHeaderMatches();
	});
	
	// Видео-лента. Прокрутка вверх/вниз
	$(".top_image").click(function() {
		VideoScrollPrev();
	});
	$(".bottom_image").click(function() {
		VideoScrollNext();
	});
});

function SetInputPlaceholder(fieldId, placeholder)
{
	var fieldType = $("#"+fieldId).attr("type");
	var fieldName = $("#"+fieldId).attr("name");

	if (fieldType == "password") 
	{
		var textFieldHtml = "<input type='text' id='" + fieldId + "' name='" + fieldName + "' />";
		$("#"+fieldId).replaceWith(textFieldHtml);	
		$("#"+fieldId).val(placeholder);
	}
	else
	{
		$("#"+fieldId).val(placeholder);	
	}
	InitInputEvents(fieldId, placeholder, fieldType, fieldName);
}

var CHANGED = false;

function InitInputEvents(fieldId, placeholder, fieldType, fieldName)
{
	$("#"+fieldId).focus(function() {
		if ($(this).val() == placeholder)
		{
			$(this).val("");
		
			if (fieldType == "password")
			{
				var textFieldHtml = "<input type='password' id='" + fieldId + "' name='" + fieldName + "' />";
				$("#"+fieldId).replaceWith(textFieldHtml);
				InitInputEvents(fieldId, placeholder, fieldType, fieldName);
				CHANGED = true;
				$("#"+fieldId).focus();
			}
		}
	});
	$("#"+fieldId).blur(function() {
		if ($(this).val() == "")
		{
			$(this).val(placeholder);

			if (fieldType == "password") 
			{
				var textFieldHtml = "<input value='" + placeholder + "' type='text' id='" + fieldId + "' name='" + fieldName + "' />";
				$("#"+fieldId).replaceWith(textFieldHtml);	
				InitInputEvents(fieldId, placeholder, fieldType, fieldName);
			}
		}
	});
}



// Скрытие матчей чемпионата нац. дивизии в шапке.
function HideHeaderMatches()
{
	$(".table ul.result").each(function() {
		$(this).find("li:gt(1)").hide();
	});
	$("a.dev-show-hide:first").show();
	$("a.dev-show-hide:last").hide();
	$(".table").attr("status", "0");
}

// Отображение матчей чемпионата нац. дивизии в шапке.
function ShowHeaderMatches()
{
	$(".table ul.result").each(function() {
		$(this).find("li:gt(1)").show();
	});
	$("a.dev-show-hide:first").hide();
	$("a.dev-show-hide:last").show();
	$(".table").attr("status", "1");
}


function VideoScrollNext()
{
	$(".video_archive div:first").insertAfter(".video_archive div:last").hide();
	$(".video_archive div:eq(0)").attr("class", "small_img");
	$(".video_archive div:eq(1)").attr("class", "medium_img");
	$(".video_archive div:eq(2)").attr("class", "big_img");
	$(".video_archive div:eq(3)").attr("class", "medium_img_bot");
	$(".video_archive div:gt(3)").attr("class", "small_img_bot");
	if ($(".video_archive div").length > 4)
		$(".video_archive div:eq(4)").show();
	else
		$(".video_archive div:last").show();
}

function VideoScrollPrev()
{
	$(".video_archive div:last").insertBefore(".video_archive div:first").show();
	$(".video_archive div:eq(0)").attr("class", "small_img");
	$(".video_archive div:eq(1)").attr("class", "medium_img");
	$(".video_archive div:eq(2)").attr("class", "big_img");
	$(".video_archive div:eq(3)").attr("class", "medium_img_bot");
	$(".video_archive div:gt(3)").attr("class", "small_img_bot");
	$(".video_archive div:eq(5)").hide();
}





