//	Набор скриптов для сайта
//	
//	Использует:
//	jquery.js
//
////////////////////////////////////////////////

// jQuery.noConflict();

(function($) {

	function InitSite()
	{
		InitCorners();
		InitSearch();
		InitQuestions();
		InitSpoilers();
		InitTopMenu();
		InitFlash();
	}
	
	function InitCorners()
	{
		if($(".more").length > 0)
			$(".more").corner("4px");
		
		if($("#content table thead th div").length > 0)
		{
			$("#content table thead").each(function(i){
				$("#content table thead:eq("+ i +") div").wrap('<div class="wrap"></div>');
				$("#content table thead:eq("+ i +") div:first div").addClass("lu");
				$("#content table thead:eq("+ i +") div:last").addClass("ru");
				$("#content table thead:eq("+ i +") .wrap:first").addClass("ld");
				$("#content table thead:eq("+ i +") .wrap:last").addClass("rd");
			})
		}
	}

	function InitSearch()
	{
		if($(".search_field").length > 0)
		{
			if($(".search_field").val() !== "Поиск")
				$(".search_field").removeClass("unactive");
			
			
			$(".search_field").focus(function(){
				if($(this).val() == "Поиск" && $(this).hasClass("unactive"))
				{
					$(this).val("").removeClass("unactive");
				}
			});
			
			$(".search_field").blur(function(){
				if($(this).val() == "")
				{
					$(this).val("Поиск").addClass("unactive");
				}
			});
			
			$("#find_btn").click(function(){
				$("#ajaxSearch_form").submit();
			});
		}
	}
	
	function InitQuestions()
	{
		if($("#question_form").length > 0 && $("#askquestion").length > 0)
		{
			$("#askquestion").toggle(
				function(){ $("#question_form").slideDown("fast", function(){ $("#question_form input[type='text']:eq(0)").focus(); }); },
				function(){ $("#question_form").slideUp("fast"); }
			);
		}
	}
	
	function InitSpoilers()
	{
		if($(".spoiler").length > 0)
		{
			$(".spoiler dt").toggle(
				function(){ $(this).next().slideDown("fast"); },
				function(){  $(this).next().slideUp("fast"); }
			);
		}
	}
	
	function InitTopMenu()
	{
		$("#top_menu ul:eq(0) li").hover(
			function()
			{
				var i = $("#top_menu ul:eq(0) li").index(this);
				$(this).children("ul").fadeIn("fast");
			},
			function()
			{
				var i = $("#top_menu ul:eq(0) li").index(this);
				$(this).children("ul").fadeOut("fast");
			}
		);
	}
	
	function InitFlash()
	{
		if($("#banner20").length > 0)
		{
			$("#banner20").flash({
				src:	'/assets/templates/ultramed/fla/banner.swf',
				width: 	304,
				height: 434
			});
		}
	}
	
////////////////////////////////////////////////////////////////////////////////
	$(document).ready( function(){ InitSite(); });
})(jQuery);
