﻿//анимация текста к программам
var jqueryslidemenu = {
	animateduration: {over: 300, out: 200}, //duration of slide in/ out animation, in milliseconds
	buildmenu:       function(){

		var selector = "#program_today li p:gt(0), #program_tomorrow li p";
		var $mainmenu=$(selector);
		var $headers=$mainmenu.parent();
		$headers.each(function(i){
			var $curobj=$(this);
			var $subul=$(this).find(selector);
			$curobj.hover(
				function(e){
					var $targetul=$(this).children(selector);
					$(this).css("height","91px");
					$targetul.slideDown(jqueryslidemenu.animateduration.over);
				},
				function(e){
					var $targetul=$(this).children(selector);
					if(!detectIE(6) && !detectIE(7))
					{
						$targetul.stop(true,true).slideUp(jqueryslidemenu.animateduration.out);
						$(this).animate({"height": 21}, 200);
					}
					else
					{
						$targetul.stop(true,true).hide();
						$(this).animate({"height": 21}, 200);
					}
				}
			); //end hover
		}); //end $headers.each()
		$mainmenu.find(selector).css({display:"none", visibility:"visible"});
		
		$("#program_today li p:eq(0)").css("display", "block")
			.parent().css("height", "91px");
	}
};

//******************************//
function detectIE(ver)
{
	var browser = navigator.appName;
	if (browser == "Microsoft Internet Explorer")
	{
		var b_version = navigator.appVersion;
		var re = /\MSIE\s+(\d\.\d\b)/;
		var res = b_version.match(re);
		if (res[1] <= 6 && ver == 6){
			return true;
		}
		else if(res[1] == 7.0 && ver == 7){
			return true;
		}
	}
	return false;
}

var tabs_options = {initialIndex: 0, tabs: 'li', effect: 'fade'};

$(document).ready(function()
{
	(function(){
		$(".menu-main")
			.find(".submenu").css("display", "none")
		.end()
			.children("li")
				.mouseenter(function(){
					$("> .submenu", this)
						.stop(true,false)
						.slideDown(300, function(){$(this).removeAttr("style").css({"display" : "block"});});
				})
				.mouseleave(function(){
					$("> .submenu", this)
						.stop(true,false)
						.slideUp(200, function(){$(this).removeAttr("style").css({"display" : "none"});});
				})
			;
	})();
	
	
	$("#right ul.tabs").tabs("#right div.panes > .pane", tabs_options);

	$('#program_today, #program_tomorrow').show();
	$('#header .not-init-jcarousel').removeClass("not-init-jcarousel");
	$('#header .program-jcarousel').jcarousel({
	//	wrap: 'circular',
		scroll: 1
	});
	$('#program_tomorrow').hide();

	//build menu on page:
	jqueryslidemenu.buildmenu();

	//$(".carousel-programm li").css("position", "relative");
	$("<span></span>").insertAfter(".now p");

	$("#header p.air_links a").click(function(){
		var $a = $(this);

		if ($a.hasClass("active")) return false;

		var $other_a = $a.parent().find("a.active");
		$other_a.removeClass("active");

		$("#program_"+$other_a.attr("rel")).hide();
		$("#program_"+$a.attr("rel")).show();

		$a.addClass("active");

		return false;
	});

	$(".add-message-form").hide();
	$(".add-message-link").click(function(){
		var $form = $(".add-message-form");
		var $parent = $(this).parent();
		$form.stop(true,true);
		if ($parent.next(".add-message-form").length === 0)
		{
			$form.removeClass("is-visible").hide().insertAfter($parent);
		}
		if ($form.hasClass("is-visible"))
		{
			$form.slideUp().removeClass("is-visible");
		}
		else
		{
			$form.slideDown().addClass("is-visible");
		}
		return false;
	});
	
});
