var breaking_letter_timer = null
function breaking_type_letter(n, offset) {
	var l = $("#superBreakingString h2:eq(" + n + ")").data("txt").slice(offset++, offset)
	$("#superBreakingString h2:eq(" + n + ") a").text($("#superBreakingString h2:eq(" + n + ")").text() + l)

	if (offset < $("#superBreakingString h2:eq(" + n + ")").data("txt").length) {
		window.clearTimeout(breaking_letter_timer)
		breaking_letter_timer = window.setTimeout("breaking_type_letter('" + n + "', '" + offset + "')", 80)
	} else {
		/* n++
		if (n + 1 > $("#superBreakingString h2").size()) {
			n = 0
		} */
		breaking_text_timer = window.setTimeout("breaking_type_text('" + n + "')", 2000)
	}
}

var breaking_text_timer = null
function breaking_type_text(n) {
	window.clearTimeout(breaking_letter_timer)
	window.clearTimeout(breaking_text_timer)
	breaking_letter_timer = breaking_text_timer = null

	if ($("#superBreakingString h2.active").size()) {
		$("#superBreakingString h2.active").fadeTo(300, 0)
	}
	window.setTimeout(function() {
		/*if (!$("#superBreakingString h2:eq(" + n + ")").data("txt")) {
			$("#superBreakingString h2:eq(" + n + ")").attr({
				"data-txt" : $("#superBreakingString h2:eq(" + n + ") a").text()
				// "data-link" : $("#superBreakingString h2:eq(" + n + ") a").attr("href")
			});
		}*/

		$("#superBreakingString h2").removeClass("active")
		$("#superBreakingString h4").removeClass("express").removeClass("exclusive").addClass($("#superBreakingString h2:eq(" + n + ")")[0].className).text($("#superBreakingString h2:eq(" + n + ")").data("label"))
		$("#superBreakingString h2:eq(" + n + ") a").empty()
		$("#superBreakingString h2:eq(" + n + ")").fadeTo(1, 1).addClass("active")

		$("#brstr_btn_prev").removeClass("disable");
		$("#brstr_btn_next").removeClass("disable");
		if (n == 0) {
			$("#brstr_btn_prev").addClass("disable");
		}
		if (n == $("#superBreakingString h2").size() - 1) {
			$("#brstr_btn_next").addClass("disable");
		}

		breaking_type_letter(n, 0)
	}, 500)
}

function breaking_over(e) {
	window.clearTimeout(breaking_text_timer)
	breaking_text_timer = null

	window.clearTimeout(breaking_letter_timer)
	breaking_letter_timer = null

	$("#superBreakingString h2.active a").text($("#superBreakingString h2.active"))
	e.stopPropogation()
}
function breaking_out() {
	breaking_type_text($("#superBreakingString h2").index($("#superBreakingString h2.active")))
	e.stopPropogation()
}

function hot_action() {
	var animblock_w = $("#topStoryAnimation:eq(0)").width(),
		animblock_class = $("#topStoryAnimation:eq(0)")[0].className
	$("#topStoryAnimation:eq(0) div").width(animblock_w)

	$("#top_story_title").fadeTo(300,0, function() {
		$("#topStoryAnimation").css({
			"width" : "10px",
			"left" : "975px"
		}).show()

		$("#topStoryAnimation:eq(0)").animate({
			"left" : "11px"
		}, 300, function() {
			$("#topStoryAnimation:eq(0)").animate({
				"width" : animblock_w + "px"
			}, 300, function() {
				window.setTimeout(function() {
					$("#topStoryAnimation:eq(0)")[0].className = "animblock_none"
					window.setTimeout(function() {
						$("#topStoryAnimation:eq(0)")[0].className = animblock_class
						window.setTimeout(function() {
							$("#topStoryAnimation:eq(0)").animate({
								"left" : (animblock_w + 11) + "px",
								"width" : "0"
							}, 300, function() {
								$("#topStoryAnimation:eq(0)").hide()
								$("#top_story_title").fadeTo(300,1)
							})
						}, 300)
					}, 300)
				}, 300)
			})
		})
	})
}

function innerhots_action() {
	var animblock_w = $("#innerHotsAnimation").width()
	$("#innerHotsAnimation div").width(animblock_w)

	$("#inner_hots_block").fadeTo(300,0, function() {
		$("#innerHotsAnimation").css({
			"width" : "10px",
			"left" : "515px"
		}).show()

		$("#innerHotsAnimation").animate({
			"left" : "0"
		}, 300, function() {
			$("#innerHotsAnimation").animate({
				"width" : animblock_w + "px"
			}, 300, function() {
				window.setTimeout(function() {
					$("#innerHotsAnimation").animate({
						"left" : (animblock_w) + "px",
						"width" : "0"
					}, 300, function() {
						$("#innerHotsAnimation").hide()
						$("#inner_hots_block").fadeTo(300,1)
					})
				}, 700)
			})
		})
	})
}

function widget_gallery() {
	$(".widget_gallery li img").mouseover(function() {
		$(this).parents("ul").find("img").stop().not(this).fadeTo(500, 0.6)
		$(this).fadeTo(500, 1)
	}).mouseout(function() {
		$(this).parents("ul").find("img").stop().fadeTo(500, 1)
	})
}

var mainhots_hide_timer = null;

$(function() {
	if ($("#superBreakingString").size()) {
		// убираем "последние новости"
		window.setTimeout(function() {
			$("#superBreakingString h4").animate({"width" : "230px"}, 500)
		}, 1500)

		// начинаем писать текст
		breaking_text_timer = window.setTimeout(function() {
			breaking_type_text(0)
		}, 2000)

		$("#brstr_btn_prev").click(function() {
			if ($(this).hasClass("disable")) { return; }
			var n = $("#superBreakingString h2").index($("#superBreakingString h2.active")) || 0
			n--
			if (n < 0) {
				n = $("#superBreakingString h2").size() - 1
			}
			breaking_type_text(n)
		})
		$("#brstr_btn_next").click(function() {
			if ($(this).hasClass("disable")) { return; }
			var n = $("#superBreakingString h2").index($("#superBreakingString h2.active")) || 0
			n++
			if (n + 1 > $("#superBreakingString h2").size()) {
				n = 0
			}
			breaking_type_text(n)
		})

		// $("#superBreakingString").mouseover(breaking_over).mouseout(breaking_out)

	}

	if ($("#topStoryAnimation").size()) {
		hot_action()
	}
	if ($("#innerHotsAnimation").size()) {
		innerhots_action()
	}
	widget_gallery()

	// переключение хотов
	/* if ($("#sbTitleBody").size()) {
		$("#sbFooter ul li").mouseover(function() {
			window.clearTimeout(mainhots_hide_timer)

			$(".mainhots_block").hide()
			$(".mainhots_block:eq(" + ($("#sbFooter ul li").index(this) + 1) + ")").show()
		})
		$(".mainhots_block").mouseover(function() {
			window.clearTimeout(mainhots_hide_timer)
		})

		$("#sbFooter ul li, .mainhots_block").mouseout(function() {
			window.clearTimeout(mainhots_hide_timer)

			// начинаем писать текст
			mainhots_hide_timer = window.setTimeout(function() {
				$(".mainhots_block").hide()
				$(".mainhots_block:eq(0)").show()
			}, 1000)
		})

	} */
})



