//custom js jq effects

var $jq = jQuery.noConflict();

var $current_animal_active = '';

$jq(document).ready(function(){
	
	if ($jq('.current_animal').length)
	{
		var temp_animal = $jq('.current_animal').attr("class");
		
		temp_animal = temp_animal.replace("current_animal", "");
		temp_animal = temp_animal.replace("submenu_animals", "");
		temp_animal = temp_animal.replace(" ", "");
	}
	
	$current_animal_active = temp_animal;
	
	
	//подъезд к статьям
	if ($jq('#anchor-articles-top').length)
	{
		go_to_anchor_on_page('anchor-articles-top');
	}
	
});

function animal_click(animal_name)
{
	if ($current_animal_active == '' || $current_animal_active == null)
	{
		$jq('.submenu_animals').each(function(){
			this.style.display = 'none';
		});
		
		var img_obj = $jq('#' + animal_name + '_image_menu');
		
		img_obj.attr("src", '/images/vetby/icons/' + animal_name + '_act.png');
		img_obj.addClass("active_animal");
		
		var submenu_div = $jq('.lpart').children().filter('.' + animal_name);
		
		//submenu_div.css({opacity: '0', display: 'block'});
		submenu_div.css({display: 'block'});
		
		//submenu_div.fadeTo("slow", 1);
		
		//alert($jq('.' + animal_name).attr("onmouseout"));
		$current_animal_active = animal_name;
	}
	else
	{
		$current_animal_active = $current_animal_active.replace(" ", "");
		
		var clicked_animal = $jq('#' + animal_name + '_image_menu');
		var current_animal = $jq('#' + $current_animal_active + '_image_menu');
		
		if (clicked_animal.parent().attr("class") != current_animal.parent().attr("class"))
		{
			//var img_obj = document.getElementById($current_animal_active + '_image_menu');
			
			//alert(img_obj.tagName);
			//alert(img_obj.className);
			//alert(clicked_animal.parent().attr("class"));
			//alert(current_animal.parent().attr("class"));
			
			/*
			clicked_animal.mouseout(function(){
				clicked_animal.attr("src", '/images/vetby/icons/' + animal_name + '_act.png');
			}).attr("src", '/images/vetby/icons/' + animal_name + '_act.png');
			
			current_animal.mouseout(function(){
				current_animal.attr("src", '/images/vetby/icons/' + $current_animal_active + '_off.png');
			}).attr("src", '/images/vetby/icons/' + $current_animal_active + '_off.png');
			*/
			
			clicked_animal.attr("src", '/images/vetby/icons/' + animal_name + '_act.png');
			current_animal.attr("src", '/images/vetby/icons/' + $current_animal_active + '_off.png');
			
			clicked_animal.addClass("active_animal");
			current_animal.removeClass("active_animal");
			
			//$jq('.' + $current_animal_active).fadeTo("slow", 0);
			//setTimeout ( "animal_click_part2('" + animal_name + "')", 800 );
			
			$jq('.' + $current_animal_active).css({display:'none'});
			$jq('.lpart').children().filter('.' + animal_name).css({display:'block'});
			
			$current_animal_active = animal_name;
		}
	}
	
	return false;
}

function animal_click_part2(animal_name)
{
	$jq('.' + $current_animal_active).css({display:'none'});
	var temp_div = $jq('.lpart').children().filter('.' + animal_name);
	temp_div.css({opasity:0});
	temp_div.css({display:'block'});
	temp_div.fadeTo("slow", 1);
	
	$current_animal_active = animal_name;
	
	return false;
}


function onmouseout_animal(animal_name)
{
	var animal_img = $jq('#' + animal_name + '_image_menu');
	
	if (animal_img.hasClass("active_animal"))
	{
		animal_img.attr("src", "/images/vetby/icons/" + animal_name + "_act.png")
	}
	else
	{
		animal_img.attr("src", "/images/vetby/icons/" + animal_name + "_off.png")
	}
}


function hide_fade(type1,type2)
{
	param1=document.getElementById(type1);
	param2=document.getElementById(type2);
	
	
	
	//alert(param1.style.display);
	//alert(param2.style.display);
	
	if(param1.style.display == 'none')
	{
		$jq(param2).fadeTo(800, 0);
		
		setTimeout ( "hide_fade_part2('" + type1 + "', '" + type2 + "')", 800 );
	}
	else
	{
		$jq(param1).fadeTo(800, 0);
		
		setTimeout ( "hide_fade_part2('" + type1 + "', '" + type2 + "')", 800 );
	}
	
}


function hide_fade_part2(type1, type2)
{
	param1=document.getElementById(type1);
	param2=document.getElementById(type2);
	
	
	if(param1.style.display == 'none')
	{
		param2.style.display = 'none';
		
		param1.style.opacity = 0;
		param1.style.display = 'block';
		
		$jq(param1).fadeTo(800, 1);
		
	}
	else
	{
		param1.style.display = 'none';
		
		param2.style.opacity = 0;
		param2.style.display = 'block';
		
		$jq(param2).fadeTo(800, 1);
	}
}


function go_to_anchor_on_page(anchor_id,offset_top,time_to_scroll)
{
	var position = $jq('#' + anchor_id).offset();
	var top_position = position.top;
	var scrolling_time = 500;
	if (offset_top != null)
	{
		top_position = top_position + offset_top;
	}
	
	if (time_to_scroll != null)
	{
		scrolling_time = time_to_scroll;
	}
	
	
	$jq(document).scrollTo({top:top_position + 'px', left: '0px'}, scrolling_time);
	return false;
}




function qw_jq(type1)
{
	if(document.getElementById(type1) != null)
	{
		if(document.getElementById(type1).style.display=='none')
		{
			document.getElementById(type1).style.display='block';
		}
		else if(document.getElementById(type1).style.display=='block')
		{
			document.getElementById(type1).style.display='none';
		}
		else
		{
			document.getElementById(type1).style.display='block';
		}
		return false;
	}
	return true;s
	/*
	var max=50;
	for(i=1;i<max;i++)
	{
		if (type1!='lev2'+i) 
		{
			if (document.getElementById('lev2'+i) != null)
			{
				document.getElementById('lev2'+i).style.display='none';
			}
		}
		else if (document.getElementById('lev2'+i).style.display=='none') 
		{
			if (document.getElementById('lev2'+i) != null)
			{
				document.getElementById('lev2'+i).style.display='block';
			}
		}
		else 
		{
			if (document.getElementById('lev2'+i) != null)
			{
				document.getElementById('lev2'+i).style.display='none';
			}
		}
	}
	*/
}
